How to calculate the average time a user spent on a particular page

You can use this query to calculate the average time your users spent on a particular page. You can replace the screen ID with page title or url

Select screen_id, avg((next_screen_ts-event_time_ts)/1000000) as seconds_on_screen
from
(Select user_id, screen_id, event_time_ts, lead(event_time_ts) over (partition by user_id, session_id order by event_time_ts) as next_screen_ts
from
(Select screen_id, former_screen, event_time_ts, user_id, session_id, event_name
from
(select screen_id, lag(screen_id) over (partition by player_id, session_id order by event_time_ts) as former_screen, event_time_ts, user_id, session_id, event_name
from cooladata
Where date_range(context)  and filters(context)  and screen_id is not null)
where (screen_id <> former_screen) or former_screen is null))
Where next_screen_ts is not null
Group by screen_id
order by seconds_on_screen desc      
Segentation
Behavioral