implement cohorts to clickhouse/pg library and all relevant queries

This commit is contained in:
Francis Cao 2025-07-03 12:06:49 -07:00
parent a753809a74
commit e75d009df3
22 changed files with 220 additions and 10983 deletions

View file

@ -23,7 +23,7 @@ async function relationalQuery(
{ pageviews: number; visitors: number; visits: number; bounces: number; totaltime: number }[]
> {
const { getTimestampDiffSQL, parseFilters, rawQuery } = prisma;
const { filterQuery, joinSession, params } = await parseFilters(websiteId, {
const { filterQuery, cohortQuery, joinSession, params } = await parseFilters(websiteId, {
...filters,
eventType: EVENT_TYPE.pageView,
});
@ -44,6 +44,7 @@ async function relationalQuery(
min(website_event.created_at) as "min_time",
max(website_event.created_at) as "max_time"
from website_event
${cohortQuery}
${joinSession}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
@ -63,7 +64,7 @@ async function clickhouseQuery(
{ pageviews: number; visitors: number; visits: number; bounces: number; totaltime: number }[]
> {
const { rawQuery, parseFilters } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
const { filterQuery, cohortQuery, params } = await parseFilters(websiteId, {
...filters,
eventType: EVENT_TYPE.pageView,
});
@ -86,6 +87,7 @@ async function clickhouseQuery(
min(created_at) min_time,
max(created_at) max_time
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
@ -108,6 +110,7 @@ async function clickhouseQuery(
min(min_time) min_time,
max(max_time) max_time
from umami.website_event_stats_hourly "website_event"
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}