-
-
Save brunomertins/31501bdc79c342ec0ceb78f39b38e31b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
-- Subquery to define static and/or dynamic start and end date for the whole query | |
period AS ( | |
SELECT | |
'20200220' AS start_date, | |
FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)) AS end_date) | |
SELECT | |
-- Event count per user (metric | the number of times an individual event (change event_name 'page_view' to event that needs to be counted) was triggered divided by amount of users) | |
COUNT(DISTINCT | |
CASE | |
WHEN event_name = 'page_view' THEN CONCAT(user_pseudo_id, CAST(event_timestamp AS STRING)) | |
END | |
) / COUNT(DISTINCT user_pseudo_id) AS event_count_per_user | |
FROM | |
-- Change this to your Google Analytics 4 export location in BigQuery | |
`ga4.analytics_1234567890.events_*`, | |
period | |
WHERE | |
_table_suffix BETWEEN period.start_date | |
AND period.end_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment