Skip to content

Commit 072c456

Browse files
authored
feat: build win10 user targeting for braze to start ip warming (#8135)
* feat: build win10 user targeting for braze * reworking win10 users to handle duplication and create braze sync table * refactor braze derived and external tables for windows 10 sync * change incremental strategy to true
1 parent 5bbba8b commit 072c456

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
friendly_name: Fxa Win10 Users Daily
2+
description: |-
3+
This query identifies Firefox Accounts users on Windows 10 who have been inactive for exactly 14 days and
4+
prepares their records for Braze by assigning an external ID and email.
5+
owners:
6+
7+
labels:
8+
incremental: false
9+
schedule: daily
10+
owner: lmcfall
11+
scheduling:
12+
dag_name: bqetl_braze
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 DISTINCT
37+
user_id_sha256
38+
FROM
39+
`moz-fx-data-shared-prod.accounts_backend_derived.users_services_last_seen_v1`
40+
WHERE
41+
submission_date = @submission_date
42+
-- bit pattern 100000000000000, last seen 14 days from submission date
43+
AND days_seen_bits = 16384
44+
),
45+
inactive_win10_users AS (
46+
SELECT
47+
win10.submission_date,
48+
last_seen.user_id_sha256,
49+
win10.os,
50+
win10.os_version,
51+
win10.locale
52+
FROM
53+
last_seen_14_days AS last_seen
54+
LEFT JOIN
55+
win10_users AS win10
56+
ON last_seen.user_id_sha256 = win10.fxa_id_sha256
57+
-- filter out users that don't have an FX account
58+
WHERE
59+
win10.fxa_id_sha256 IS NOT NULL
60+
)
61+
SELECT
62+
inactive.submission_date,
63+
braze_users.external_id AS external_id,
64+
-- if user is in our braze users table use their email, otherwise use the email associated with their fxa_id
65+
IFNULL(braze_users.email, fxa_emails.normalizedEmail) AS email,
66+
inactive.user_id_sha256,
67+
inactive.locale
68+
FROM
69+
inactive_win10_users AS inactive
70+
LEFT JOIN
71+
`moz-fx-data-shared-prod.braze_derived.users_v1` AS braze_users
72+
ON inactive.user_id_sha256 = braze_users.fxa_id_sha256
73+
LEFT JOIN
74+
`moz-fx-data-shared-prod.accounts_backend_external.emails_v1` AS fxa_emails
75+
ON inactive.user_id_sha256 = TO_HEX(SHA256(fxa_emails.uid))
76+
-- some users have multiple email addresses in this table, only use primary
77+
AND fxa_emails.isPrimary = TRUE
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
friendly_name: Fxa Win10 Users Historical
2+
description: |-
3+
This query compiles the full list of Win10 users who have reached 14 days of inactivity.
4+
5+
owners:
6+
7+
labels:
8+
incremental: true
9+
schedule: daily
10+
owner: lmcfall
11+
scheduling:
12+
dag_name: bqetl_braze
13+
bigquery:
14+
time_partitioning:
15+
type: day
16+
field: submission_date
17+
require_partition_filter: false
18+
expiration_days: null
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
WITH current_list AS (
2+
SELECT
3+
fxa_id_sha256
4+
FROM
5+
`moz-fx-data-shared-prod.braze_derived.fxa_win10_users_historical_v1`
6+
)
7+
SELECT
8+
daily.submission_date,
9+
IFNULL(daily.external_id, TO_HEX(SHA256(GENERATE_UUID()))) AS external_id,
10+
daily.email,
11+
daily.locale,
12+
daily.user_id_sha256 AS fxa_id_sha256
13+
FROM
14+
`moz-fx-data-shared-prod.braze_derived.fxa_win10_users_daily_v1` AS daily
15+
LEFT JOIN
16+
current_list AS historical
17+
ON historical.fxa_id_sha256 = daily.user_id_sha256
18+
WHERE
19+
submission_date = @submission_date
20+
AND daily.email IS NOT NULL
21+
-- FILTER OUT USERS ALREADY IN THE LIST
22+
AND historical.fxa_id_sha256 IS NULL
23+
-- ONLY FOR EMAIL WARMING IN en-US LOCALE
24+
-- REMOVE THIS FILTER BEFORE 10/14/2025 WHEN FULL CAMPAIGN STARTS
25+
AND daily.locale = 'en-US'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
friendly_name: Win10 Users Sync
2+
description: |-
3+
This table will sync inactive Windows 10 Firefox users to Braze to be contacted
4+
in the Win10 Inactive User Campaign.
5+
owners:
6+
7+
labels:
8+
incremental: true
9+
owner1: lmcfall
10+
scheduling:
11+
dag_name: bqetl_braze
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SELECT
2+
CURRENT_TIMESTAMP() AS updated_at,
3+
external_id,
4+
TO_JSON(
5+
STRUCT(
6+
email AS email,
7+
"subscribed" AS email_subscribe,
8+
STRUCT(
9+
"718eea53-371c-4cc6-9fdc-1260b1311bd8" AS subscription_group_id,
10+
"subscribed" AS subscription_state
11+
) AS subscription_groups,
12+
locale AS locale,
13+
fxa_id_sha256
14+
)
15+
) AS payload
16+
FROM
17+
`moz-fx-data-shared-prod.braze_derived.fxa_win10_users_historical_v1`
18+
WHERE
19+
submission_date = @submission_date

0 commit comments

Comments
 (0)