From f7201c9cfc5ac250992282266a0b60b6606cde8c Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 26 Feb 2021 19:50:44 -0800 Subject: [PATCH] Remove domain parameter from queries. --- components/metrics/MetricsTable.js | 2 -- components/metrics/ReferrersTable.js | 1 - lib/queries.js | 2 +- pages/api/website/[id]/metrics.js | 26 ++++++++++++++++---------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/components/metrics/MetricsTable.js b/components/metrics/MetricsTable.js index 25bb4a08..95eb00c3 100644 --- a/components/metrics/MetricsTable.js +++ b/components/metrics/MetricsTable.js @@ -17,7 +17,6 @@ import styles from './MetricsTable.module.css'; export default function MetricsTable({ websiteId, - websiteDomain, type, className, dataFilter, @@ -42,7 +41,6 @@ export default function MetricsTable({ type, start_at: +startDate, end_at: +endDate, - domain: websiteDomain, url, }, onDataLoad, diff --git a/components/metrics/ReferrersTable.js b/components/metrics/ReferrersTable.js index 2d51ab74..cbd4c9ba 100644 --- a/components/metrics/ReferrersTable.js +++ b/components/metrics/ReferrersTable.js @@ -42,7 +42,6 @@ export default function ReferrersTable({ websiteId, websiteDomain, showFilters, type="referrer" metric={} websiteId={websiteId} - websiteDomain={websiteDomain} dataFilter={refFilter} filterOptions={{ domain: websiteDomain, diff --git a/lib/queries.js b/lib/queries.js index df23bde8..48f9f265 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -428,7 +428,7 @@ export function getPageviewMetrics(website_id, start_at, end_at, field, table, f if (domain) { domainFilter = `and referrer not like $${params.length + 1} and referrer not like '/%'`; - params.push(`%${domain}%`); + params.push(`%://${domain}/%`); } if (url) { diff --git a/pages/api/website/[id]/metrics.js b/pages/api/website/[id]/metrics.js index ef736ee0..3e9b9925 100644 --- a/pages/api/website/[id]/metrics.js +++ b/pages/api/website/[id]/metrics.js @@ -1,6 +1,5 @@ -import { getPageviewMetrics, getSessionMetrics } from 'lib/queries'; -import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response'; -import { DOMAIN_REGEX } from 'lib/constants'; +import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'lib/queries'; +import { ok, methodNotAllowed, unauthorized, badRequest } from 'lib/response'; import { allowQuery } from 'lib/auth'; const sessionColumns = ['browser', 'os', 'device', 'country']; @@ -31,11 +30,7 @@ export default async (req, res) => { return unauthorized(res); } - const { id, type, start_at, end_at, domain, url } = req.query; - - if (domain && !DOMAIN_REGEX.test(domain)) { - return badRequest(res); - } + const { id, type, start_at, end_at, url } = req.query; const websiteId = +id; const startDate = new Date(+start_at); @@ -47,7 +42,18 @@ export default async (req, res) => { return ok(res, data); } - if (type === 'event' || pageviewColumns.includes(type)) { + if (pageviewColumns.includes(type) || type === 'event') { + let domain; + if (type === 'referrer') { + const website = getWebsiteById(websiteId); + + if (!website) { + return badRequest(res); + } + + domain = website.domain; + } + const data = await getPageviewMetrics( websiteId, startDate, @@ -55,7 +61,7 @@ export default async (req, res) => { getColumn(type), getTable(type), { - domain: type !== 'event' && domain, + domain, url: type !== 'url' && url, }, );