Allow filtering of events with url.

This commit is contained in:
Mike Cao 2022-04-13 19:04:06 -07:00
parent 1cff704379
commit f69dbaeaf6
2 changed files with 11 additions and 6 deletions

View File

@ -64,7 +64,7 @@ export function getFilterQuery(table, filters = {}, params = []) {
switch (key) {
case 'url':
if (table === 'session' || table === 'pageview') {
if (table === 'pageview' || table === 'event') {
arr.push(`and ${table}.${key}=$${params.length + 1}`);
params.push(decodeURIComponent(value));
}
@ -110,11 +110,11 @@ export function getFilterQuery(table, filters = {}, params = []) {
}
export function parseFilters(table, filters = {}, params = []) {
const { domain, url, referrer, os, browser, device, country, event_type } = filters;
const { domain, url, event_url, referrer, os, browser, device, country, event_type } = filters;
const pageviewFilters = { domain, url, referrer };
const sessionFilters = { os, browser, device, country };
const eventFilters = { event_type };
const eventFilters = { url: event_url, event_type };
return {
pageviewFilters,
@ -502,8 +502,11 @@ export function getSessionMetrics(website_id, start_at, end_at, field, filters =
export function getPageviewMetrics(website_id, start_at, end_at, field, table, filters = {}) {
const params = [website_id, start_at, end_at];
console.log({ table, filters });
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(table, filters, params);
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
table,
filters,
params,
);
return rawQuery(
`
@ -514,6 +517,7 @@ export function getPageviewMetrics(website_id, start_at, end_at, field, table, f
and ${table}.created_at between $2 and $3
${pageviewQuery}
${joinSession && sessionQuery}
${eventQuery}
group by 1
order by 2 desc
`,

View File

@ -83,12 +83,13 @@ export default async (req, res) => {
const data = await getPageviewMetrics(websiteId, startDate, endDate, column, table, {
domain,
url: type !== 'url' ? url : undefined,
url: type !== 'url' && table !== 'event' ? url : undefined,
referrer: type !== 'referrer' ? referrer : undefined,
os: type !== 'os' ? os : undefined,
browser: type !== 'browser' ? browser : undefined,
device: type !== 'device' ? device : undefined,
country: type !== 'country' ? country : undefined,
event_url: type !== 'url' && table === 'event' ? url : undefined,
});
return ok(res, data);