From 64b040c8653802e789e2adf1b7206c62c40e916f Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 30 Mar 2023 09:44:04 -0700 Subject: [PATCH] Fixed query parameter filter. --- lib/clickhouse.ts | 4 ++-- lib/filters.js | 2 +- pages/api/websites/[id]/metrics.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/clickhouse.ts b/lib/clickhouse.ts index d9e6a02b..031f9319 100644 --- a/lib/clickhouse.ts +++ b/lib/clickhouse.ts @@ -190,8 +190,8 @@ function parseFilters(filters: any = {}, params: any = {}) { async function rawQuery(query, params = {}) { if (process.env.LOG_QUERY) { - log(query); - log(params); + log('QUERY:\n', query); + log('PARAMETERS:\n', params); } await connect(); diff --git a/lib/filters.js b/lib/filters.js index 9681a802..8bc6229d 100644 --- a/lib/filters.js +++ b/lib/filters.js @@ -50,7 +50,7 @@ export const percentFilter = data => { export const paramFilter = data => { const map = data.reduce((obj, { x, y }) => { try { - const searchParams = new URLSearchParams(x.split('?')[1]); + const searchParams = new URLSearchParams(x); for (const [key, value] of searchParams) { if (!obj[key]) { diff --git a/pages/api/websites/[id]/metrics.ts b/pages/api/websites/[id]/metrics.ts index ad57790e..e6bae8f2 100644 --- a/pages/api/websites/[id]/metrics.ts +++ b/pages/api/websites/[id]/metrics.ts @@ -89,6 +89,7 @@ export default async ( subdivision1, subdivision2, city, + query, } = req.query; if (req.method === 'GET') { @@ -162,7 +163,7 @@ export default async ( subdivision2: type !== 'subdivision2' ? subdivision2 : undefined, city: type !== 'city' ? city : undefined, eventUrl: type !== 'url' && table === 'event' ? url : undefined, - query: type === 'query' && table !== 'event' ? true : undefined, + query: type !== 'query' && table !== 'event' ? query : undefined, }; const data = await getPageviewMetrics(websiteId, {