umami/queries/analytics/stats/getActiveVisitors.js
2022-07-15 16:47:38 -07:00

18 lines
361 B
JavaScript

import { rawQuery } from 'lib/db';
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,
);
}