umami/queries/analytics/pageview/getPageviewStats.js

40 lines
792 B
JavaScript
Raw Normal View History

2022-07-21 22:21:33 +02:00
import { parseFilters, rawQuery, getDateQuery } from 'lib/queries';
2022-07-12 23:14:36 +02:00
export function getPageviewStats(
website_id,
start_at,
end_at,
timezone = 'utc',
unit = 'day',
count = '*',
filters = {},
) {
const params = [website_id, start_at, end_at];
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
'pageview',
null,
filters,
params,
);
2022-07-12 23:14:36 +02:00
return rawQuery(
`
2022-07-13 07:39:16 +02:00
select
2022-07-21 22:21:33 +02:00
g.t as t,
2022-07-13 07:39:16 +02:00
g.y as y
from
(select ${getDateQuery('pageview.created_at', unit, timezone)} t,
count(${count}) y
from pageview
${joinSession}
where pageview.website_id=$1
and pageview.created_at between $2 and $3
${pageviewQuery}
${sessionQuery}
group by 1) g
2022-07-12 23:14:36 +02:00
order by 1
`,
params,
);
}