Skip to content

Instantly share code, notes, and snippets.

@ZordnajelA
Last active February 19, 2024 06:24
Show Gist options
  • Save ZordnajelA/6a895b3f05854078723adb383ffc1501 to your computer and use it in GitHub Desktop.
Save ZordnajelA/6a895b3f05854078723adb383ffc1501 to your computer and use it in GitHub Desktop.
Using SQL window functions to replicate Google Analytics custom dimensions behavior
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