Added events to website stats.

pull/1464/head
Guillermo Grau 2022-08-26 13:08:36 +02:00
parent 0f976be5d8
commit bb8f611604
1 changed files with 24 additions and 2 deletions

View File

@ -25,9 +25,11 @@ async function relationalQuery(website_id, start_at, end_at, filters = {}) {
filters,
params,
);
const { joinSession: joinEventSession } = parseFilters('event', null, filters, params);
return rawQuery(
`
select * from (
select sum(t.c) as "pageviews",
count(distinct t.session_id) as "uniques",
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
@ -44,7 +46,16 @@ async function relationalQuery(website_id, start_at, end_at, filters = {}) {
${pageviewQuery}
${sessionQuery}
group by 1, 2
) t
) t
) stats_views
cross join (
select count(*) events
from event
${joinEventSession}
where event.website_id=$1
and event.created_at between $2 and $3
${sessionQuery}
) stats_events
`,
params,
);
@ -59,9 +70,11 @@ async function clickhouseQuery(website_id, start_at, end_at, filters = {}) {
params,
'session_uuid',
);
const { joinSession: joinEventSession } = parseFilters('event', null, filters, params);
return rawQueryClickhouse(
`
select * from (
select
sum(t.c) as "pageviews",
count(distinct t.session_uuid) as "uniques",
@ -81,7 +94,16 @@ async function clickhouseQuery(website_id, start_at, end_at, filters = {}) {
${sessionQuery}
group by pageview.session_uuid, time_series
) t;
`,
) stats_views
cross join (
select count(*) events
from event
${joinEventSession}
where event.website_id=$1
and ${getBetweenDatesClickhouse('event.created_at', start_at, end_at)}
${sessionQuery}
) stats_events
`,
params,
);
}