@@ -39,7 +39,7 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
3939 name : "median_session_duration" ,
4040 type : "number" ,
4141 label : "Median Session Duration" ,
42- description : "Median session duration in seconds " ,
42+ description : "Median time spent actively on pages " ,
4343 unit : "seconds" ,
4444 } ,
4545 {
@@ -81,7 +81,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
8181 const baseEventsQuery = helpers ?. sessionAttributionCTE
8282 ? `base_events AS (
8383 SELECT e.session_id, e.anonymous_id, e.event_name,
84- toTimeZone(e.time, {timezone:String}) as normalized_time
84+ toTimeZone(e.time, {timezone:String}) as normalized_time,
85+ e.time_on_page
8586 FROM analytics.events e
8687 ${ helpers . sessionAttributionJoin ( "e" ) }
8788 WHERE e.client_id = {websiteId:String}
@@ -92,7 +93,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
9293 ),`
9394 : `base_events AS (
9495 SELECT session_id, anonymous_id, event_name,
95- toTimeZone(time, {timezone:String}) as normalized_time
96+ toTimeZone(time, {timezone:String}) as normalized_time,
97+ time_on_page
9698 FROM analytics.events
9799 WHERE client_id = {websiteId:String}
98100 AND time >= toDateTime({startDate:String})
@@ -108,8 +110,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
108110 session_agg AS (
109111 SELECT session_id,
110112 countIf(event_name = 'screen_view') as page_count,
111- countIf(event_name != 'screen_view') as engagement_count,
112- dateDiff('second', min(normalized_time), max(normalized_time) ) as duration
113+ countIf(event_name != 'screen_view' AND event_name != 'page_exit' ) as engagement_count,
114+ sumIf(time_on_page, event_name = 'page_exit' AND time_on_page > 0 ) as duration
113115 FROM base_events
114116 GROUP BY session_id
115117 ),
@@ -225,7 +227,7 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
225227 name : "median_session_duration" ,
226228 type : "number" ,
227229 label : "Median Session Duration" ,
228- description : "Median session duration in seconds " ,
230+ description : "Median time spent actively on pages " ,
229231 unit : "seconds" ,
230232 } ,
231233 {
@@ -273,7 +275,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
273275 const baseEventsQuery = helpers ?. sessionAttributionCTE
274276 ? `base_events AS (
275277 SELECT e.session_id, e.anonymous_id, e.event_name,
276- toTimeZone(e.time, {timezone:String}) as normalized_time
278+ toTimeZone(e.time, {timezone:String}) as normalized_time,
279+ e.time_on_page
277280 FROM analytics.events e
278281 ${ helpers . sessionAttributionJoin ( "e" ) }
279282 WHERE e.client_id = {websiteId:String}
@@ -283,7 +286,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
283286 ),`
284287 : `base_events AS (
285288 SELECT session_id, anonymous_id, event_name,
286- toTimeZone(time, {timezone:String}) as normalized_time
289+ toTimeZone(time, {timezone:String}) as normalized_time,
290+ time_on_page
287291 FROM analytics.events
288292 WHERE client_id = {websiteId:String}
289293 AND ${ dateFilter }
@@ -299,8 +303,8 @@ export const SummaryBuilders: Record<string, SimpleQueryConfig> = {
299303 SELECT session_id,
300304 ${ timeBucketFn } (minIf(normalized_time, event_name = 'screen_view')) as time_bucket,
301305 countIf(event_name = 'screen_view') as page_count,
302- countIf(event_name != 'screen_view') as engagement_count,
303- dateDiff('second', min(normalized_time), max(normalized_time) ) as duration
306+ countIf(event_name != 'screen_view' AND event_name != 'page_exit' ) as engagement_count,
307+ sumIf(time_on_page, event_name = 'page_exit' AND time_on_page > 0 ) as duration
304308 FROM base_events
305309 GROUP BY session_id
306310 ),
0 commit comments