我想选择第一次访问我们的应用程序的用户
event.name = "first_open"
及其随后的访问
在接下来的几周内event.name = "user_engagement"
。
我到目前为止的查询是:
SELECT user_dim.app_info.app_instance_id AS id,
FORMAT_DATE('%Y-%W', PARSE_DATE('%Y%m%d', event.date)) AS period,
event.name
FROM `database.app_events_*`,
UNNEST(event_dim) AS event
WHERE event.name IN ("first_open", "user_engagement")
AND (_TABLE_SUFFIX BETWEEN '20180205' AND '20180330')
GROUP BY id, period, event.name
HAVING COUNT(id) >=2
ORDER BY id asc
但它包括那段时间内第一次没有打开应用程序的常规用户。如何排除这些?
答案 0 :(得分:0)
如果不了解您的事件结构或跟踪逻辑,我很难优化我的响应,但基本上我采用的方法是ID字段上的子查询(例如id in ( select id from ... where event_name = 'first_open'
)而不是单个查询寻找两者;或者,如果您想确保事件实际发生在以后(假设您在第一个会话期间也跟踪user_engagement
),请使用自联接来检查相同的ID但仅基于以后的事件事件的时间戳或会话标识符。
答案 1 :(得分:0)
这样的东西?
#standardSQL
SELECT user_dim.app_info.app_instance_id AS id, COUNT(*) as visits
FROM `data.source`,
UNNEST(event_dim) AS event
WHERE event.name = 'user_engagement' AND
user_dim.app_info.app_instance_id IN (SELECT
user_dim.app_info.app_instance_id FROM UNNEST(event_dim) AS event
WHERE event.name = 'first_open')
GROUP BY id
HAVING COUNT(id) >= 2
ORDER BY visits DESC