feature(lib): add event type query

This commit is contained in:
Alexander Klein 2021-02-15 16:28:09 +01:00
parent 2cab8bb15d
commit 8b6308d686

View File

@ -501,6 +501,41 @@ export function getEventMetrics(
);
}
export function getEventTypes(
website_id,
start_at,
end_at,
timezone = 'utc',
unit = 'day',
filters = {},
) {
const params = [website_id, start_at, end_at];
const { url } = filters;
let urlFilter = '';
if (url) {
urlFilter = `and url=$${params.length + 1}`;
params.push(decodeURIComponent(url));
}
return rawQuery(
`
select
event_type x,
${getDateQuery('created_at', unit, timezone)} t,
count(*) y
from event
where website_id=$1
and created_at between $2 and $3
${urlFilter}
group by 1, 2
order by 2
`,
params,
);
}
export async function getRealtimeData(websites, time) {
const [pageviews, sessions, events] = await Promise.all([
getPageviews(websites, time),