umami/queries/analytics/stats/getActiveVisitors.js

18 lines
366 B
JavaScript
Raw Normal View History

2022-07-13 00:14:27 +02:00
import { rawQuery } from 'lib/queries';
2022-07-12 23:14:36 +02:00
import { subMinutes } from 'date-fns';
export function getActiveVisitors(website_id) {
const date = subMinutes(new Date(), 5);
const params = [website_id, date];
return rawQuery(
`
select count(distinct session_id) x
from pageview
where website_id=$1
and created_at >= $2
`,
params,
);
}