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.

fix realtime queries for stats

Francis Cao3205b4f0f417
diff --git a/src/queries/analytics/pageviews/getPageviewStats.ts b/src/queries/analytics/pageviews/getPageviewStats.ts
index 8d757de31..f6ea1e08f 100644
--- a/src/queries/analytics/pageviews/getPageviewStats.ts
+++ b/src/queries/analytics/pageviews/getPageviewStats.ts
@@ -47,6 +47,9 @@ async function clickhouseQuery(
eventType: EVENT_TYPE.pageView,
});
+ const table = unit === 'minute' ? 'website_event' : 'website_event_stats_hourly';
+ const columnQuery = unit === 'minute' ? 'count(*)' : 'sum(views)';
+
return rawQuery(
`
select
@@ -55,8 +58,8 @@ async function clickhouseQuery(
from (
select
${getDateSQL('created_at', unit, timezone)} as t,
- sum(views) as y
- from website_event_stats_hourly website_event
+ ${columnQuery} as y
+ from ${table} website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
diff --git a/src/queries/analytics/sessions/getSessionStats.ts b/src/queries/analytics/sessions/getSessionStats.ts
index 0fe0b8a55..7bba14df1 100644
--- a/src/queries/analytics/sessions/getSessionStats.ts
+++ b/src/queries/analytics/sessions/getSessionStats.ts
@@ -47,6 +47,9 @@ async function clickhouseQuery(
eventType: EVENT_TYPE.pageView,
});
+ const table = unit === 'minute' ? 'website_event' : 'website_event_stats_hourly';
+ const columnQuery = unit === 'minute' ? 'count(distinct session_id)' : 'uniq(session_id)';
+
return rawQuery(
`
select
@@ -55,8 +58,8 @@ async function clickhouseQuery(
from (
select
${getDateSQL('created_at', unit, timezone)} as t,
- uniq(session_id) as y
- from website_event_stats_hourly website_event
+ ${columnQuery} as y
+ from ${table} website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}