WITH first_open AS ( SELECT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Hong_Kong") AS first_open_dt, user_pseudo_id FROM`YourAppChartID.events_*` WHERE event_name = "first_open" AND geo.country <> "China" AND app_info.version = "1.0.20" -- AND user_pseudo_id in ( --SELECT user_pseudo_id --FROM`YourAppChartID.events_*` --WHERE event_name like'%YourDefineData%') ), active as ( SELECTDISTINCT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Hong_Kong") AS active_dt, user_pseudo_id FROM`YourAppChartID.events_*` WHERE event_name <> "app_remove" ), cohort_size AS ( SELECT first_open_dt, COUNT(DISTINCT first_open.user_pseudo_id) AS users FROM first_open GROUPBY1 ) SELECT first_open.first_open_dt AS first_open_dt, DATE_DIFF(active.active_dt, first_open.first_open_dt, DAY) AS days, cohort_size.users AS cohort_users, COUNT(DISTINCT active.user_pseudo_id) as retained, SAFE_DIVIDE(COUNT(DISTINCT active.user_pseudo_id), cohort_size.users) AS retention_rate FROM first_open LEFTJOIN cohort_size ON first_open.first_open_dt = cohort_size.first_open_dt LEFTJOIN active ON first_open.user_pseudo_id = active.user_pseudo_id GROUPBY1,2,3HAVING days IN (1,3,7,30) ORDERBY1,2ASC;
替换App的数据集名字即可使用。
1 2
SELECTDATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Hong_Kong") AS first_open_dt, user_pseudo_id