Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with
- event_counts AS (
- SELECT
- ft.uid,
- ft.dt,
- CASE
- WHEN (deviceType = 2 AND appVersion % 2 = 0) THEN 'iOS_Parent'
- WHEN (deviceType = 1 AND appVersion % 2 = 1) THEN 'Android_Parent'
- WHEN (deviceType = 2 AND appVersion % 2 = 1) THEN 'iOS_Child'
- WHEN (deviceType = 1 AND appVersion % 2 = 0) THEN 'Android_Child'
- ELSE 'Unknown'
- END AS platform,
- had_any_payment,
- ft.dt >= pp.full_reg_datetime + interval '30' day as flg_30day_old_user,
- region,
- MAX(ft.action in ('open', 'open_parent_activity', 'open_parent_screen')) AS open,
- COUNT(ft.uid) FILTER (WHERE ft.action in ('open', 'open_parent_activity', 'open_parent_screen')) AS open_count,
- MAX(ft.action = 'feed_opened_full') AS is_feed_opened_full,
- COUNT(ft.uid) FILTER (WHERE ft.action = 'feed_opened_full') AS feed_opened_full_count,
- MAX(ft.action = 'open_function_records') AS is_open_function_records,
- COUNT(ft.uid) FILTER (WHERE ft.action = 'open_function_records') AS open_records_count,
- MAX(ft.action = 'open_function_noise') AS is_open_function_noise,
- COUNT(ft.uid) FILTER (WHERE ft.action = 'open_function_noise') AS open_noise_count,
- MAX(ft.action = 'open_function_zones') AS is_open_function_zones,
- COUNT(ft.uid) FILTER (WHERE ft.action = 'open_function_zones') AS open_zones_count,
- MAX(ft.action = 'open_function_appstat') AS is_open_function_appstat,
- COUNT(ft.uid) FILTER (WHERE ft.action = 'open_function_appstat') AS open_appstat_count,
- MAX(ft.action IN (
- 'open_function_records',
- 'open_function_noise',
- 'open_function_zones',
- 'open_function_appstat'
- )) AS is_any_feature_used
- FROM
- stat.funnelTrack ft join analytics.parent_properties pp using uid
- WHERE ft.dt >= '2025-04-01'
- AND ft.action IN (
- 'open', 'open_parent_activity', 'open_parent_screen',
- 'feed_opened_full',
- 'open_function_records', 'open_function_noise', 'open_function_zones',
- 'open_function_appstat'
- )
- GROUP BY 1, 2, 3, 4, 5, 6
- )
- SELECT
- dt,
- platform,
- had_any_payment,
- flg_30day_old_user,
- region,
- uniq(uid) as total_users, -- Debug: total users in event_counts
- uniqIf(uid, open) active_users,
- uniqIf(uid, is_any_feature_used) users_with_any_feature,
- uniqIf(uid, is_feed_opened_full) as users_feed_opened,
- uniqIf(uid, is_open_function_records) as users_records,
- uniqIf(uid, is_open_function_appstat) as users_appstat,
- uniqIf(uid, is_open_function_zones) as users_zones,
- round(users_with_any_feature/active_users, 4) as use_any_feature
- FROM event_counts
- group by 1, 2, 3, 4, 5
- ORDER BY dt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement