Skip to content

Commit 1763ecb

Browse files
Changes to active_users_aggregates query for Mobile (#5396)
* Changes to active_users_aggregates. * Remove days_since_seen and calculate activity segment. * Remove is_core_active not required. * Remove days_seen_bits from mobile queries not required. * Adjust mobile query to use the baseline_clients_last_seen views. * Update Focus Android query to use the baseline_clients_last_seen view. * Get activity segments from the views instead of hard-coding it. Query attribution only when neccesary to improve performance. Delay update by 1 day to get metrics ping's data. * Get app_name from clients_last_seen_v2 view. * Set activity_segment as NULL for legacy Focus Android. * Formatting * Remove first_seen_date and correct column name in desktop_query.sql * Update active_users_aggregates query for Desktop to get app_name and growth metrics from clients_last_seen_v2, replace language_name with locale and remove search metrics based on sprint decision (see DENG-1989). * Update active_users_aggregates query for Mobile to remove search metrics based on sprint decision (see DENG-1989) and calculate the min metrics ping received between the current and next date, given that these pings can arrive in the same or next date as the baseline ping. * Revert changes to Desktop queries in this PR, as this implementation is separated to [PR-5607](#5607). * Space * Formatting. * Change name of activity_segment to segment. * Fix reference to app name. * Update app_anme in checks for Focus * Use active_users instead of baseline_clients_last_seen and improve retrieving metrics ping's data. * Formatting. * Get distribution_id for Fenix. * Get distribution_id for Fenix. --------- Co-authored-by: Brad Ochocki Szasz <[email protected]>
1 parent f7f707d commit 1763ecb

File tree

6 files changed

+203
-314
lines changed

6 files changed

+203
-314
lines changed

sql_generators/active_users_aggregates_v3/templates/focus_android_query.sql

Lines changed: 89 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ WITH baseline AS (
44
submission_date,
55
normalized_channel,
66
client_id,
7-
days_since_seen,
8-
days_seen_bits,
97
days_created_profile_bits,
10-
durations,
118
os AS normalized_os,
129
osversion AS normalized_os_version,
1310
locale,
@@ -17,11 +14,16 @@ WITH baseline AS (
1714
device AS device_model,
1815
first_seen_date,
1916
submission_date = first_seen_date AS is_new_profile,
20-
NULL AS uri_count,
21-
default_browser AS is_default_browser,
2217
distribution_id,
2318
CAST(NULL AS string) AS isp,
24-
'Focus Android' AS app_name
19+
'Focus Android Legacy' AS app_name,
20+
CAST(NULL AS STRING) AS segment,
21+
CAST(NULL AS BOOLEAN) AS is_daily_user,
22+
CAST(NULL AS BOOLEAN) AS is_weekly_user,
23+
CAST(NULL AS BOOLEAN) AS is_monthly_user,
24+
CAST(NULL AS BOOLEAN) AS is_dau,
25+
CAST(NULL AS BOOLEAN) AS is_wau,
26+
CAST(NULL AS BOOLEAN) AS is_mau
2527
FROM
2628
`{{ project_id }}.telemetry.core_clients_last_seen`
2729
WHERE
@@ -33,10 +35,7 @@ WITH baseline AS (
3335
submission_date,
3436
normalized_channel,
3537
client_id,
36-
days_since_seen,
37-
days_seen_bits,
3838
days_created_profile_bits,
39-
durations,
4039
normalized_os,
4140
normalized_os_version,
4241
locale,
@@ -46,127 +45,97 @@ WITH baseline AS (
4645
device_model,
4746
first_seen_date,
4847
submission_date = first_seen_date AS is_new_profile,
49-
uri_count,
50-
is_default_browser,
5148
CAST(NULL AS string) AS distribution_id,
5249
isp,
53-
'Focus Android Glean' AS app_name
50+
app_name,
51+
activity_segment AS segment,
52+
is_daily_user,
53+
is_weekly_user,
54+
is_monthly_user,
55+
is_dau,
56+
is_wau,
57+
is_mau
5458
FROM
55-
`{{ project_id }}.{{ app_name }}.clients_last_seen_joined`
59+
`{{ project_id }}.{{ app_name }}.active_users`
5660
WHERE
5761
submission_date = @submission_date
5862
),
59-
unioned AS (
60-
SELECT
61-
* REPLACE (IF(isp = 'BrowserStack', CONCAT(app_name, ' BrowserStack'), app_name) AS app_name)
62-
FROM
63-
baseline
64-
),
65-
search_clients AS (
63+
metrics AS (
64+
-- Metrics ping can arrive either in the same or next day as the baseline ping.
6665
SELECT
6766
client_id,
68-
submission_date,
69-
ad_click,
70-
organic,
71-
search_count,
72-
search_with_ads
67+
ARRAY_AGG(normalized_channel IGNORE NULLS ORDER BY submission_date ASC)[
68+
SAFE_OFFSET(0)
69+
] AS normalized_channel,
70+
ARRAY_AGG(uri_count IGNORE NULLS ORDER BY submission_date ASC)[SAFE_OFFSET(0)] AS uri_count,
71+
ARRAY_AGG(is_default_browser IGNORE NULLS ORDER BY submission_date ASC)[
72+
SAFE_OFFSET(0)
73+
] AS is_default_browser
7374
FROM
74-
`moz-fx-data-shared-prod.search_derived.mobile_search_clients_daily_v1`
75+
`{{ project_id }}.{{ app_name }}.metrics_clients_last_seen`
7576
WHERE
76-
submission_date = @submission_date
77-
),
78-
search_metrics AS (
79-
SELECT
80-
unioned.client_id,
81-
unioned.submission_date,
82-
SUM(ad_click) AS ad_clicks,
83-
SUM(organic) AS organic_search_count,
84-
SUM(search_count) AS search_count,
85-
SUM(search_with_ads) AS search_with_ads
86-
FROM
87-
unioned
88-
LEFT JOIN
89-
search_clients s
90-
ON unioned.client_id = s.client_id
91-
AND unioned.submission_date = s.submission_date
77+
DATE(submission_date)
78+
BETWEEN @submission_date
79+
AND DATE_ADD(@submission_date, INTERVAL 1 DAY)
9280
GROUP BY
93-
client_id,
94-
submission_date
81+
client_id
9582
),
96-
unioned_with_searches AS (
83+
unioned AS (
9784
SELECT
98-
unioned.client_id,
99-
CASE
100-
WHEN BIT_COUNT(days_seen_bits)
101-
BETWEEN 1
102-
AND 6
103-
THEN 'infrequent_user'
104-
WHEN BIT_COUNT(days_seen_bits)
105-
BETWEEN 7
106-
AND 13
107-
THEN 'casual_user'
108-
WHEN BIT_COUNT(days_seen_bits)
109-
BETWEEN 14
110-
AND 20
111-
THEN 'regular_user'
112-
WHEN BIT_COUNT(days_seen_bits) >= 21
113-
THEN 'core_user'
114-
ELSE 'other'
115-
END AS activity_segment,
116-
unioned.app_name,
117-
unioned.app_display_version AS app_version,
118-
unioned.normalized_channel,
119-
IFNULL(country, '??') country,
120-
unioned.city,
121-
unioned.days_seen_bits,
122-
unioned.days_created_profile_bits,
123-
DATE_DIFF(unioned.submission_date, unioned.first_seen_date, DAY) AS days_since_first_seen,
124-
unioned.device_model,
125-
unioned.isp,
126-
unioned.is_new_profile,
127-
unioned.locale,
128-
unioned.first_seen_date,
129-
unioned.days_since_seen,
130-
unioned.normalized_os,
131-
unioned.normalized_os_version,
85+
baseline.client_id,
86+
baseline.segment,
87+
baseline.app_name,
88+
baseline.app_display_version AS app_version,
89+
baseline.normalized_channel,
90+
IFNULL(baseline.country, '??') country,
91+
baseline.city,
92+
baseline.days_created_profile_bits,
93+
baseline.device_model,
94+
baseline.isp,
95+
baseline.is_new_profile,
96+
baseline.locale,
97+
baseline.first_seen_date,
98+
baseline.normalized_os,
99+
baseline.normalized_os_version,
132100
COALESCE(
133-
SAFE_CAST(NULLIF(SPLIT(unioned.normalized_os_version, ".")[SAFE_OFFSET(0)], "") AS INTEGER),
101+
SAFE_CAST(NULLIF(SPLIT(baseline.normalized_os_version, ".")[SAFE_OFFSET(0)], "") AS INTEGER),
134102
0
135103
) AS os_version_major,
136104
COALESCE(
137-
SAFE_CAST(NULLIF(SPLIT(unioned.normalized_os_version, ".")[SAFE_OFFSET(1)], "") AS INTEGER),
105+
SAFE_CAST(NULLIF(SPLIT(baseline.normalized_os_version, ".")[SAFE_OFFSET(1)], "") AS INTEGER),
138106
0
139107
) AS os_version_minor,
140108
COALESCE(
141-
SAFE_CAST(NULLIF(SPLIT(unioned.normalized_os_version, ".")[SAFE_OFFSET(2)], "") AS INTEGER),
109+
SAFE_CAST(NULLIF(SPLIT(baseline.normalized_os_version, ".")[SAFE_OFFSET(2)], "") AS INTEGER),
142110
0
143111
) AS os_version_patch,
144-
unioned.durations AS durations,
145-
unioned.submission_date,
146-
unioned.uri_count,
147-
unioned.is_default_browser,
148-
unioned.distribution_id,
112+
baseline.submission_date,
113+
metrics.uri_count,
114+
metrics.is_default_browser,
115+
baseline.distribution_id,
149116
CAST(NULL AS string) AS attribution_content,
150117
CAST(NULL AS string) AS attribution_source,
151118
CAST(NULL AS string) AS attribution_medium,
152119
CAST(NULL AS string) AS attribution_campaign,
153120
CAST(NULL AS string) AS attribution_experiment,
154121
CAST(NULL AS string) AS attribution_variation,
155-
search.ad_clicks,
156-
search.organic_search_count,
157-
search.search_count,
158-
search.search_with_ads,
159-
CAST(NULL AS FLOAT64) AS active_hours_sum
122+
CAST(NULL AS FLOAT64) AS active_hours_sum,
123+
is_daily_user,
124+
is_weekly_user,
125+
is_monthly_user,
126+
is_dau,
127+
is_wau,
128+
is_mau
160129
FROM
161-
unioned
130+
baseline
162131
LEFT JOIN
163-
search_metrics search
164-
ON search.client_id = unioned.client_id
165-
AND search.submission_date = unioned.submission_date
132+
metrics
133+
ON baseline.client_id = metrics.client_id
134+
AND baseline.normalized_channel IS NOT DISTINCT FROM metrics.normalized_channel
166135
),
167136
todays_metrics AS (
168137
SELECT
169-
activity_segment AS segment,
138+
segment,
170139
app_version,
171140
attribution_medium,
172141
attribution_source,
@@ -184,63 +153,43 @@ todays_metrics AS (
184153
normalized_os_version AS os_version,
185154
os_version_major,
186155
os_version_minor,
187-
durations,
188156
submission_date,
189-
days_since_seen,
190157
client_id,
191-
first_seen_date,
192-
ad_clicks,
193-
organic_search_count,
194-
search_count,
195-
search_with_ads,
196158
uri_count,
197159
active_hours_sum,
160+
is_daily_user,
161+
is_weekly_user,
162+
is_monthly_user,
163+
is_dau,
164+
is_wau,
165+
is_mau,
198166
CAST(NULL AS STRING) AS adjust_network,
199167
CAST(NULL AS STRING) AS install_source
200168
FROM
201-
unioned_with_searches
202-
),
203-
todays_metrics_enriched AS (
204-
SELECT
205-
todays_metrics.* EXCEPT (locale),
206-
CASE
207-
WHEN locale IS NOT NULL
208-
AND languages.language_name IS NULL
209-
THEN 'Other'
210-
ELSE languages.language_name
211-
END AS language_name,
212-
FROM
213-
todays_metrics
214-
LEFT JOIN
215-
`mozdata.static.csa_gblmkt_languages` AS languages
216-
ON todays_metrics.locale = languages.code
169+
unioned
217170
)
218171
SELECT
219-
todays_metrics_enriched.* EXCEPT (
172+
todays_metrics.* EXCEPT (
220173
client_id,
221-
days_since_seen,
222-
ad_clicks,
223-
organic_search_count,
224-
search_count,
225-
search_with_ads,
174+
is_daily_user,
175+
is_weekly_user,
176+
is_monthly_user,
177+
is_dau,
178+
is_wau,
179+
is_mau,
226180
uri_count,
227-
active_hours_sum,
228-
first_seen_date,
229-
durations
181+
active_hours_sum
230182
),
231-
COUNT(DISTINCT IF(days_since_seen = 0, client_id, NULL)) AS daily_users,
232-
COUNT(DISTINCT IF(days_since_seen < 7, client_id, NULL)) AS weekly_users,
233-
COUNT(DISTINCT client_id) AS monthly_users,
234-
COUNT(DISTINCT IF(days_since_seen = 0 AND durations > 0, client_id, NULL)) AS dau,
235-
COUNT(DISTINCT IF(submission_date = first_seen_date, client_id, NULL)) AS new_profiles,
236-
SUM(ad_clicks) AS ad_clicks,
237-
SUM(organic_search_count) AS organic_search_count,
238-
SUM(search_count) AS search_count,
239-
SUM(search_with_ads) AS search_with_ads,
183+
COUNTIF(is_daily_user) AS daily_users,
184+
COUNTIF(is_weekly_user) AS weekly_users,
185+
COUNTIF(is_monthly_user) AS monthly_users,
186+
COUNTIF(is_dau) AS dau,
187+
COUNTIF(is_wau) AS wau,
188+
COUNTIF(is_mau) AS mau,
240189
SUM(uri_count) AS uri_count,
241190
SUM(active_hours_sum) AS active_hours,
242191
FROM
243-
todays_metrics_enriched
192+
todays_metrics
244193
GROUP BY
245194
app_version,
246195
attribution_medium,
@@ -251,7 +200,7 @@ GROUP BY
251200
distribution_id,
252201
first_seen_year,
253202
is_default_browser,
254-
language_name,
203+
locale,
255204
app_name,
256205
channel,
257206
os,

sql_generators/active_users_aggregates_v3/templates/focus_android_view.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE OR REPLACE VIEW
55
AS
66
SELECT
77
* EXCEPT (app_version, app_name),
8-
IF(app_name IN ('Focus Android Glean', 'Focus Android'), 'Focus Android', app_name) AS app_name,
8+
app_name,
99
app_version,
1010
`mozfun.norm.browser_version_info`(app_version).major_version AS app_version_major,
1111
`mozfun.norm.browser_version_info`(app_version).minor_version AS app_version_minor,
@@ -15,4 +15,4 @@ SELECT
1515
FROM
1616
`{{ project_id }}.{{ app_name }}_derived.{{ table_name }}`
1717
WHERE
18-
app_name IN ('Focus Android Glean', 'Focus Android Glean BrowserStack')
18+
app_name != 'Focus Android Legacy'

sql_generators/active_users_aggregates_v3/templates/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ labels:
2525
scheduling:
2626
dag_name: bqetl_analytics_aggregations
2727
task_name: {{ app_name }}_active_users_aggregates
28+
date_partition_offset: -1
2829
bigquery:
2930
time_partitioning:
3031
type: day

sql_generators/active_users_aggregates_v3/templates/mobile_checks.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ WITH daily_users_sum AS (
1919
WHERE
2020
submission_date = @submission_date
2121
{% if app_name == "focus_android" -%}
22-
AND app_name IN ('Focus Android Glean', 'Focus Android Glean BrowserStack')
22+
AND app_name IN ('Focus Android', 'Focus Android BrowserStack')
2323
{% endif -%}
2424
),
2525
distinct_client_count_base AS (

0 commit comments

Comments
 (0)