Skip to content

Instantly share code, notes, and snippets.

@josiehall
Created April 22, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josiehall/af546b3f95659b28eaf403ccfc1f44e4 to your computer and use it in GitHub Desktop.
Save josiehall/af546b3f95659b28eaf403ccfc1f44e4 to your computer and use it in GitHub Desktop.
SQL query which shows how long users typically spend on your site, and how that has trended over time.
select
date(session_start_timestamp) as date,
avg(stats.duration_millis) as mean_session_duration_millis,
approx_quantiles(stats.duration_millis, 101)[safe_offset(25)] as percentile_25,
approx_quantiles(stats.duration_millis, 101)[safe_offset(50)] as percentile_50,
approx_quantiles(stats.duration_millis, 101)[safe_offset(75)] as percentile_75
from
dataform_data_sources.segment_sessions
group by
date
order by
date desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment