按用户ID分组的BigQuery Firebase事件日志

时间:2018-07-30 16:21:05

标签: firebase google-bigquery firebase-analytics

问题:对于Android用户,我想提取按用户ID分组并按发生时间排序的Firebase事件数据流。我在下面创建了两个脚本,但是不幸的是,在这两个脚本中,我似乎都无法正确理解最后一部分,这是首先成功地将所有app_instance_ids分组,而不考虑时间戳。我也许应该看看改用不同的user_ids?

失败的尝试1:

SELECT
  d.userid,
  c.ev_timestamp,
  c.ev_name
FROM (SELECT 
        user_dim.app_info.app_instance_id as userid
      FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS event
      WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
      AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000
      GROUP BY 1) AS d
  LEFT JOIN (SELECT user_dim.app_info.app_instance_id as userid,
            event.timestamp_micros as ev_timestamp,
            event.name as ev_name
            FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS event
            WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
            AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000) AS c
  ON d.userid = c.userid
ORDER BY 2 ASC
LIMIT 1000;

enter image description here

尝试2:失败

SELECT
  d.userid,
  d.ev_timestamp,
  c.ev_name
FROM (SELECT 
        user_dim.app_info.app_instance_id as userid,
        event.timestamp_micros as ev_timestamp
      FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS event
      WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
      AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000
      GROUP BY 1,2
      ORDER BY 2 ASC) AS d
  LEFT JOIN (SELECT user_dim.app_info.app_instance_id as userid,
            event.timestamp_micros as ev_timestamp,
            event.name as ev_name
            FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS event
            WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
            AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000) AS c
  ON d.userid = c.userid AND d.ev_timestamp = c.ev_timestamp
#ORDER BY 2 ASC
LIMIT 1000;

enter image description here

正确答案(Amod的答案已转换为“新导出方案”):

SELECT user_pseudo_id, event_timestamp, event_name
FROM `xxxx.analytics_xxxx.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20180630' AND '20180702'
AND user_first_touch_timestamp BETWEEN 1530453600000000 AND 1530468000000000
AND platform = "ANDROID"
ORDER BY 1,2 ASC
LIMIT 1000

1 个答案:

答案 0 :(得分:1)

尝试

    SELECT user_dim.app_info.app_instance_id as userid, X.timestamp_micros,X.name as ev_name,X
FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS X
WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
      AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000
      and user_dim.app_info.app_instance_id like 'C4%'
      order by 1,2 ASC

SELECT user_dim.app_info.app_instance_id as userid, X.timestamp_micros,X.name as ev_name
FROM `firebase-analytics-sample-data.ios_dataset.app_events_*`, UNNEST(event_dim) AS X
WHERE _TABLE_SUFFIX BETWEEN '20160601' AND '20160603'
      AND user_dim.first_open_timestamp_micros BETWEEN 1464789600000000 AND 1464962400000000
      order by 1,2 ASC