如何在事件中为多个参数取出数据,其中一个参数的值在事件

时间:2018-01-31 14:20:38

标签: firebase google-bigquery firebase-analytics

举个例子,

event_dim.name = "Start_Level"
event_dim.params.key = "Chapter_Name"
event_dim.params.value.string_value = "chapter_1" (or "chapter_2" or "chapter_3" and so on)
event_dim.params.key = "Level"
event_dim.params.value.int_value = 1 or 2 or 3 or 4 and so on
event_dim.params.key = "Opening_Balance"
event_dim.params.value = 1000 or 1200 or 300 or so on

如果我愿意,如何取出数据: - 查看仅为event_dim.params.string_value =“chapter_1”播放“Level”的唯一用户(意味着第1章中的级别) - 查看每个“级别”的“Opening_Balance”,仅查看event_dim.params.key =“Chapter_Name”和event_dim.params.value.string_value =“chapter_2”

章节中的级别

目前,我正在尝试按照以下方式来获取我认为不会给我正确数据的数据。我试图为在特定日期(通过first_open)和特定来源之间安装游戏的用户取出关卡数据。:

SELECT
  COUNT(DISTINCT(app_instance)),
  event_value.int_value
FROM (
  SELECT
    user_dim.app_info.app_instance_id AS app_instance, 
    event.name AS event,
    (
    SELECT
      user_prop.value.value.int_value
    FROM
      UNNEST(user_dim.user_properties) AS user_prop
    WHERE
      user_prop.key = 'first_open_time') AS first_open,
    params.key AS event_param,
    params.value AS event_value
  FROM
    `app_package.app_events_*`,
    UNNEST(event_dim) AS event,
    UNNEST(event.params) AS params
  WHERE
    event.name = "start_level"
    AND user_dim.traffic_source.user_acquired_source = "source"
    AND params.key != 'firebase_event_origin'
    AND params.key != 'firebase_screen_class'
    AND params.key != 'firebase_screen_id' )
WHERE
  event_param = "Level"
  AND (first_open >= 1516579200000 AND first_open <= 1516924800000)
GROUP BY
  event_value.int_value

但是,我无法隔离事件中chapter_name =“chapter_1”时特定的事件。 (不幸的是我不知道怎么做,因此问题)

更新:(根据Mikhail的要求添加了一些其他信息)

示例输入事件如下:

+-----------------+-------------+-----------------+--------------+-----------+
| app_instance_id | event_name  |    param_key    | string_value | int_value |
+-----------------+-------------+-----------------+--------------+-----------+
|          100001 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 1         |
|                 |             | opening_balance | null         | 2000      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 2500      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 2750      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 3         |
|                 |             | opening_balance | null         | 3000      |
|                 | start_level | chapter_name    | chapter_2    | null      |
|                 |             | level           | null         | 1         |
|                 |             | opening_balance | null         | 3100      |
|                 | start_level | chapter_name    | chapter_2    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 3500      |
|                 | start_level | chapter_name    | chapter_2    | null      |
|                 |             | level           | null         | 3         |
|                 |             | opening_balance | null         | 3800      |
|          100002 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 1         |
|                 |             | opening_balance | null         | 2000      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 2250      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 2400      |
|                 | start_level | chapter_name    | chapter_1    | null      |
|                 |             | level           | null         | 3         |
|                 |             | opening_balance | null         | 2800      |
|                 | start_level | chapter_name    | chapter_2    | null      |
|                 |             | level           | null         | 1         |
|                 |             | opening_balance | null         | 3000      |
|                 | start_level | chapter_name    | chapter_2    | null      |
|                 |             | level           | null         | 2         |
|                 |             | opening_balance | null         | 3200      |
+-----------------+-------------+-----------------+--------------+-----------+

所需输出如下:

+-----------+-------+--------------+-------------------+---------------+
|  Chapter  | Level | Unique Users | Total Level Start | Avg. Open Bal |
+-----------+-------+--------------+-------------------+---------------+
| chapter_1 |     1 |            2 |                 2 |          2000 |
| chapter_1 |     2 |            2 |                 3 |          2383 |
| chapter_1 |     3 |            2 |                 3 |          2850 |
| chapter_2 |     1 |            2 |                 2 |          3050 |
| chapter_2 |     2 |            2 |                 2 |          3350 |
| chapter_2 |     3 |            1 |                 1 |          3800 |
+-----------+-------+--------------+-------------------+---------------+

1 个答案:

答案 0 :(得分:0)

对于正在寻找此问题答案的任何人,您可以尝试以下标准的SQL查询:

SELECT
    chapter,
    level,
    count(distinct id) as Unique_Users,
    count(id) as Level_start,
    avg(opening_balance) as Avg_Open_Bal,
FROM(
SELECT
    user_dim.app_info.app_instance_id AS id,
    event.date,
    event.name,
    (SELECT value.string_value FROM UNNEST(event.params) WHERE key = "chapter_name") AS chapter,
    (SELECT value.int_value FROM UNNEST(event.params) WHERE key = "level") AS level,
    (SELECT value.int_value FROM UNNEST(event.params) WHERE key = "opening_coin_balance") AS open_bal
  FROM
    `<table_name>`,
    UNNEST(event_dim) AS event
  WHERE
    event.name = "start_level"
)
GROUP BY
    chapter,
    level