Last active
February 19, 2024 06:24
-
-
Save ZordnajelA/6a895b3f05854078723adb383ffc1501 to your computer and use it in GitHub Desktop.
Using SQL window functions to replicate Google Analytics custom dimensions behavior
This file contains hidden or 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
LAST_VALUE( | |
(SELECT | |
value.string_value --value.int_value, value.float_value, value.double_value | |
FROM | |
UNNEST(event_params) | |
WHERE | |
key = 'name_of_event_parameter_to_use_as_dimension' | |
) | |
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_custom_dimension |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment