Browse Source

Remove domain parameter from queries.

dev
Mike Cao 6 months ago
parent
commit
f7201c9cfc
4 changed files with 17 additions and 14 deletions
  1. +0
    -2
      components/metrics/MetricsTable.js
  2. +0
    -1
      components/metrics/ReferrersTable.js
  3. +1
    -1
      lib/queries.js
  4. +16
    -10
      pages/api/website/[id]/metrics.js

+ 0
- 2
components/metrics/MetricsTable.js View File

@ -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,


+ 0
- 1
components/metrics/ReferrersTable.js View File

@ -42,7 +42,6 @@ export default function ReferrersTable({ websiteId, websiteDomain, showFilters,
type="referrer"
metric={<FormattedMessage id="metrics.views" defaultMessage="Views" />}
websiteId={websiteId}
websiteDomain={websiteDomain}
dataFilter={refFilter}
filterOptions={{
domain: websiteDomain,


+ 1
- 1
lib/queries.js View File

@ -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) {


+ 16
- 10
pages/api/website/[id]/metrics.js View File

@ -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,
},
);


Loading…
Cancel
Save