diff --git a/lib/queries.js b/lib/queries.js index df23bde8..f5a677a4 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -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),