BigQuery: 如何访问特定 event_name 的所有不同 event_params.key

huangapple go评论58阅读模式
英文:

BigQuery: How to access all the distinct event_params.key of a event_name

问题

我想了解特定 event_name 的可用 event_params.key

我明白,要访问参数值,需要单独访问和展开数组的每个元素。例如,要访问每个事件的用户会话 ID 和按钮名称:

select user_id, event_name,
(select value.int_value from unnest(event_params) where key='ga_session_id') as session_id,
(select value.string_value from unnest(event_params) where key='button_name') as button_name
from `analytics_xx.events_*`
where user_id = 'abc'

但这假定我知道键是什么。如果我不知道呢?如何返回该 event_name 的所有可用键呢?

以下方法不起作用:

select event_name,
    (select * from unnest(event_params)) as available_keys
from `analytics_xx.events_*`
where event_name = "button_click"
英文:

I am interesting in knowing the distinct event_params.key available for a particular event_name.

I understand that in order to access parameter values, each individual element of the array will need to be accessed and expanded individually. For instance, to access a user’s session_id and button_name per event:

select user_id, event_name,
(select value.int_value from unnest(event_params) where key='ga_session_id') as session_id,
(select value.string_value from unnest(event_params) where key='button_name') as button_name
from `analytics_xx.events_*`
where user_id = 'abc'

But this assumes I know the key. What if I don't? How can I return all the available keys for that event_name?

The following didn't work:

select event_name,
    (select * from unnest(event_params)) as available_keys
from `analytics_xx.events_*`
where event_name = "button_click"

答案1

得分: 1

select distinct event_params.key
from analytics_xxx.events_*, unnest(event_params) as event_params
where event_name = "button_click"

英文:

One approach would be to unnest the event parameters and access the "key" attribute (distinct).

select distinct event_params.key
from `analytics_xxx.events_*`, unnest(event_params) as event_params
where event_name = "button_click"

huangapple
  • 本文由 发表于 2023年2月16日 05:56:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定