Skip to content

Instantly share code, notes, and snippets.

@nicobrx
Last active August 9, 2023 20:11
Show Gist options
  • Save nicobrx/d18eec47931a52f5e5b096d5f2afbb43 to your computer and use it in GitHub Desktop.
Save nicobrx/d18eec47931a52f5e5b096d5f2afbb43 to your computer and use it in GitHub Desktop.
--Looker Studio BigQuery custom query to get sessions per user
with s as (select distinct
user_pseudo_id,
concat(user_pseudo_id,(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id')) AS session_id,
timestamp_micros(event_timestamp) as timestamp
from `yourbqproject.analytics_1234567.events_*`
where _table_suffix between @DS_START_DATE and @DS_END_DATE
and event_name = 'session_start')
select distinct
user_pseudo_id,
count(*) over (partition by user_pseudo_id) AS session_count
from s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment