Created
June 8, 2023 04:09
-
-
Save nicobrx/bc48e92878bfbf28bf29627906ec5339 to your computer and use it in GitHub Desktop.
Query for getting average engagement time per page from GA4 BigQuery data.
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
SELECT | |
page_location, | |
SUM(engagement_time_seconds) AS engagement_time_seconds, | |
SUM(page_views) AS page_views, | |
SAFE_DIVIDE( SUM(engagement_time_seconds), SUM(page_views) ) AS average_engagement_time_per_page | |
FROM ( | |
SELECT | |
( | |
SELECT | |
value.string_value | |
FROM | |
UNNEST (event_params) | |
WHERE | |
KEY = 'page_location' ) AS page_location, | |
SUM(( | |
SELECT | |
value.int_value | |
FROM | |
UNNEST(event_params) | |
WHERE | |
KEY = 'engagement_time_msec'))/1000 AS engagement_time_seconds, | |
COUNT( | |
CASE | |
WHEN event_name = 'page_view' THEN 1 | |
END | |
) AS page_views | |
FROM | |
## replace with your project & dataset | |
`yourbigquery.analytics_12345678.events_*` | |
WHERE | |
_TABLE_SUFFIX BETWEEN '20230501' | |
AND '20230531' | |
GROUP BY | |
page_location ) | |
GROUP BY | |
page_location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment