Remove domain parameter from queries.

This commit is contained in:
Mike Cao 2021-02-26 19:50:44 -08:00
parent 278672233e
commit f7201c9cfc
4 changed files with 17 additions and 14 deletions

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,

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,

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

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