fix: forgot to include referrer filter in sessionMetrics

This commit is contained in:
Holger Huo 2022-04-07 21:33:01 +08:00
parent 7c744589ae
commit 0377773e21
2 changed files with 9 additions and 2 deletions

View File

@ -424,15 +424,21 @@ export function getPageviewStats(
export function getSessionMetrics(website_id, start_at, end_at, field, filters = {}) {
const params = [website_id, start_at, end_at];
const { url } = filters;
const { url, referrer } = filters;
let urlFilter = '';
let refFilter = '';
if (url) {
urlFilter = `and url=$${params.length + 1}`;
params.push(decodeURIComponent(url));
}
if (referrer) {
refFilter = `and referrer like $${params.length + 1}`;
params.push(`%${decodeURIComponent(referrer)}%`);
}
return rawQuery(
`
select ${field} x, count(*) y
@ -443,6 +449,7 @@ export function getSessionMetrics(website_id, start_at, end_at, field, filters =
where website_id=$1
and created_at between $2 and $3
${urlFilter}
${refFilter}
)
group by 1
order by 2 desc

View File

@ -40,7 +40,7 @@ export default async (req, res) => {
const endDate = new Date(+end_at);
if (sessionColumns.includes(type)) {
let data = await getSessionMetrics(websiteId, startDate, endDate, type, { url });
let data = await getSessionMetrics(websiteId, startDate, endDate, type, { url, referrer });
if (type === 'language') {
let combined = {};