Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Mike Cao 2022-12-27 00:00:42 -08:00
commit c90bd941b5
6 changed files with 22 additions and 11 deletions

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ export default async (
return unauthorized(res); 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 startDate = new Date(+startAt);
const endDate = new Date(+endAt); const endDate = new Date(+endAt);

View File

@ -134,7 +134,7 @@ export default async (
browser: type !== 'browser' ? browser : undefined, browser: type !== 'browser' ? browser : undefined,
device: type !== 'device' ? device : undefined, device: type !== 'device' ? device : undefined,
country: type !== 'country' ? country : 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, query: type === 'query' && table !== 'event' ? true : undefined,
}; };

View File

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