diff --git a/bigquery_etl/shredder/config.py b/bigquery_etl/shredder/config.py index a269a7a4e8..66c41de560 100755 --- a/bigquery_etl/shredder/config.py +++ b/bigquery_etl/shredder/config.py @@ -161,6 +161,9 @@ DELETE_TARGETS: DeleteIndex = { client_id_target(table="fenix_derived.new_profile_activation_v1"): FENIX_SRC, client_id_target(table="fenix_derived.firefox_android_clients_v1"): FENIX_SRC, client_id_target(table="search_derived.acer_cohort_v1"): DESKTOP_SRC, + client_id_target( + table="firefox_ios_derived.clients_activation_v1" + ): FIREFOX_IOS_SRC, client_id_target( table="search_derived.mobile_search_clients_daily_v1" ): DESKTOP_SRC, diff --git a/sql/moz-fx-data-shared-prod/firefox_ios/clients_activation/view.sql b/sql/moz-fx-data-shared-prod/firefox_ios/clients_activation/view.sql new file mode 100644 index 0000000000..5d42a4da35 --- /dev/null +++ b/sql/moz-fx-data-shared-prod/firefox_ios/clients_activation/view.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE VIEW + `moz-fx-data-shared-prod.firefox_ios.clients_activation` +AS +SELECT + * +FROM + `moz-fx-data-shared-prod.firefox_ios_derived.clients_activation_v1` diff --git a/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/checks.sql b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/checks.sql new file mode 100644 index 0000000000..d91af3e96d --- /dev/null +++ b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/checks.sql @@ -0,0 +1,30 @@ +#fail +{{ is_unique(["client_id"]) }} +#fail +{{ min_row_count(1, "`submission_date` = @submission_date") }} +#fail +WITH upstream_clients_count AS ( + SELECT COUNT(*) + FROM `{{ project_id }}.firefox_ios.firefox_ios_clients` + WHERE first_seen_date = DATE_SUB(@submission_date, INTERVAL 6 DAY) +), +activations_clients_count AS ( + SELECT COUNT(*) + FROM `{{ project_id }}.{{ dataset_id }}.{{ table_name }}` + WHERE submission_date = @submission_date +) +SELECT + IF( + (SELECT * FROM upstream_clients_count) <> (SELECT * FROM activations_clients_count), + ERROR("Number of client records should match for the same first_seen_date."), + NULL + ); +#fail +SELECT + IF( + DATE_DIFF(submission_date, first_seen_date, DAY) <> 6, + ERROR("Day difference between values inside first_seen_date and submission_date fields should be 6."), + NULL + ) +FROM `{{ project_id }}.{{ dataset_id }}.{{ table_name }}` +WHERE `submission_date` = @submission_date; diff --git a/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/metadata.yaml b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/metadata.yaml new file mode 100644 index 0000000000..45c74c084a --- /dev/null +++ b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/metadata.yaml @@ -0,0 +1,26 @@ +friendly_name: Clients Activation (Firefox iOS) +description: |- + Mobile activation metric used for Marketing campaign performance. + A records per client indicating whether they became activated. + + Activated means, a week has elapsed since the client was first seen + and within days 2 and 7 they had at least one instance of activity along + along with at least 1 search count. +owners: +- vsabino@mozilla.com +- kik@mozilla.com +labels: + incremental: true +bigquery: + time_partitioning: + type: day + field: submission_date + require_partition_filter: false + expiration_days: null + clustering: + fields: + - sample_id +scheduling: + dag_name: bqetl_firefox_ios + date_partition_parameter: submission_date + depends_on_past: false diff --git a/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/query.sql b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/query.sql new file mode 100644 index 0000000000..74d95fa2fc --- /dev/null +++ b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/query.sql @@ -0,0 +1,66 @@ +-- This table implements the Mobile activation metric defined in June 2022 +-- Based on data from the first seven days since profile creation, we select +-- clients with at least three days of use (first open plus two) and who +-- perform a search on the later half of the week. As such, this table will +-- always lag new profiles by seven days and the CTEs are filtered for +-- corresponding periods. +-- Each entry in this table corresponds to a new_profile +WITH new_clients AS ( + SELECT + client_id, + first_seen_date, + sample_id, + channel, + FROM + firefox_ios.firefox_ios_clients + WHERE + first_seen_date = DATE_SUB(@submission_date, INTERVAL 6 DAY) +), +new_clients_activity AS ( + SELECT + client_id, + first_seen_date, + sample_id, + normalized_channel AS channel, + ARRAY_LENGTH( + mozfun.bits28.to_dates(mozfun.bits28.range(days_seen_bits, -5, 6), submission_date) + ) AS days_2_7, + FROM + firefox_ios.baseline_clients_last_seen + WHERE + submission_date = @submission_date + AND DATE_DIFF(submission_date, first_seen_date, DAY) = 6 +), +clients_search AS ( + SELECT + client_id, + sample_id, + channel, + SUM(search_count) AS search_count + FROM + search_derived.mobile_search_clients_daily_v1 + WHERE + (submission_date BETWEEN DATE_SUB(@submission_date, INTERVAL 3 DAY) AND @submission_date) + AND os = 'iOS' + AND normalized_app_name = 'Fennec' + GROUP BY + client_id, + sample_id, + channel +) +SELECT + @submission_date AS submission_date, + first_seen_date, + client_id, + sample_id, + (days_2_7 > 1 AND COALESCE(search_count, 0) > 0) AS is_activated, +FROM + new_clients +LEFT JOIN + new_clients_activity +USING + (client_id, first_seen_date, sample_id, channel) +LEFT JOIN + clients_search +USING + (client_id, sample_id, channel) diff --git a/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/schema.yaml b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/schema.yaml new file mode 100644 index 0000000000..5d04add361 --- /dev/null +++ b/sql/moz-fx-data-shared-prod/firefox_ios_derived/clients_activation_v1/schema.yaml @@ -0,0 +1,31 @@ +fields: + +- mode: NULLABLE + name: submission_date + type: DATE + description: | + Date when a client activated. + +- mode: NULLABLE + name: first_seen_date + type: DATE + description: | + Date when the app first reported a baseline ping for the client. + +- mode: NULLABLE + name: client_id + type: STRING + description: | + Unique ID for the client installation. + +- mode: NULLABLE + name: sample_id + type: INTEGER + description: | + Sample ID to limit query results during an analysis. + +- mode: NULLABLE + name: is_activated + type: BOOLEAN + description: | + Determines if a client is activated based on the activation metric and a 7 day lag.