@@ -32,14 +32,14 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
3232 name : "bounce_rate" ,
3333 type : "number" ,
3434 label : "Bounce Rate" ,
35- description : "Percentage of single-page sessions" ,
35+ description : "Percentage of non-engaged sessions (single pageview, < 10s duration, no interactions) " ,
3636 unit : "%" ,
3737 } ,
3838 {
39- name : "avg_session_duration " ,
39+ name : "median_session_duration " ,
4040 type : "number" ,
41- label : "Avg Session Duration" ,
42- description : "Average session duration in seconds" ,
41+ label : "Median Session Duration" ,
42+ description : "Median session duration in seconds" ,
4343 unit : "seconds" ,
4444 } ,
4545 {
@@ -108,6 +108,7 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
108108 session_agg AS (
109109 SELECT session_id,
110110 countIf(event_name = 'screen_view') as page_count,
111+ countIf(event_name != 'screen_view') as engagement_count,
111112 dateDiff('second', min(normalized_time), max(normalized_time)) as duration
112113 FROM base_events
113114 GROUP BY session_id
@@ -118,9 +119,9 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
118119 uniq(if(event_name = 'screen_view', anonymous_id, null)) as unique_visitors
119120 FROM base_events
120121 )
121- SELECT ea.pageviews, ea.unique_visitors, count( ) as sessions,
122- round(countIf(sa.page_count = 1) * 100.0 / nullIf(count( ), 0), 2) as bounce_rate,
123- round(medianIf(sa.duration, sa.duration >= 0), 2) as avg_session_duration ,
122+ SELECT ea.pageviews, ea.unique_visitors, countIf(sa.page_count >= 1 ) as sessions,
123+ round(countIf(sa.page_count = 1 AND sa.duration < 10 AND sa.engagement_count = 0 ) * 100.0 / nullIf(countIf(sa.page_count >= 1 ), 0), 2) as bounce_rate,
124+ round(medianIf(sa.duration, sa.page_count >= 1 AND sa. duration >= 0), 2) as median_session_duration ,
124125 ea.total_events
125126 FROM session_agg sa
126127 CROSS JOIN event_agg ea
@@ -217,14 +218,14 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
217218 name : "bounce_rate" ,
218219 type : "number" ,
219220 label : "Bounce Rate" ,
220- description : "Bounce rate for the period " ,
221+ description : "Percentage of non-engaged sessions (single pageview, < 10s duration, no interactions) " ,
221222 unit : "%" ,
222223 } ,
223224 {
224- name : "avg_session_duration " ,
225+ name : "median_session_duration " ,
225226 type : "number" ,
226- label : "Avg Session Duration" ,
227- description : "Average session duration" ,
227+ label : "Median Session Duration" ,
228+ description : "Median session duration in seconds " ,
228229 unit : "seconds" ,
229230 } ,
230231 {
@@ -296,8 +297,9 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
296297 ${ baseEventsQuery }
297298 session_agg AS (
298299 SELECT session_id,
299- ${ timeBucketFn } (min (normalized_time)) as time_bucket,
300+ ${ timeBucketFn } (minIf (normalized_time, event_name = 'screen_view' )) as time_bucket,
300301 countIf(event_name = 'screen_view') as page_count,
302+ countIf(event_name != 'screen_view') as engagement_count,
301303 dateDiff('second', min(normalized_time), max(normalized_time)) as duration
302304 FROM base_events
303305 GROUP BY session_id
@@ -311,8 +313,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
311313 )
312314 SELECT ${ dateFormat } as date, ea.pageviews, ea.visitors,
313315 count(sa.session_id) as sessions,
314- round(countIf(sa.page_count = 1) * 100.0 / nullIf(count(sa.session_id), 0), 2) as bounce_rate,
315- round(medianIf(sa.duration, sa.duration >= 0), 2) as avg_session_duration ,
316+ round(countIf(sa.page_count = 1 AND sa.duration < 10 AND sa.engagement_count = 0 ) * 100.0 / nullIf(count(sa.session_id), 0), 2) as bounce_rate,
317+ round(medianIf(sa.duration, sa.duration >= 0), 2) as median_session_duration ,
316318 round(ea.pageviews * 1.0 / nullIf(count(sa.session_id), 0), 2) as pages_per_session
317319 FROM event_agg ea
318320 LEFT JOIN session_agg sa ON ea.time_bucket = sa.time_bucket
0 commit comments