Fix event var names.

This commit is contained in:
Brian Cao 2022-12-26 23:21:54 -08:00
parent dff105c747
commit ef9d915592
6 changed files with 22 additions and 11 deletions

View File

@ -120,11 +120,15 @@ function getFilterQuery(filters = {}, params = []) {
case 'browser':
case 'device':
case 'country':
case 'eventName':
arr.push(`and ${key}=$${params.length + 1}`);
params.push(decodeURIComponent(filter));
break;
case 'eventName':
arr.push(`and event_name=$${params.length + 1}`);
params.push(decodeURIComponent(filter));
break;
case 'referrer':
arr.push(`and referrer like $${params.length + 1}`);
params.push(`%${decodeURIComponent(filter)}%`);
@ -147,12 +151,12 @@ function getFilterQuery(filters = {}, params = []) {
}
function parseFilters(filters = {}, params = []) {
const { domain, url, event_url, referrer, os, browser, device, country, eventName, query } =
const { domain, url, eventUrl, referrer, os, browser, device, country, eventName, query } =
filters;
const pageviewFilters = { domain, url, referrer, query };
const sessionFilters = { os, browser, device, country };
const eventFilters = { url: event_url, eventName };
const eventFilters = { url: eventUrl, eventName };
return {
pageviewFilters,

View File

@ -124,19 +124,26 @@ function getFilterQuery(filters = {}, params = []): string {
case 'browser':
case 'device':
case 'country':
case 'eventName':
arr.push(`and ${key}=$${params.length + 1}`);
params.push(decodeURIComponent(filter));
break;
case 'eventName':
arr.push(`and event_name=$${params.length + 1}`);
params.push(decodeURIComponent(filter));
break;
case 'referrer':
arr.push(`and referrer like $${params.length + 1}`);
params.push(`%${decodeURIComponent(filter)}%`);
break;
case 'domain':
arr.push(`and referrer not like $${params.length + 1}`);
arr.push(`and referrer not like '/%'`);
params.push(`%://${filter}/%`);
break;
case 'query':
arr.push(`and url like '%?%'`);
}
@ -152,12 +159,12 @@ function parseFilters(
params = [],
sessionKey = 'session_id',
) {
const { domain, url, event_url, referrer, os, browser, device, country, eventName, query } =
const { domain, url, eventUrl, referrer, os, browser, device, country, eventName, query } =
filters;
const pageviewFilters = { domain, url, referrer, query };
const sessionFilters = { os, browser, device, country };
const eventFilters = { url: event_url, eventName };
const eventFilters = { url: eventUrl, eventName };
return {
pageviewFilters,

View File

@ -31,7 +31,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
const { type, payload } = getJsonBody(req);
const { referrer, eventName, event_data: eventData } = payload;
const { referrer, eventName, eventData } = payload;
let { url } = payload;
// Validate eventData is JSON

View File

@ -34,7 +34,7 @@ export default async (
return unauthorized(res);
}
const { startAt, endAt, event_name: eventName, columns, filters } = req.body;
const { startAt, endAt, eventName, columns, filters } = req.body;
const startDate = new Date(+startAt);
const endDate = new Date(+endAt);

View File

@ -134,7 +134,7 @@ export default async (
browser: type !== 'browser' ? browser : undefined,
device: type !== 'device' ? device : undefined,
country: type !== 'country' ? country : undefined,
event_url: type !== 'url' && table === 'event' ? url : undefined,
eventUrl: type !== 'url' && table === 'event' ? url : undefined,
query: type === 'query' && table !== 'event' ? true : undefined,
};

View File

@ -108,8 +108,8 @@
assign(getPayload(), {
website: websiteId,
url,
event_name: eventName,
event_data: eventData,
eventName: eventName,
eventData: eventData,
}),
);