diff --git a/lib/clickhouse.js b/lib/clickhouse.js index 78676371..46cdaabc 100644 --- a/lib/clickhouse.js +++ b/lib/clickhouse.js @@ -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, diff --git a/lib/prisma.ts b/lib/prisma.ts index 55e5644a..17c5d094 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -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, diff --git a/pages/api/collect.ts b/pages/api/collect.ts index b288d991..4c989e9b 100644 --- a/pages/api/collect.ts +++ b/pages/api/collect.ts @@ -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 diff --git a/pages/api/websites/[id]/eventdata.ts b/pages/api/websites/[id]/eventdata.ts index 28997116..9e21eb13 100644 --- a/pages/api/websites/[id]/eventdata.ts +++ b/pages/api/websites/[id]/eventdata.ts @@ -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); diff --git a/pages/api/websites/[id]/metrics.ts b/pages/api/websites/[id]/metrics.ts index 04a27129..62497dbd 100644 --- a/pages/api/websites/[id]/metrics.ts +++ b/pages/api/websites/[id]/metrics.ts @@ -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, }; diff --git a/tracker/index.js b/tracker/index.js index a9e11d0d..e91da659 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -108,8 +108,8 @@ assign(getPayload(), { website: websiteId, url, - event_name: eventName, - event_data: eventData, + eventName: eventName, + eventData: eventData, }), );