Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

feature(lib): add event type query

Alexander Klein8b6308d68650
diff --git a/lib/queries.js b/lib/queries.js
index df23bde83..f5a677a4c 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),