diff --git a/bq_queries/optional_tables/ad_group_network_split_extended.sql b/bq_queries/optional_tables/ad_group_network_split_extended.sql new file mode 100644 index 0000000..5caa21d --- /dev/null +++ b/bq_queries/optional_tables/ad_group_network_split_extended.sql @@ -0,0 +1,167 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- Contains ad group level performance segmented by network (Search, Display, YouTube). +-- Added Cohort Performance view on the Campaign and AgGroup Level +CREATE TEMP FUNCTION GetCohort(arr ARRAY, day INT64) +RETURNS FLOAT64 +AS ( + arr[SAFE_OFFSET(day)] +); +CREATE OR REPLACE TABLE {target_dataset}.network_split +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + ad_group_id, + SUM(conversions) AS conversions, + SUM(conversions_value) AS conversions_value, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.ad_group_conversion_split` + GROUP BY + 1, 2, 3 + ), + MappingTable AS + ( + SELECT + ad_group_id, + ANY_VALUE(ad_group_name) AS ad_group_name, + ANY_VALUE(ad_group_status) AS ad_group_status, + ANY_VALUE(campaign_id) AS campaign_id, + ANY_VALUE(campaign_name) AS campaign_name, + ANY_VALUE(campaign_status) AS campaign_status, + ANY_VALUE(account_id) AS account_id, + ANY_VALUE(account_name) AS account_name, + ANY_VALUE(currency) AS currency + FROM + `{bq_dataset}.account_campaign_ad_group_mapping` + GROUP BY + 1 + ), + FinalTablePrep AS + ( + SELECT + PARSE_DATE("%Y-%m-%d", ICP.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + IFNULL(G.geos, "All") AS geos, + IFNULL(G.languages, "All") AS languages, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + "" AS firebase_bidding_status, + M.ad_group_id, + M.ad_group_name, + M.ad_group_status, + ICP.network, + SUM(ICP.clicks) AS clicks, + SUM(ICP.impressions) AS impressions, + `{bq_dataset}.NormalizeMillis`(SUM(ICP.cost)) AS cost, + SUM(ICP.video_views) AS video_views, + SUM(ICP.interactions) AS interactions, + SUM(ICP.engagements) AS engagements, + SUM(ICP.view_through_conversions) AS view_through_conversions, + SUM(ICP.video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(ICP.video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(ICP.video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(ICP.video_quartile_p100_rate) AS video_quartile_p100_rate, + SUM(CS.conversions) AS conversions, + SUM(CS.installs) AS installs, + SUM(CS.inapps) AS inapps, + SUM(ICP.conversions_value) AS conversions_value + FROM + `{bq_dataset}.ad_group_performance_extended` AS ICP + LEFT JOIN + ConversionsTable AS CS + USING(date, ad_group_id, network) + LEFT JOIN + MappingTable AS M + ON ICP.ad_group_id = M.ad_group_id + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + ON M.campaign_id = ACS.campaign_id + LEFT JOIN + `{bq_dataset}.GeoLanguageView` AS G + ON M.campaign_id = G.campaign_id + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 + ) + + SELECT + day, + account_id, + account_name, + currency, + campaign_id, + campaign_name, + campaign_status, + campaign_sub_type, + geos, + IFNULL(languages, "All") AS languages, + app_id, + app_store, + bidding_strategy, + target_conversions, + firebase_bidding_status, + ad_group_id, + ad_group_name, + ad_group_status, + `{bq_dataset}.ConvertAdNetwork`(network) AS network, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + SUM(cost) AS cost, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate, + SUM(conversions) AS conversions, + SUM(installs) AS installs, + SUM(inapps) AS inapps, + SUM(conversions_value) AS conversions_value, + {% for day in cohort_days %} + SUM(GetCohort(CC.lag_data.installs, {{day}})) AS installs_{{day}}_day, + SUM(GetCohort(CC.lag_data.inapps, {{day}})) AS inapps_{{day}}_day, + SUM(GetCohort(CC.lag_data.conversions_value, {{day}})) AS conversions_value_{{day}}_day, + {% endfor %} + FROM + FinalTablePrep + LEFT JOIN + ( + SELECT + day_of_interaction AS day, + ad_group_id, + network, + lag_data + FROM + `{bq_dataset}.CampaignAdGroupCohorts` + ) AS CC + USING (day, ad_group_id, network) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 + ); \ No newline at end of file diff --git a/bq_queries/optional_tables/change_history_extended.sql b/bq_queries/optional_tables/change_history_extended.sql new file mode 100644 index 0000000..75004f1 --- /dev/null +++ b/bq_queries/optional_tables/change_history_extended.sql @@ -0,0 +1,653 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--TODO@dbenger: Adjust the script so that it resembles generic change_history script +CREATE TEMP FUNCTION GetCohort(arr ARRAY, day INT64) +RETURNS FLOAT64 AS ( + arr[SAFE_OFFSET(day)] +); +--TODO: When Conv. Lag Calculation is added, include it to this part +-- iOS Campaign Overall Performance with Cohorts +CREATE OR REPLACE TABLE {target_dataset}.ios_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT --TODO: replace ad_group_id with campaing_id + date, + campaign_id, + network, + SUM(conversions) AS conversions, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.ios_campaign_conversion_split` + GROUP BY + 1, 2, 3 + ), + iOSCampaignRaw AS + ( + SELECT + PARSE_DATE("%Y-%m-%d", IOP.date) AS day, + IOP.campaign_id, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + SUM(engagements) AS engagements, + SUM(interactions) AS interactions, + SUM(video_views) AS video_views, + SUM(cost) AS cost, + SUM(view_through_conversions) AS view_through_conversions, + SUM(conversions) AS conversions, + SUM(installs) AS installs, + SUM(inapps) AS inapps, + SUM(conversions_value) AS conversions_value, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate, + SUM(skan_installs) AS skan_installs + FROM + `{bq_dataset}.ios_campaign_overall_perfomance` AS IOP + LEFT JOIN + ConversionsTable AS CT + USING(date, campaign_id, network) + LEFT JOIN + ( + SELECT + date, + campaign_id, + skan_installs + FROM + `{bq_dataset}.ios_campaign_skan_perfomance` + ) AS SP + USING(date, campaign_id) + GROUP BY + 1, 2 + ), + iOSCampaignMapping AS + ( + SELECT + campaign_id, + ANY_VALUE(campaign_name) AS campaign_name, + ANY_VALUE(campaign_status) AS campaign_status, + ANY_VALUE(account_id) AS account_id, + ANY_VALUE(account_name) AS account_name, + ANY_VALUE(currency) AS currency + FROM + `{bq_dataset}.account_campaign_ad_group_mapping` + GROUP BY + 1 + ), + + FinalTablePrep AS + ( + SELECT + ICR.day, + ICR.campaign_id, + M.account_id, + M.account_name, + M.currency, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + IFNULL(G.geos, "All") AS geos, + IFNULL(G.languages, "All") AS languages, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + ACS.start_date AS start_date, + DATE_DIFF( + CURRENT_DATE(), + PARSE_DATE("%Y-%m-%d", ACS.start_date), + DAY) AS days_since_start_date, + ACS.n_of_target_conversions, + `{bq_dataset}.NormalizeMillis`(B.budget_amount) AS current_budget_amount, + `{bq_dataset}.NormalizeMillis`(B.target_cpa) AS current_target_cpa, + B.target_roas AS current_target_roas, + `{bq_dataset}.NormalizeMillis`(BidBudgetHistory.budget_amount) AS budget, + `{bq_dataset}.NormalizeMillis`(BidBudgetHistory.target_cpa) AS target_cpa, + BidBudgetHistory.target_roas AS target_roas, + -- If cost for a given day is higher than allocated budget than is_budget_limited = 1 + IF(ICR.cost > BidBudgetHistory.budget_amount, 1, 0) AS is_budget_limited, + -- If cost for a given day is 20% higher than allocated budget than is_budget_overshooting = 1 + IF(ICR.cost > BidBudgetHistory.budget_amount * 1.2, 1, 0) AS is_budget_overshooting, + -- If cost for a given day is 50% lower than allocated budget than is_budget_underspend = 1 + IF(ICR.cost < BidBudgetHistory.budget_amount * 0.5, 1, 0) AS is_budget_underspend, + -- If CPA for a given day is 10% higher than target_cpa than is_cpa_overshooting = 1 + IF(SAFE_DIVIDE(ICR.cost, ICR.conversions) > BidBudgetHistory.target_cpa * 1.1, 1, 0) AS is_cpa_overshooting, + CASE + WHEN BidBudgetHistory.target_cpa = LAG(BidBudgetHistory.target_cpa) + OVER (PARTITION BY ICR.campaign_id ORDER BY ICR.day ASC) + OR LAG(BidBudgetHistory.target_cpa) + OVER (PARTITION BY ICR.campaign_id ORDER BY ICR.day ASC) IS NULL + THEN 0 + ELSE 1 + END AS bid_changes, + CASE + WHEN BidBudgetHistory.budget_amount = LAG(BidBudgetHistory.budget_amount) + OVER (PARTITION BY ICR.campaign_id ORDER BY ICR.day ASC) + OR LAG(BidBudgetHistory.budget_amount) + OVER (PARTITION BY ICR.campaign_id ORDER BY ICR.day ASC) IS NULL + THEN 0 + ELSE 1 + END AS budget_changes, + ICR.clicks, + ICR.impressions, + ICR.engagements, + ICR.interactions, + ICR.video_views, + `{bq_dataset}.NormalizeMillis`(ICR.cost) AS cost, + ICR.conversions, + ICR.installs, + ICR.inapps, + ICR.conversions_value, + ICR.view_through_conversions, + ICR.video_quartile_p25_rate, + ICR.video_quartile_p50_rate, + ICR.video_quartile_p75_rate, + ICR.video_quartile_p100_rate, + ICR.skan_installs + FROM + iOSCampaignRaw AS ICR + LEFT JOIN + iOSCampaignMapping AS M + USING (campaign_id) + LEFT JOIN + {bq_dataset}.bids_budgets AS B + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.bid_budgets_*` AS BidBudgetHistory + USING (day, campaign_id) + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.GeoLanguageView` AS G + USING (campaign_id) + ), + + iOSCampaignPerformance AS + ( + SELECT + day, + account_id, + account_name, + campaign_id, + campaign_name, + campaign_status, + currency, + campaign_sub_type, + geos, + languages, + app_id, + app_store, + bidding_strategy, + "" AS firebase_bidding_status, + target_conversions, + start_date, + days_since_start_date, + n_of_target_conversions, + MIN(current_budget_amount) AS current_budget_amount, + MIN(current_target_cpa) AS current_target_cpa, + MIN(current_target_roas) AS current_target_roas, + MIN(budget) AS budget, + MIN(target_cpa) AS target_cpa, + MIN(target_roas) AS target_roas, + MIN(is_budget_limited) AS is_budget_limited, + MIN(is_budget_overshooting) AS is_budget_overshooting, + MIN(is_budget_underspend) AS is_budget_underspend, + MIN(is_cpa_overshooting) AS is_cpa_overshooting, + MIN(bid_changes) AS bid_changes, + MIN(budget_changes) AS budget_changes, + MIN(clicks) AS clicks, + MIN(impressions) AS impressions, + MIN(cost) AS cost, + MIN(installs) AS installs, + MIN(inapps) AS inapps, + MIN(video_views) AS video_views, + MIN(interactions) AS interactions, + MIN(engagements) AS engagements, + MIN(conversions_value) AS conversions_value, + MIN(view_through_conversions) AS view_through_conversions, + MIN(video_quartile_p25_rate) AS video_quartile_p25_rate, + MIN(video_quartile_p50_rate) AS video_quartile_p50_rate, + MIN(video_quartile_p75_rate) AS video_quartile_p75_rate, + MIN(video_quartile_p100_rate) AS video_quartile_p100_rate, + MIN(skan_installs) AS skan_installs, + CASE + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0 AND 0.01 THEN '<1%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.01 AND 0.1 THEN '1%-10%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.1 AND 0.25 THEN '10%-25%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.25 AND 0.5 THEN '25%-50%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.5 AND 0.75 THEN '50%-75%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.75 AND 0.9 THEN '75%-90%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 0.9 AND 1 THEN '90%-100%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1 AND 1.10 THEN '100%-110%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.10 AND 1.20 THEN '110%-120%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.20 AND 1.30 THEN '120%-130%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.30 AND 1.40 THEN '130%-140%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.40 AND 1.50 THEN '140%-150%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.50 AND 1.60 THEN '150%-160%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.60 AND 1.70 THEN '160%-170%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.70 AND 1.80 THEN '170%-180%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.80 AND 1.90 THEN '180%-190%' + WHEN SAFE_DIVIDE(MIN(cost), MIN(budget)) BETWEEN 1.90 AND 2 THEN '190%-200%' + ELSE '>200%' + END AS budget_util_tier, + CASE + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0 AND 0.01 THEN '<1%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.01 AND 0.1 THEN '1%-10%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.1 AND 0.25 THEN '10%-25%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.25 AND 0.5 THEN '25%-50%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.5 AND 0.75 THEN '50%-75%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.75 AND 0.9 THEN '75%-90%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 0.9 AND 1 THEN '90%-100%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1 AND 1.10 THEN '100%-110%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.10 AND 1.20 THEN '110%-120%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.20 AND 1.30 THEN '120%-130%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.30 AND 1.40 THEN '130%-140%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.40 AND 1.50 THEN '140%-150%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.50 AND 1.60 THEN '150%-160%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.60 AND 1.70 THEN '160%-170%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.70 AND 1.80 THEN '170%-180%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.80 AND 1.90 THEN '180%-190%' + WHEN bidding_strategy = "tCPA (AC Actions)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(cost), SUM(inapps)), AVG(target_cpa)) BETWEEN 1.90 AND 2 THEN '190%-200%' + ELSE '>200%' + END AS tcpa_bid_util_tier, + CASE + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0 AND 0.01 THEN '<1%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.01 AND 0.1 THEN '1%-10%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.1 AND 0.25 THEN '10%-25%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.25 AND 0.5 THEN '25%-50%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.5 AND 0.75 THEN '50%-75%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.75 AND 0.9 THEN '75%-90%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 0.9 AND 1 THEN '90%-100%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1 AND 1.10 THEN '100%-110%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.10 AND 1.20 THEN '110%-120%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.20 AND 1.30 THEN '120%-130%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.30 AND 1.40 THEN '130%-140%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.40 AND 1.50 THEN '140%-150%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.50 AND 1.60 THEN '150%-160%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.60 AND 1.70 THEN '160%-170%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.70 AND 1.80 THEN '170%-180%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.80 AND 1.90 THEN '180%-190%' + WHEN bidding_strategy = "tROAS (AC ROAS)" AND SAFE_DIVIDE(SAFE_DIVIDE(SUM(conversions_value), SUM(cost)), AVG(target_roas)) BETWEEN 1.90 AND 2 THEN '190%-200%' + ELSE '>200%' + END AS troas_bid_util_tier + FROM + FinalTablePrep + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 + ) + +SELECT + day, + account_id, + account_name, + campaign_id, + campaign_name, + campaign_status, + currency, + campaign_sub_type, + geos, + languages, + app_id, + app_store, + bidding_strategy, + target_conversions, + start_date, + days_since_start_date, + n_of_target_conversions, + CAST(budget_util_tier AS STRING) AS budget_util_tier , + CAST(troas_bid_util_tier AS STRING) AS troas_bid_util_tier, + CAST(tcpa_bid_util_tier AS STRING) AS tcpa_bid_util_tier, + SUM(current_budget_amount) AS current_budget_amount, + SUM(current_target_cpa) AS current_target_cpa, + SUM(current_target_roas) AS current_target_roas, + SUM(budget) AS budget, + SUM(target_cpa) AS target_cpa, + SUM(target_roas) AS target_roas, + SUM(is_budget_limited) AS is_budget_limited, + SUM(is_budget_overshooting) AS is_budget_overshooting, + SUM(is_budget_underspend) AS is_budget_underspend, + SUM(is_cpa_overshooting) AS is_cpa_overshooting, + SUM(bid_changes) AS bid_changes, + SUM(budget_changes) AS budget_changes, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + SUM(cost) AS cost, + SUM(installs) AS installs, + SUM(inapps) AS inapps, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(conversions_value) AS conversions_value, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate, + SUM(skan_installs) AS skan_installs, + {% for day in cohort_days %} + -- SUM(GetCohort(CC.lag_data.skan_postbacks, {{day}})) AS skan_postbacks_{{day}}_day, + SUM(GetCohort(CC.lag_data.installs, {{day}})) AS installs_{{day}}_day, + SUM(GetCohort(CC.lag_data.inapps, {{day}})) AS inapps_{{day}}_day, + SUM(GetCohort(CC.lag_data.conversions_value, {{day}})) AS conversions_value_{{day}}_day, + {% endfor %} +FROM + iOSCampaignPerformance AS ICP +LEFT JOIN +( + SELECT + day_of_interaction AS day, + campaign_id, + lag_data + FROM + `{bq_dataset}.CampaignAdGroupCohorts` +) AS CC + USING (day, campaign_id) +GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 +); + +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +CREATE TEMPORARY FUNCTION equalsArr(x ARRAY, y ARRAY) +RETURNS INT64 +LANGUAGE js AS r""" +var count = 0; +if(x.length >= y.length) {{ +for(var i=0; i BidBudgetHistory.budget_amount, 1, 0) AS is_budget_limited, + -- If cost for a given day is 20% higher than allocated budget than is_budget_overshooting = 1 + IF(CP.cost > BidBudgetHistory.budget_amount * 1.2, 1, 0) AS is_budget_overshooting, + -- If cost for a given day is 50% lower than allocated budget than is_budget_underspend = 1 + IF(CP.cost < BidBudgetHistory.budget_amount * 0.5, 1, 0) AS is_budget_underspend, + -- If CPA for a given day is 10% higher than target_cpa than is_cpa_overshooting = 1 + IF(SAFE_DIVIDE(CP.cost, CP.conversions) > BidBudgetHistory.target_cpa * 1.1, 1, 0) AS is_cpa_overshooting, + AssetChanges.headline_changes + AssetChanges.description_changes AS text_changes, + AssetChanges.image_changes AS image_changes, + AssetChanges.html5_changes AS html5_changes, + AssetChanges.video_changes AS video_changes, + 0 AS geo_changes, + 0 AS ad_group_added, + 0 AS ad_group_resumed, + 0 AS ad_group_paused, + 0 AS ad_group_deleted, + CASE + WHEN BidBudgetHistory.target_cpa = LAG(BidBudgetHistory.target_cpa) + OVER (PARTITION BY M.campaign_id ORDER BY CP.day ASC) + OR LAG(BidBudgetHistory.target_cpa) + OVER (PARTITION BY M.campaign_id ORDER BY CP.day ASC) IS NULL + THEN 0 + ELSE 1 + END AS bid_changes, + CASE + WHEN BidBudgetHistory.budget_amount = LAG(BidBudgetHistory.budget_amount) + OVER (PARTITION BY M.campaign_id ORDER BY CP.day ASC) + OR LAG(BidBudgetHistory.budget_amount) + OVER (PARTITION BY M.campaign_id ORDER BY CP.day ASC) IS NULL + THEN 0 + ELSE 1 + END AS budget_changes, + CP.clicks, + CP.impressions, + `{bq_dataset}.NormalizeMillis`(CP.cost) AS cost, + IF(ACS.bidding_strategy = "OPTIMIZE_INSTALLS_TARGET_INSTALL_COST", + CP.installs, CP.inapps) AS conversions, + IF(ACS.bidding_strategy = "OPTIMIZE_INSTALLS_TARGET_INSTALL_COST", + CP.installs_adjusted, CP.inapps_adjusted) AS conversions_adjusted, + CP.installs, + CP.installs_adjusted, + CP.inapps, + CP.inapps_adjusted, + CP.view_through_conversions, + CP.conversions_value + CP.skan_installs +FROM CampaignPerformance AS CP +LEFT JOIN CampaignMapping AS M + ON CP.campaign_id = M.campaign_id +LEFT JOIN `{bq_dataset}.bid_budget` AS B + ON CP.campaign_id = B.campaign_id +LEFT JOIN `{bq_dataset}.bid_budgets_*` AS BidBudgetHistory + ON M.campaign_id = BidBudgetHistory.campaign_id + AND CP.day = BidBudgetHistory.day +LEFT JOIN `{bq_dataset}.AppCampaignSettingsView` AS ACS + ON M.campaign_id = ACS.campaign_id +LEFT JOIN `{bq_dataset}.GeoLanguageView` AS G + ON M.campaign_id = G.campaign_id +LEFT JOIN AssetChanges + ON M.campaign_id = AssetChanges.campaign_id + AND CP.day = AssetChanges.day); diff --git a/bq_queries/optional_tables/conversion_lag_performance.sql b/bq_queries/optional_tables/conversion_lag_performance.sql new file mode 100644 index 0000000..75e225b --- /dev/null +++ b/bq_queries/optional_tables/conversion_lag_performance.sql @@ -0,0 +1,139 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- Contains Campaign & Ad Group level Covnersion conversion_lag performance segmented by network (Search, Display, YouTube). +-- Added Cohort Performance view on the Campaign and AgGroup Level +CREATE TEMP FUNCTION GetCohort(arr ARRAY, day INT64) +RETURNS FLOAT64 +AS ( + arr[SAFE_OFFSET(day)] +); +CREATE OR REPLACE TABLE {target_dataset}.conversion_lag_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + ad_group_id, + CASE + WHEN conversion_lag = 'LESS_THAN_ONE_DAY' THEN "< 1 Day" + WHEN conversion_lag = 'ONE_TO_TWO_DAYS' THEN "1-2 Days" + WHEN conversion_lag = 'TWO_TO_THREE_DAYS' THEN "2-3 Days" + WHEN conversion_lag = 'THREE_TO_FOUR_DAYS' THEN "3-4 Days" + WHEN conversion_lag = 'FOUR_TO_FIVE_DAYS' THEN "4-5 Days" + WHEN conversion_lag = 'FIVE_TO_SIX_DAYS'THEN "5-6 Days" + WHEN conversion_lag = 'SIX_TO_SEVEN_DAYS' THEN "6-7 Days" + WHEN conversion_lag = 'SEVEN_TO_EIGHT_DAYS' THEN "7-8 Days" + WHEN conversion_lag = 'EIGHT_TO_NINE_DAYS' THEN "8-9 Days" + WHEN conversion_lag = 'NINE_TO_TEN_DAYS' THEN "9-10 Days" + WHEN conversion_lag = 'TEN_TO_ELEVEN_DAYS' THEN "10-11 Days" + WHEN conversion_lag = 'ELEVEN_TO_TWELVE_DAYS' THEN "11-12 Days" + WHEN conversion_lag = 'TWELVE_TO_THIRTEEN_DAYS' THEN "12-13 Days" + WHEN conversion_lag = 'THIRTEEN_TO_FOURTEEN_DAYS' THEN "13-14 Days" + WHEN conversion_lag = 'FOURTEEN_TO_TWENTY_ONE_DAYS' THEN "14-21 Days" + WHEN conversion_lag = 'TWENTY_ONE_TO_THIRTY_DAYS' THEN "21-30 Days" + WHEN conversion_lag = 'THIRTY_TO_FORTY_FIVE_DAYS' THEN "30-45 Days" + ELSE 'Other' + END AS conversion_lag_range, + CASE + WHEN conversion_lag = 'LESS_THAN_ONE_DAY' THEN 1 + WHEN conversion_lag = 'ONE_TO_TWO_DAYS' THEN 2 + WHEN conversion_lag = 'TWO_TO_THREE_DAYS' THEN 3 + WHEN conversion_lag = 'THREE_TO_FOUR_DAYS' THEN 4 + WHEN conversion_lag = 'FOUR_TO_FIVE_DAYS' THEN 5 + WHEN conversion_lag = 'FIVE_TO_SIX_DAYS'THEN 6 + WHEN conversion_lag = 'SIX_TO_SEVEN_DAYS' THEN 7 + WHEN conversion_lag = 'SEVEN_TO_EIGHT_DAYS' THEN 8 + WHEN conversion_lag = 'EIGHT_TO_NINE_DAYS' THEN 9 + WHEN conversion_lag = 'NINE_TO_TEN_DAYS' THEN 10 + WHEN conversion_lag = 'TEN_TO_ELEVEN_DAYS' THEN 11 + WHEN conversion_lag = 'ELEVEN_TO_TWELVE_DAYS' THEN 12 + WHEN conversion_lag = 'TWELVE_TO_THIRTEEN_DAYS' THEN 13 + WHEN conversion_lag = 'THIRTEEN_TO_FOURTEEN_DAYS' THEN 14 + WHEN conversion_lag = 'FOURTEEN_TO_TWENTY_ONE_DAYS' THEN 21 + WHEN conversion_lag = 'TWENTY_ONE_TO_THIRTY_DAYS' THEN 30 + WHEN conversion_lag = 'THIRTY_TO_FORTY_FIVE_DAYS' THEN 45 + ELSE 'Other' + END AS conversion_lag_rank, + SUM(all_conversions) AS all_conversions, + SUM(all_conversions_value) AS all_conversions_value, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS all_installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS all_inapps + FROM + `{bq_dataset}.conversion_conversion_lag_performance` + GROUP BY + 1, 2, 3, 4 + ), + MappingTable AS + ( + SELECT + ad_group_id, + ANY_VALUE(ad_group_name) AS ad_group_name, + ANY_VALUE(ad_group_status) AS ad_group_status, + ANY_VALUE(campaign_id) AS campaign_id, + ANY_VALUE(campaign_name) AS campaign_name, + ANY_VALUE(campaign_status) AS campaign_status, + ANY_VALUE(account_id) AS account_id, + ANY_VALUE(account_name) AS account_name, + ANY_VALUE(currency) AS currency + FROM + `{bq_dataset}.account_campaign_ad_group_mapping` + GROUP BY + 1 + ), + FinalTablePrep AS + ( + SELECT + PARSE_DATE("%Y-%m-%d", CT.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + IFNULL(G.geos, "All") AS geos, + IFNULL(G.languages, "All") AS languages, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + "" AS firebase_bidding_status, + M.ad_group_id, + M.ad_group_name, + M.ad_group_status, + CT.network, + CT.conversion_lag_range, + CT.conversion_lag_rank, + SUM(CT.all_conversions) AS all_conversions, + SUM(CT.all_installs) AS all_installs, + SUM(CT.all_inapps) AS all_inapps, + SUM(CT.all_conversions_value) AS all_conversions_value + FROM + ConversionsTable AS CT + USING(date, ad_group_id, network) + LEFT JOIN + MappingTable AS M + ON ICP.ad_group_id = M.ad_group_id + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + ON M.campaign_id = ACS.campaign_id + LEFT JOIN + `{bq_dataset}.GeoLanguageView` AS G + ON M.campaign_id = G.campaign_id + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 + ) \ No newline at end of file diff --git a/bq_queries/optional_tables/demographics_performance.sql b/bq_queries/optional_tables/demographics_performance.sql new file mode 100644 index 0000000..9815d29 --- /dev/null +++ b/bq_queries/optional_tables/demographics_performance.sql @@ -0,0 +1,273 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- Final Table for Age Group Performance +CREATE OR REPLACE TABLE {target_dataset}.age_group_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + campaign_id, + age_range, + SUM(conversions) AS conversions, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.age_range_conversion_split` + GROUP BY + 1, 2, 3, 4 + ) + + SELECT + PARSE_DATE("%Y-%m-%d", ARP.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + ACS.start_date AS start_date, + ARP.network, + age_range, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + `{bq_dataset}.NormalizeMillis`(SUM(ARP.cost)) AS cost, + SUM(ConvSplit.installs) AS installs, + SUM(ConvSplit.inapps) AS inapps, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(conversions_value) AS conversions_value, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate + FROM + `{bq_dataset}.age_range_performance` AS ARP + LEFT JOIN + ConversionsTable AS ConvSplit + USING (campaign_id, network, date, age_range) + LEFT JOIN + `{bq_dataset}.account_campaign_ad_group_mapping` AS M + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + USING (campaign_id) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +); + +--Final Table for Gender Group Performance +CREATE OR REPLACE TABLE {target_dataset}.gender_group_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + campaign_id, + gender_group, + SUM(conversions) AS conversions, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.gender_group_conversion_split` + GROUP BY + 1, 2, 3, 4 + ) + + SELECT + PARSE_DATE("%Y-%m-%d", GGP.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + ACS.start_date AS start_date, + GGP.network, + gender_group, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + `{bq_dataset}.NormalizeMillis`(SUM(GGP.cost)) AS cost, + SUM(ConvSplit.installs) AS installs, + SUM(ConvSplit.inapps) AS inapps, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(conversions_value) AS conversions_value, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate + FROM + `{bq_dataset}.gender_group_performance` AS GGP + LEFT JOIN + ConversionsTable AS ConvSplit + USING (campaign_id, network, date, gender_group) + LEFT JOIN + `{bq_dataset}.account_campaign_ad_group_mapping` AS M + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + USING (campaign_id) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +); + +--Final Table for Income Group Performance +CREATE OR REPLACE TABLE {target_dataset}.income_group_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + campaign_id, + income_range, + SUM(conversions) AS conversions, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.income_range_conversion_split` + GROUP BY + 1, 2, 3, 4 + ) + + SELECT + PARSE_DATE("%Y-%m-%d", IRP.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + ACS.start_date AS start_date, + IRP.network, + income_range, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + `{bq_dataset}.NormalizeMillis`(SUM(IRP.cost)) AS cost, + SUM(ConvSplit.installs) AS installs, + SUM(ConvSplit.inapps) AS inapps, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(conversions_value) AS conversions_value, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate + FROM + `{bq_dataset}.income_range_performance` AS IRP + LEFT JOIN + ConversionsTable AS ConvSplit + USING (campaign_id, network, date, income_range) + LEFT JOIN + `{bq_dataset}.account_campaign_ad_group_mapping` AS M + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + USING (campaign_id) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +); + +--Final Table for Income Group Performance +CREATE OR REPLACE TABLE {target_dataset}.parent_group_performance +AS ( + WITH + ConversionsTable AS + ( + SELECT + date, + network, + campaign_id, + parent_group, + SUM(conversions) AS conversions, + SUM(IF(conversion_category = "DOWNLOAD", conversions, 0)) AS installs, + SUM(IF(conversion_category != "DOWNLOAD", conversions, 0)) AS inapps + FROM + `{bq_dataset}.parent_group_conversion_split` + GROUP BY + 1, 2, 3, 4 + ) + + SELECT + PARSE_DATE("%Y-%m-%d", PGP.date) AS day, + M.account_id, + M.account_name, + M.currency, + M.campaign_id, + M.campaign_name, + M.campaign_status, + ACS.campaign_sub_type, + ACS.app_id, + ACS.app_store, + ACS.bidding_strategy, + ACS.target_conversions, + ACS.start_date AS start_date, + PGP.network, + parent_group, + SUM(clicks) AS clicks, + SUM(impressions) AS impressions, + `{bq_dataset}.NormalizeMillis`(SUM(PGP.cost)) AS cost, + SUM(ConvSplit.installs) AS installs, + SUM(ConvSplit.inapps) AS inapps, + SUM(video_views) AS video_views, + SUM(interactions) AS interactions, + SUM(engagements) AS engagements, + SUM(conversions_value) AS conversions_value, + SUM(view_through_conversions) AS view_through_conversions, + SUM(video_quartile_p25_rate) AS video_quartile_p25_rate, + SUM(video_quartile_p50_rate) AS video_quartile_p50_rate, + SUM(video_quartile_p75_rate) AS video_quartile_p75_rate, + SUM(video_quartile_p100_rate) AS video_quartile_p100_rate + FROM + `{bq_dataset}.parent_group_performance` AS PGP + LEFT JOIN + ConversionsTable AS ConvSplit + USING (campaign_id, network, date, parent_group) + LEFT JOIN + `{bq_dataset}.account_campaign_ad_group_mapping` AS M + USING (campaign_id) + LEFT JOIN + `{bq_dataset}.AppCampaignSettingsView` AS ACS + USING (campaign_id) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +); diff --git a/bq_queries/optional_tables/skan_geo_performance.sql b/bq_queries/optional_tables/skan_geo_performance.sql new file mode 100644 index 0000000..bfa7d6f --- /dev/null +++ b/bq_queries/optional_tables/skan_geo_performance.sql @@ -0,0 +1,101 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- SKAN Only Geo Performance +CREATE OR REPLACE TABLE {target_dataset}.skan_geo_performance +AS ( + WITH + SharePrep AS + ( + SELECT + campaign_id, + country_code, + SAFE_DIVIDE(cost,SUM(cost) OVER (campaigns)) AS geo_cost_share, + SAFE_DIVIDE(impressions,SUM(impressions) OVER (campaigns)) AS geo_impressions_share, + SAFE_DIVIDE(clicks,SUM(clicks) OVER (campaigns)) AS geo_clicks_share, + SAFE_DIVIDE(interactions,SUM(interactions) OVER (campaigns)) AS geo_interactions_share, + SAFE_DIVIDE(conversions,SUM(conversions) OVER (campaigns)) AS geo_conversions_share, + SAFE_DIVIDE(installs,SUM(installs) OVER (campaigns)) AS geo_installs_share, + SAFE_DIVIDE(inapps,SUM(inapps) OVER (campaigns)) AS geo_inapps_share, + SAFE_DIVIDE(conversions_value,SUM(conversions_value) OVER (campaigns)) AS geo_conversion_value_share + FROM + `{target_dataset}.geo_performance` + WINDOW campaigns AS (PARTITION BY campaign_id) + ), + + ShareFinal AS + ( + SELECT + campaign_id, + country_code, + MIN(geo_cost_share) AS geo_cost_share, + MIN(geo_impressions_share) AS geo_impressions_share, + MIN(geo_clicks_share) AS geo_clicks_share, + MIN(geo_interactions_share) AS geo_interactions_share, + MIN(geo_conversions_share) AS geo_conversions_share, + MIN(geo_installs_share) AS geo_installs_share, + MIN(geo_inapps_share) AS geo_inapps_share, + MIN(geo_conversion_value_share) AS geo_conversion_value_share, + AVG(average_geo_share) AS average_geo_share + FROM + SharePrep, + UNNEST ([geo_cost_share,geo_impressions_share, geo_clicks_share, geo_interactions_share, geo_conversions_share, geo_installs_share, geo_inapps_share, geo_conversion_value_share]) AS average_geo_share + GROUP BY + 1,2 + ) + + SELECT + day, + account_id, + account_name, + currency, + campaign_id, + campaign_name, + campaign_status, + campaign_sub_type, + app_id, + bidding_strategy, + target_conversions, + start_date, + country_code, + SUM(skan_installs) AS skan_installs, + MIN(geo_cost_share) AS geo_cost_share, + MIN(geo_impressions_share) AS geo_impressions_share, + MIN(geo_clicks_share) AS geo_clicks_share, + MIN(geo_interactions_share) AS geo_interactions_share, + MIN(geo_conversions_share) AS geo_conversions_share, + MIN(geo_installs_share) AS geo_installs_share, + MIN(geo_inapps_share) AS geo_inapps_share, + MIN(geo_conversion_value_share) AS geo_conversion_value_share, + AVG(average_geo_share) AS average_geo_share + FROM + `{target_dataset}.geo_performance` + LEFT JOIN + ( + SELECT + PARSE_DATE("%Y-%m-%d", date) AS day, + campaign_id, + SUM(skan_installs) AS skan_installs + FROM + `{bq_dataset}.ios_campaign_skan_performance` + GROUP BY + 1, 2 + ) + USING (day, campaign_id) + LEFT JOIN + ShareFinal + USING(campaign_id, country_code) + GROUP BY + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 + ); \ No newline at end of file diff --git a/bq_queries/optional_tables/snapshots/campaign_conversion_lags.sql b/bq_queries/optional_tables/snapshots/campaign_conversion_lags.sql new file mode 100644 index 0000000..8860f9b --- /dev/null +++ b/bq_queries/optional_tables/snapshots/campaign_conversion_lags.sql @@ -0,0 +1,38 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- All App Campaigns | Contains conversions and their values on a given day with automatically calculated lag number +CREATE OR REPLACE TABLE {bq_dataset}.campaign_conversion_lags_{date_iso} +AS ( + SELECT + PARSE_DATE("%Y-%m-%d", AGP.date) AS day_of_interaction, + DATE_DIFF( + CURRENT_DATE(), + PARSE_DATE("%Y-%m-%d", AGP.date), + DAY) AS lag, + campaign_id, + ad_group_id, + network, + SUM(IF(CS.conversion_category = "DOWNLOAD", CS.conversions, 0)) AS installs, + SUM(IF(CS.conversion_category != "DOWNLOAD", CS.conversions, 0)) AS inapps, + SUM(AGP.view_through_conversions) AS view_through_conversions, + SUM(AGP.conversions_value) AS conversions_value + FROM + {bq_dataset}.ad_group_performance AS AGP + LEFT JOIN + {bq_dataset}.ad_group_conversion_split AS CS + USING(date, ad_group_id, campaign_id, network) + GROUP BY + 1, 2, 3, 4, 5 + ); \ No newline at end of file diff --git a/bq_queries/optional_tables/views_and_functions/views_extended.sql b/bq_queries/optional_tables/views_and_functions/views_extended.sql new file mode 100644 index 0000000..c45b8b3 --- /dev/null +++ b/bq_queries/optional_tables/views_and_functions/views_extended.sql @@ -0,0 +1,45 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +-- Overall App Campaigns | Aggregated Daily Campaign & AdGroup Conversion Lag Snapshots +CREATE OR REPLACE VIEW `{bq_dataset}.CampaignAdGroupCohorts` AS ( +WITH + RawCampaignAdGroupLags AS + ( + SELECT + * + FROM + `{bq_dataset}.campaign_conversion_lags_*` + ) + + SELECT + day_of_interaction, + campaign_id, + ad_group_id, + network, + STRUCT( + ARRAY_AGG(lag ORDER BY lag) AS lags, + ARRAY_AGG(installs ORDER BY lag) AS installs, + ARRAY_AGG(inapps ORDER BY lag) AS inapps, + ARRAY_AGG(conversions_value ORDER BY lag) AS conversions_value, + ARRAY_AGG(view_through_conversions ORDER BY lag) AS view_through_conversions + ) AS lag_data + FROM + RawCampaignAdGroupLags + WHERE + day_of_interaction IS NOT NULL + AND lag <= 90 + GROUP BY + 1, 2, 3, 4 +); \ No newline at end of file diff --git a/google_ads_queries/optional_tables/account_conversion_action_settings.sql b/google_ads_queries/optional_tables/account_conversion_action_settings.sql new file mode 100644 index 0000000..5ce2bf2 --- /dev/null +++ b/google_ads_queries/optional_tables/account_conversion_action_settings.sql @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + customer.id AS customer_id, + conversion_action.id AS conversion_id, + conversion_action.third_party_app_analytics_settings.event_name AS third_party_app_analytics_event_name, + conversion_action.third_party_app_analytics_settings.provider_name AS third_party_app_analytics_provider_name, + conversion_action.firebase_settings.event_name AS firebase_event_name, + conversion_action.firebase_settings.property_name AS firebase_property_name, + conversion_action.status AS conversion_event_status, + conversion_action.category AS conversion_event_category, + conversion_action.type AS conversion_event_type, + conversion_action.counting_type AS conversion_event_counting_type, + conversion_action.include_in_conversions_metric AS include_event_in_conversions_metric, + conversion_action.name AS conversion_event_name, + conversion_action.view_through_lookback_window_days AS conversion_event_view_through_lookback_window, + conversion_action.click_through_lookback_window_days AS conversion_event_click_through_lookback_window, + metrics.all_conversions, + metrics.all_conversions_value +FROM + conversion_action +WHERE + segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file diff --git a/google_ads_queries/optional_tables/ad_group_conversion_lag.sql b/google_ads_queries/optional_tables/ad_group_conversion_lag.sql new file mode 100644 index 0000000..cdca740 --- /dev/null +++ b/google_ads_queries/optional_tables/ad_group_conversion_lag.sql @@ -0,0 +1,30 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + ad_group.id AS ad_group_id, + segments.ad_network_type AS network, + segments.conversion_action_name AS conversion_name, + segments.conversion_action_category AS conversion_category, + segments.conversion_action AS conversion_id, + segments.conversion_lag_bucket AS conversion_lag, + metrics.all_conversions AS all_conversions, + metrics.all_conversions_value AS all_conversions_value +FROM + ad_group +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file diff --git a/google_ads_queries/optional_tables/ad_group_performance_extended.sql b/google_ads_queries/optional_tables/ad_group_performance_extended.sql new file mode 100644 index 0000000..3fed20d --- /dev/null +++ b/google_ads_queries/optional_tables/ad_group_performance_extended.sql @@ -0,0 +1,34 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + metrics.clicks AS clicks, + metrics.impressions AS impressions, + metrics.cost_micros AS cost, + metrics.engagements AS engagements, + metrics.view_through_conversions AS view_through_conversions, + metrics.video_views AS video_views, + metrics.video_quartile_p25_rate AS video_quartile_p25_rate, + metrics.video_quartile_p50_rate AS video_quartile_p50_rate, + metrics.video_quartile_p75_rate AS video_quartile_p75_rate, + metrics.video_quartile_p100_rate AS video_quartile_p100_rate, + metrics.conversions_value AS conversions_value +FROM ad_group +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" diff --git a/google_ads_queries/optional_tables/age_range_conversion_split.sql b/google_ads_queries/optional_tables/age_range_conversion_split.sql new file mode 100644 index 0000000..7ee682e --- /dev/null +++ b/google_ads_queries/optional_tables/age_range_conversion_split.sql @@ -0,0 +1,27 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + age_range_view.resource_name AS age_range, + segments.conversion_action_category AS conversion_category, + metrics.conversions AS conversions +FROM + age_range_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file diff --git a/google_ads_queries/optional_tables/age_range_performance.sql b/google_ads_queries/optional_tables/age_range_performance.sql new file mode 100644 index 0000000..1b7fa07 --- /dev/null +++ b/google_ads_queries/optional_tables/age_range_performance.sql @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + age_range_view.resource_name AS age_range, + metrics.clicks AS clicks, + metrics.impressions AS impressions, + metrics.engagements AS engagements, + metrics.interactions AS interactions, + metrics.video_views AS video_views, + metrics.video_quartile_p25_rate AS video_quartile_p25_rate, + metrics.video_quartile_p50_rate AS video_quartile_p50_rate, + metrics.video_quartile_p75_rate AS video_quartile_p75_rate, + metrics.video_quartile_p100_rate AS video_quartile_p100_rate, + metrics.view_through_conversions AS view_through_conversions, + metrics.cost_micros AS cost, + metrics.conversions_value AS conversions_value +FROM + age_range_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file diff --git a/google_ads_queries/optional_tables/gender_group_conversion_split.sql b/google_ads_queries/optional_tables/gender_group_conversion_split.sql new file mode 100644 index 0000000..9b3de21 --- /dev/null +++ b/google_ads_queries/optional_tables/gender_group_conversion_split.sql @@ -0,0 +1,27 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + gender_view.resource_name AS gender_group, + segments.conversion_action_category AS conversion_category, + metrics.conversions AS conversions +FROM + gender_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" diff --git a/google_ads_queries/optional_tables/gender_group_performance.sql b/google_ads_queries/optional_tables/gender_group_performance.sql new file mode 100644 index 0000000..56e3712 --- /dev/null +++ b/google_ads_queries/optional_tables/gender_group_performance.sql @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + gender_view.resource_name AS gender_group, + metrics.clicks AS clicks, + metrics.impressions AS impressions, + metrics.engagements AS engagements, + metrics.interactions AS interactions, + metrics.video_views AS video_views, + metrics.video_quartile_p25_rate AS video_quartile_p25_rate, + metrics.video_quartile_p50_rate AS video_quartile_p50_rate, + metrics.video_quartile_p75_rate AS video_quartile_p75_rate, + metrics.video_quartile_p100_rate AS video_quartile_p100_rate, + metrics.view_through_conversions AS view_through_conversions, + metrics.cost_micros AS cost, + metrics.conversions_value AS conversions_value +FROM + gender_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" diff --git a/google_ads_queries/optional_tables/income_range_conversion_split.sql b/google_ads_queries/optional_tables/income_range_conversion_split.sql new file mode 100644 index 0000000..cb96414 --- /dev/null +++ b/google_ads_queries/optional_tables/income_range_conversion_split.sql @@ -0,0 +1,27 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + income_range_view.resource_name AS income_range, + segments.conversion_action_category AS conversion_category, + metrics.conversions AS conversions +FROM + income_range_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file diff --git a/google_ads_queries/optional_tables/income_range_performance.sql b/google_ads_queries/optional_tables/income_range_performance.sql new file mode 100644 index 0000000..eaab399 --- /dev/null +++ b/google_ads_queries/optional_tables/income_range_performance.sql @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + income_range_view.resource_name AS income_range, + metrics.clicks AS clicks, + metrics.impressions AS impressions, + metrics.engagements AS engagements, + metrics.interactions AS interactions, + metrics.video_views AS video_views, + metrics.video_quartile_p25_rate AS video_quartile_p25_rate, + metrics.video_quartile_p50_rate AS video_quartile_p50_rate, + metrics.video_quartile_p75_rate AS video_quartile_p75_rate, + metrics.video_quartile_p100_rate AS video_quartile_p100_rate, + metrics.view_through_conversions AS view_through_conversions, + metrics.cost_micros AS cost, + metrics.conversions_value AS conversions_value +FROM + income_range_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" diff --git a/google_ads_queries/optional_tables/parent_group_conversion_split.sql b/google_ads_queries/optional_tables/parent_group_conversion_split.sql new file mode 100644 index 0000000..59b0c1f --- /dev/null +++ b/google_ads_queries/optional_tables/parent_group_conversion_split.sql @@ -0,0 +1,28 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + parental_status_view.resource_name AS parent_group, + segments.conversion_action_category AS conversion_category, + metrics.conversions AS conversions, + metrics.conversions_value AS conversions_value +FROM + parental_status_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" diff --git a/google_ads_queries/optional_tables/parent_group_performance.sql b/google_ads_queries/optional_tables/parent_group_performance.sql new file mode 100644 index 0000000..37b3fe4 --- /dev/null +++ b/google_ads_queries/optional_tables/parent_group_performance.sql @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SELECT + segments.date AS date, + segments.ad_network_type AS network, + ad_group.id AS ad_group_id, + parental_status_view.resource_name AS parent_group, + metrics.clicks AS clicks, + metrics.impressions AS impressions, + metrics.engagements AS engagements, + metrics.interactions AS interactions, + metrics.video_views AS video_views, + metrics.video_quartile_p25_rate AS video_quartile_p25_rate, + metrics.video_quartile_p50_rate AS video_quartile_p50_rate, + metrics.video_quartile_p75_rate AS video_quartile_p75_rate, + metrics.video_quartile_p100_rate AS video_quartile_p100_rate, + metrics.view_through_conversions AS view_through_conversions, + metrics.cost_micros AS cost, + metrics.conversions_value AS conversions_value +FROM + parental_status_view +WHERE + campaign.advertising_channel_type = "MULTI_CHANNEL" + AND segments.date >= "{start_date}" + AND segments.date <= "{end_date}" \ No newline at end of file