implement visit duration

This commit is contained in:
Francis Cao 2024-08-13 08:45:52 -07:00
parent fc758745dc
commit f9c7129a3e
2 changed files with 34 additions and 10 deletions

View file

@ -23,9 +23,8 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
return rawQuery(
`
select
session_id as id,
website_id as websiteId,
select id,
websiteId,
hostname,
browser,
os,
@ -37,13 +36,32 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
city,
min(min_time) as firstAt,
max(max_time) as lastAt,
uniq(visit_id) as visits,
sumIf(views, event_type = 1) as views,
length(groupArrayArray(event_name)) as events
from website_event_stats_hourly
where website_id = {websiteId:UUID}
and session_id = {sessionId:UUID}
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city;
uniq(visit_id) visits,
sum(views) as views,
sum(events) as events,
sum(max_time-min_time) as totaltime
from (select
session_id as id,
visit_id,
website_id as websiteId,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
city,
min(min_time) as min_time,
max(max_time) as max_time,
sum(views) as views,
length(groupArrayArray(event_name)) as events
from website_event_stats_hourly
where website_id = {websiteId:UUID}
and session_id = {sessionId:UUID}
group by session_id, visit_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city) t
group by id, websiteId, hostname, browser, os, device, screen, language, country, subdivision1, city;
`,
{ websiteId, sessionId },
).then(result => result?.[0]);