Bigquery & Firebase Analytics - 如何根据不同的参数选择一个事件

Posted

技术标签:

【中文标题】Bigquery & Firebase Analytics - 如何根据不同的参数选择一个事件【英文标题】:Bigquery & Firebase Analytics - how to select one event based on different parameters 【发布时间】:2017-08-17 11:24:26 【问题描述】:

我正在尝试创建一个查询,让我也可以看到 firebse_event_origin = "auto" 和 firebase_screen_class= TicketViewController 的次数。

我尝试了如下图所示的 AND 语句,但我没有得到任何结果。 (ps。有些情况会发生)。

https://i.stack.imgur.com/XyX2R.png

基本上我想知道的是: firebase_event_origin = "auto" firebase_screen_class= "TicketViewController"

时发生了多少个 screen_view 事件

【问题讨论】:

您能否将查询文本直接包含在您的问题中,而不是作为图像? @ElliottBrossard 当然是 - SELECT * FROM ruter-pilot.no_ruter_RuterPilot_WIP_dev_ios.app_events_intraday_20170823, UNNEST (event_dim) as ed UNNEST (ed.params) as edp WHERE ed.name = "user_engagement" and (edp.key = firebase_event_origin" and (edp.value.string_value = "auto")) and (edp.key = "firebase_screen_class" and edp.value.string_value ="TicketViewController") 【参考方案1】:

这可能是您正在寻找的,或者可能会给您一些见解:

SELECT
  count(1) screen_views
FROM `ruter-pilot.no_ruter_RuterPilot_WPI_IOS.app_events_20170816`
WHERE EXISTS(SELECT 1 FROM UNNEST(event_dim) ed WHERE ed.name = 'user_engagement' AND (EXISTS(SELECT 1 FROM UNNEST(ed.params) params WHERE params.key = 'firebase_event_origin' AND value.string_value = 'auto')) AND(EXISTS(SELECT 1 FROM UNNEST(ed.params) params WHERE params.key = 'firebase_screen_class' AND value.string_value = 'TicketViewController')))

你可以玩模拟数据:

WITH data AS(
  SELECT ARRAY< STRUCT<name STRING, params ARRAY< STRUCT<key STRING, value STRUCT<string_value STRING> > > > > [STRUCT('user_engagement' AS name, [STRUCT('key' AS key, STRUCT('value' AS string_value) AS value ), STRUCT('firebase_event_origin' AS key, STRUCT('auto' AS string_value) AS value )] AS params)] event_dim UNION ALL
  SELECT ARRAY< STRUCT<name STRING, params ARRAY< STRUCT<key STRING, value STRUCT<string_value STRING> > > > > [STRUCT('user_engagement' AS name, [STRUCT('firebase_event_origin' AS key, STRUCT('auto' AS string_value) AS value ), STRUCT('firebase_screen_class' AS key, STRUCT('TicketViewController' AS string_value) AS value )] AS params)] event_dim UNION ALL
  SELECT ARRAY< STRUCT<name STRING, params ARRAY< STRUCT<key STRING, value STRUCT<string_value STRING> > > > > [STRUCT('user_engagement' AS name, [STRUCT('firebase_event_origin' AS key, STRUCT('auto' AS string_value) AS value ), STRUCT('firebase_screen_class' AS key, STRUCT('TicketViewController' AS string_value) AS value ), STRUCT('firebase_event_origin' AS key, STRUCT('auto' AS string_value) AS value ), STRUCT('firebase_screen_class' AS key, STRUCT('TicketViewController' AS string_value) AS value )] AS params)] event_dim UNION ALL
  SELECT ARRAY< STRUCT<name STRING, params ARRAY< STRUCT<key STRING, value STRUCT<string_value STRING> > > > > [STRUCT('user_not_engagement' AS name, [STRUCT('key' AS key, STRUCT('value' AS string_value) AS value ), STRUCT('firebase_event_origin' AS key, STRUCT('auto' AS string_value) AS value )] AS params)] event_dim
  )

SELECT
  count(1) screen_views
FROM data
WHERE EXISTS(SELECT 1 FROM UNNEST(event_dim) ed WHERE ed.name = 'user_engagement' AND (EXISTS(SELECT 1 FROM UNNEST(ed.params) params WHERE params.key = 'firebase_event_origin' AND value.string_value = 'auto')) AND(EXISTS(SELECT 1 FROM UNNEST(ed.params) params WHERE params.key = 'firebase_screen_class' AND value.string_value = 'TicketViewController')))

基本上,该查询会查找其给定事件名称同时触发了指定的params 的用户,并对发生这种情况的所有行进行计数。

【讨论】:

以上是关于Bigquery & Firebase Analytics - 如何根据不同的参数选择一个事件的主要内容,如果未能解决你的问题,请参考以下文章

BigQuery 和 Firebase - 基于键对事件值求和

在 Bigquery - 如何从 Firebase 事件表中查询昨天的数据和过去 7 天的数据

无法通过自定义分析标签聚合 Firebase 通知事件?

从python上传到Bigquery

firebase 和 BigQuery 的保留结果不匹配

如何将所有事件数据从 Firebase 导出到 BigQuery?