Advertisement
kirzecy670

Untitled

Jun 10th, 2025
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.95 KB | None | 0 0
  1. WITH article_views AS (
  2.     SELECT
  3.         uid,
  4.         MIN(dt) AS first_view_date,
  5.         visitParamExtractString(addJson, 'option') AS experiment_group
  6.     FROM stat.funnelTrack
  7.     WHERE dt >= '2024-12-01'
  8.       AND action = 'pmr_all_articles_screen'
  9.       [[AND visitParamExtractString(addJson, 'al') = {{locale}}]]
  10.       AND experiment_group in ('new', 'old')
  11.     GROUP BY uid, experiment_group
  12. ),
  13.  
  14. user_cohorts AS (
  15.     SELECT
  16.         av.experiment_group as experiment_group,
  17.         av.uid as uid,
  18.         av.first_view_date as first_view_date,
  19.         pp.full_reg_datetime as full_reg_datetime,
  20.         CASE
  21.             WHEN dateDiff('day', pp.full_reg_datetime, av.first_view_date) < 14 THEN 'A. < 2 weeks'
  22.             WHEN dateDiff('day', pp.full_reg_datetime, av.first_view_date) BETWEEN 14 AND 29 THEN 'B. 2-4 weeks'
  23.             WHEN dateDiff('day', pp.full_reg_datetime, av.first_view_date) BETWEEN 30 AND 119 THEN 'C. 1-4 months'
  24.             WHEN dateDiff('day', pp.full_reg_datetime, av.first_view_date) BETWEEN 120 AND 364 THEN 'D. 4-12 months'
  25.             WHEN dateDiff('day', pp.full_reg_datetime, av.first_view_date) BETWEEN 365 AND 729 THEN 'E. 1-2 years'
  26.             ELSE 'F. > 2 years'
  27.         END AS registration_age_group
  28.     FROM article_views av
  29.     JOIN analytics.parent_properties pp USING (uid)
  30.     WHERE pp.application_language IN ('ru', 'en', 'en-US', 'en-GB', 'de', 'esp', 'pt-BR', 'tr')
  31.       AND pp.full_reg_datetime BETWEEN '2024-12-01' AND '2025-05-01'
  32.       AND abs(dateDiff('day', pp.full_reg_datetime, av.first_view_date)) <= 1
  33.     [[AND registration_age_group = {{weeks_group}}]]
  34. )
  35.  
  36. -- SELECT * FROM user_cohorts;
  37.  
  38. SELECT
  39.     experiment_group,
  40.     action,
  41.     COUNT() AS event_count,
  42.     uniqExact(uid) AS unique_users,
  43.     SUM(unique_users) over (partition by action) as _total_users,
  44.     MAX(unique_users) over (partition by experiment_group) as _group_total_users,
  45.     unique_users/_group_total_users as conversion_rate
  46. FROM stat.funnelTrack
  47. JOIN user_cohorts USING (uid)
  48. WHERE dt >= '2024-12-01'
  49.   AND dt <= full_reg_datetime + interval '7' DAY
  50.   AND action IN (
  51.       'feed_opened_full',
  52.       'block_viewed',
  53.       'articleCarousel_link_click',
  54.       'article_click',
  55.       'articles_block_clicked',
  56.       'article_saved',
  57.       'article_subscribe_open',
  58.       'article_subscribe_click',
  59.       'search_tool_click'
  60.   )
  61.   AND (
  62.       (action = 'block_viewed' AND visitParamExtractString(addJson, 'block_name') = 'articleCarousel')
  63.       OR action = 'articleCarousel_link_click'
  64.       OR action = 'feed_opened_full'
  65.       OR (action = 'article_click' AND visitParamExtractString(addJson, 'ar') = 'all_articles')
  66.       OR action = 'article_saved'
  67.       OR action = 'article_subscribe_open'
  68.       OR action = 'article_subscribe_click'
  69.       OR action = 'search_tool_click'
  70.       OR action = 'articles_block_clicked'
  71.   )
  72. GROUP BY action, experiment_group
  73. ORDER BY _total_users DESC, action, experiment_group
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement