umami/queries/analytics/pageview/getPageviewMetrics.js

28 lines
648 B
JavaScript
Raw Normal View History

2022-07-13 00:14:27 +02:00
import { parseFilters, rawQuery } from 'lib/queries';
2022-07-12 23:14:36 +02:00
export function getPageviewMetrics(website_id, start_at, end_at, column, table, filters = {}) {
2022-07-12 23:14:36 +02:00
const params = [website_id, start_at, end_at];
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
table,
column,
2022-07-12 23:14:36 +02:00
filters,
params,
);
return rawQuery(
`
select ${column} x, count(*) y
2022-07-12 23:14:36 +02:00
from ${table}
${joinSession}
where ${table}.website_id=$1
and ${table}.created_at between $2 and $3
${pageviewQuery}
${joinSession && sessionQuery}
${eventQuery}
group by 1
order by 2 desc
`,
params,
);
}