Last active
February 19, 2024 03:30
-
-
Save ZordnajelA/e3d7574f68fe67863d13dcccbd3ac765 to your computer and use it in GitHub Desktop.
Using SQL FIRST_VALUE() window function to replicate GA4 traffic source attribution behavior
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
FIRST_VALUE( | |
(SELECT | |
value.string_value | |
FROM | |
UNNEST(event_params) | |
WHERE | |
key = 'name_of_traffic_source_parameter' | |
--source, medium, campaign, content, term, campaign_id | |
) | |
IGNORE nulls | |
) OVER ( | |
PARTITION BY | |
user_pseudo_id, | |
(SELECT | |
value.int_value | |
FROM | |
UNNEST(event_params) | |
WHERE | |
key = 'ga_session_id' | |
) | |
ORDER BY | |
event_timestamp | |
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | |
) AS my_utm_parameter_session_level |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment