mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
40 lines
792 B
JavaScript
40 lines
792 B
JavaScript
import { parseFilters, rawQuery, getDateQuery } from 'lib/queries';
|
|
|
|
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,
|
|
);
|
|
|
|
return rawQuery(
|
|
`
|
|
select
|
|
g.t as t,
|
|
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
|
|
order by 1
|
|
`,
|
|
params,
|
|
);
|
|
}
|