Updated session and events queries. Added sessions page.

This commit is contained in:
Mike Cao 2024-07-08 01:45:54 -07:00
parent 082a751ffe
commit db36c37d32
39 changed files with 376 additions and 180 deletions

View file

@ -35,14 +35,14 @@ async function relationalQuery(
}[]
> {
const { startDate, endDate, timezone = 'UTC' } = filters;
const { getDateQuery, getDayDiffQuery, getCastColumnQuery, rawQuery } = prisma;
const { getDateSQL, getDayDiffQuery, getCastColumnQuery, rawQuery } = prisma;
const unit = 'day';
return rawQuery(
`
WITH cohort_items AS (
select session_id,
${getDateQuery('created_at', unit, timezone)} as cohort_date
${getDateSQL('created_at', unit, timezone)} as cohort_date
from session
where website_id = {{websiteId::uuid}}
and created_at between {{startDate}} and {{endDate}}
@ -50,10 +50,7 @@ async function relationalQuery(
user_activities AS (
select distinct
w.session_id,
${getDayDiffQuery(
getDateQuery('created_at', unit, timezone),
'c.cohort_date',
)} as day_number
${getDayDiffQuery(getDateSQL('created_at', unit, timezone), 'c.cohort_date')} as day_number
from website_event w
join cohort_items c
on w.session_id = c.session_id
@ -115,14 +112,14 @@ async function clickhouseQuery(
}[]
> {
const { startDate, endDate, timezone = 'UTC' } = filters;
const { getDateQuery, getDateStringQuery, rawQuery } = clickhouse;
const { getDateSQL, getDateStringSQL, rawQuery } = clickhouse;
const unit = 'day';
return rawQuery(
`
WITH cohort_items AS (
select
min(${getDateQuery('created_at', unit, timezone)}) as cohort_date,
min(${getDateSQL('created_at', unit, timezone)}) as cohort_date,
session_id
from website_event
where website_id = {websiteId:UUID}
@ -132,7 +129,7 @@ async function clickhouseQuery(
user_activities AS (
select distinct
w.session_id,
(${getDateQuery('created_at', unit, timezone)} - c.cohort_date) / 86400 as day_number
(${getDateSQL('created_at', unit, timezone)} - c.cohort_date) / 86400 as day_number
from website_event w
join cohort_items c
on w.session_id = c.session_id
@ -157,7 +154,7 @@ async function clickhouseQuery(
group by 1, 2
)
select
${getDateStringQuery('c.cohort_date', unit)} as date,
${getDateStringSQL('c.cohort_date', unit)} as date,
c.day_number as day,
s.visitors as visitors,
c.visitors returnVisitors,