|
1 | | -WITH current_list AS ( |
| 1 | +WITH win10_users AS ( |
| 2 | + SELECT DISTINCT |
| 3 | + TO_HEX(SHA256(metrics.string.client_association_uid)) AS fxa_id_sha256, |
| 4 | + FIRST_VALUE(DATE(submission_timestamp)) OVER ( |
| 5 | + PARTITION BY |
| 6 | + TO_HEX(SHA256(metrics.string.client_association_uid)) |
| 7 | + ORDER BY |
| 8 | + submission_timestamp DESC |
| 9 | + ) AS submission_date, |
| 10 | + FIRST_VALUE(client_info.os) OVER ( |
| 11 | + PARTITION BY |
| 12 | + TO_HEX(SHA256(metrics.string.client_association_uid)) |
| 13 | + ORDER BY |
| 14 | + submission_timestamp DESC |
| 15 | + ) AS os, |
| 16 | + FIRST_VALUE(client_info.os_version) OVER ( |
| 17 | + PARTITION BY |
| 18 | + TO_HEX(SHA256(metrics.string.client_association_uid)) |
| 19 | + ORDER BY |
| 20 | + submission_timestamp DESC |
| 21 | + ) AS os_version, |
| 22 | + FIRST_VALUE(client_info.locale) OVER ( |
| 23 | + PARTITION BY |
| 24 | + TO_HEX(SHA256(metrics.string.client_association_uid)) |
| 25 | + ORDER BY |
| 26 | + submission_timestamp DESC |
| 27 | + ) AS locale |
| 28 | + FROM |
| 29 | + `moz-fx-data-shared-prod.firefox_desktop.fx_accounts` |
| 30 | + WHERE |
| 31 | + DATE(submission_timestamp) = @submission_date |
| 32 | + AND client_info.os = 'Windows' |
| 33 | + AND client_info.os_version = '10.0' |
| 34 | +), |
| 35 | +last_seen_14_days AS ( |
| 36 | + SELECT |
| 37 | + user_id_sha256, |
| 38 | + MIN(days_seen_bits) AS last_seen_min |
| 39 | + FROM |
| 40 | + `moz-fx-data-shared-prod.accounts_backend_derived.users_services_last_seen_v1` |
| 41 | + WHERE |
| 42 | + submission_date = @submission_date |
| 43 | + GROUP BY |
| 44 | + 1 |
| 45 | + -- bit pattern 100000000000000, last seen 14 days from submission date |
| 46 | + HAVING |
| 47 | + last_seen_min = 16384 |
| 48 | +), |
| 49 | +inactive_win10_users AS ( |
| 50 | + SELECT |
| 51 | + win10.submission_date, |
| 52 | + last_seen.user_id_sha256, |
| 53 | + win10.os, |
| 54 | + win10.os_version, |
| 55 | + win10.locale |
| 56 | + FROM |
| 57 | + last_seen_14_days AS last_seen |
| 58 | + LEFT JOIN |
| 59 | + win10_users AS win10 |
| 60 | + ON last_seen.user_id_sha256 = win10.fxa_id_sha256 |
| 61 | + -- filter out users that don't have an FX account |
| 62 | + WHERE |
| 63 | + win10.fxa_id_sha256 IS NOT NULL |
| 64 | +), |
| 65 | +current_day_users_to_add AS ( |
| 66 | + SELECT |
| 67 | + inactive.submission_date, |
| 68 | + braze_users.external_id AS external_id, |
| 69 | + -- if user is in our braze users table use their email, otherwise use the email associated with their fxa_id |
| 70 | + IFNULL(braze_users.email, fxa_emails.normalizedEmail) AS email, |
| 71 | + inactive.user_id_sha256, |
| 72 | + inactive.locale |
| 73 | + FROM |
| 74 | + inactive_win10_users AS inactive |
| 75 | + LEFT JOIN |
| 76 | + `moz-fx-data-shared-prod.braze_derived.users_v1` AS braze_users |
| 77 | + ON inactive.user_id_sha256 = braze_users.fxa_id_sha256 |
| 78 | + LEFT JOIN |
| 79 | + `moz-fx-data-shared-prod.accounts_backend_external.emails_v1` AS fxa_emails |
| 80 | + ON inactive.user_id_sha256 = TO_HEX(SHA256(fxa_emails.uid)) |
| 81 | + -- some users have multiple email addresses in this table, only use primary |
| 82 | + AND fxa_emails.isPrimary = TRUE |
| 83 | +), |
| 84 | +current_list AS ( |
2 | 85 | SELECT |
3 | 86 | fxa_id_sha256 |
4 | 87 | FROM |
|
11 | 94 | daily.locale, |
12 | 95 | daily.user_id_sha256 AS fxa_id_sha256 |
13 | 96 | FROM |
14 | | - `moz-fx-data-shared-prod.braze_derived.fxa_win10_users_daily_v1` AS daily |
| 97 | + current_day_users_to_add AS daily |
15 | 98 | LEFT JOIN |
16 | 99 | current_list AS historical |
17 | 100 | ON historical.fxa_id_sha256 = daily.user_id_sha256 |
|
0 commit comments