|
| 1 | +WITH potential_new_conversions AS ( |
| 2 | + SELECT |
| 3 | + activity_date, |
| 4 | + FORMAT_DATETIME("%F %T", DATETIME(activity_date, TIME(23, 59, 59))) AS activity_datetime, |
| 5 | + @submission_date AS run_date, |
| 6 | + gclid, |
| 7 | + -- Names as represented in Google Ads |
| 8 | + -- https://docs.google.com/spreadsheets/d/1YzhhvbpOlqPLORRJUZ55BIb0H20hwFqQFApR-r0UMfI |
| 9 | + CASE |
| 10 | + conversion_name |
| 11 | + WHEN "did_firefox_first_run" |
| 12 | + THEN "firefox_first_run" |
| 13 | + WHEN "did_search" |
| 14 | + THEN "firefox_first_search" |
| 15 | + WHEN "did_click_ad" |
| 16 | + THEN "firefox_first_ad_click" |
| 17 | + WHEN "did_returned_second_day" |
| 18 | + THEN "firefox_second_run" |
| 19 | + WHEN "first_wk_5_actv_days_and_1_or_more_search_w_ads" |
| 20 | + THEN "first_wk_5_actv_days_and_1_or_more_search_w_ads" |
| 21 | + WHEN "first_wk_3_actv_days_and_1_or_more_search_w_ads" |
| 22 | + THEN "first_wk_3_actv_days_and_1_or_more_search_w_ads" |
| 23 | + WHEN "first_wk_3_actv_days_and_24_active_minutes" |
| 24 | + THEN "first_wk_3_actv_days_and_24_active_minutes" |
| 25 | + WHEN "is_dau_at_least_4_of_first_7_days" |
| 26 | + THEN "is_dau_at_least_4_of_first_7_days" |
| 27 | + WHEN "is_dau_at_least_3_of_first_7_days" |
| 28 | + THEN "is_dau_at_least_3_of_first_7_days" |
| 29 | + WHEN "is_dau_at_least_2_of_first_7_days" |
| 30 | + THEN "is_dau_at_least_2_of_first_7_days" |
| 31 | + ELSE NULL |
| 32 | + END AS conversion_name, |
| 33 | + FROM |
| 34 | + `moz-fx-data-shared-prod.firefoxdotcom_derived.glean_gclid_conversions_v1` UNPIVOT( |
| 35 | + did_conversion FOR conversion_name IN ( |
| 36 | + did_firefox_first_run, |
| 37 | + did_search, |
| 38 | + did_click_ad, |
| 39 | + did_returned_second_day, |
| 40 | + first_wk_5_actv_days_and_1_or_more_search_w_ads, |
| 41 | + first_wk_3_actv_days_and_1_or_more_search_w_ads, |
| 42 | + first_wk_3_actv_days_and_24_active_minutes, |
| 43 | + is_dau_at_least_4_of_first_7_days, |
| 44 | + is_dau_at_least_3_of_first_7_days, |
| 45 | + is_dau_at_least_2_of_first_7_days |
| 46 | + ) |
| 47 | + ) |
| 48 | + WHERE |
| 49 | + did_conversion |
| 50 | + AND activity_date = @submission_date |
| 51 | +), |
| 52 | +--Google rejects clicks coming multiple days for the same conversion event |
| 53 | +--so we exclude any that we had already sent |
| 54 | +prior_click_conversion_combos AS ( |
| 55 | + SELECT DISTINCT |
| 56 | + gclid, |
| 57 | + conversion_name, |
| 58 | + 1 AS reported_on_different_day_already |
| 59 | + FROM |
| 60 | + `moz-fx-data-shared-prod.firefoxdotcom_derived.glean_ga_desktop_conversions_v1` |
| 61 | + WHERE |
| 62 | + activity_date < @submission_date |
| 63 | +) |
| 64 | +SELECT DISTINCT |
| 65 | + a.activity_date, |
| 66 | + a.activity_datetime, |
| 67 | + a.run_date, |
| 68 | + a.gclid, |
| 69 | + a.conversion_name |
| 70 | +FROM |
| 71 | + potential_new_conversions a |
| 72 | +LEFT OUTER JOIN |
| 73 | + prior_click_conversion_combos b |
| 74 | + ON a.gclid = b.gclid |
| 75 | + AND a.conversion_name = b.conversion_name |
| 76 | +WHERE |
| 77 | + COALESCE(b.reported_on_different_day_already, 0) != 1 |
0 commit comments