├── config ├── task_customized_empty.json ├── task_customized_example.json ├── task_trdpty.json ├── workflow_nonapplite.json ├── workflow_app.json ├── workflow_app_nonapplite.json ├── workflow_nonapp.json ├── config_api.json ├── workflow_app_hourly.json └── workflow_app_nonapp.json ├── tool └── sheet_installer │ ├── images_for_readme │ ├── 3.3.png │ ├── 3.4.png │ ├── 3.5.png │ ├── 3.6.png │ ├── 3.2.3.png │ ├── step3.1.png │ ├── 3.2.2.1.1.png │ ├── 3.2.2.1.2.png │ └── step3.2.1.png │ ├── solutions_config.json │ ├── package.json │ └── src │ └── oec │ ├── sql │ ├── adh_retail_prep.sql │ ├── workflow_active_account.sql │ ├── base_snd_account_label.sql │ ├── make_email.sql │ ├── adh_bi_load_data.sql │ ├── app_trd_ad_group_report.sql │ ├── app_trd_campaign_conv_report.sql │ ├── adh_retail_join_lego_init.sql │ ├── nonapp_snd_campaign_ads_approval.sql │ ├── nonapp_trd_geo.sql │ ├── nonapp_trd_time.sql │ ├── nonapp_trd_ads_approval.sql │ ├── nonapp_trd_gender.sql │ ├── nonapp_trd_age.sql │ ├── app_trd_account.sql │ ├── nonapp_trd_feed_item_perf.sql │ ├── nonapp_trd_dsa.sql │ ├── nonapp_trd_placement.sql │ ├── nonapp_trd_search_term.sql │ ├── nonapp_trd_sitelink.sql │ ├── nonapp_snd_campaign_pacing.sql │ ├── nonapp_trd_search_keywords.sql │ ├── adh_app_prep.sql │ ├── nonapp_trd_audience.sql │ ├── adh_retail_join_lego_final.sql │ ├── adh_bi_calc_affinity.sql │ ├── adh_bi_calc_demo.sql │ ├── nonapp_trd_pmax_conversion.sql │ ├── adh_bi_join_lego_perf.sql │ ├── nonapp_trd_user_interest.sql │ ├── nonapp_trd_video.sql │ ├── app_trd_placement_report.sql │ ├── nonapp_trd_ads_perf.sql │ ├── app_trd_recommendations.sql │ ├── adh_pure_join_lego_perf.sql │ ├── app_trd_geo_perf_report.sql │ ├── app_trd_geo_conv_report.sql │ ├── adh_bi_calc_video_asset.sql │ ├── adh_branding_reach_frequency.sql │ ├── adh_pure_calc_asset_affinity.sql │ ├── adh_pure_calc_asset_demo.sql │ ├── nonapp_trd_account.sql │ ├── nonapp_trd_pmax.sql │ ├── base_snd_geo_perf_report.sql │ ├── app_snd_campaign_conv_report.sql │ ├── app_snd_ads_approval_all.sql │ └── adh_branding_conversion_uplift_MH.sql │ └── apps_script │ └── fx_rate_sheet.js ├── .gitignore ├── RELEASE_NOTES.md ├── .gcloudignore ├── sql ├── adh_retail_prep.sql ├── workflow_active_account.sql ├── base_snd_account_label.sql ├── make_email.sql ├── adh_bi_load_data.sql ├── app_trd_ad_group_report.sql ├── app_trd_campaign_conv_report.sql ├── adh_retail_join_lego_init.sql ├── nonapp_snd_campaign_ads_approval.sql ├── nonapp_trd_geo.sql ├── nonapp_trd_time.sql ├── nonapp_trd_ads_approval.sql ├── nonapp_trd_gender.sql ├── nonapp_trd_age.sql ├── app_trd_account.sql ├── nonapp_trd_feed_item_perf.sql ├── nonapp_trd_dsa.sql ├── nonapp_trd_placement.sql ├── nonapp_trd_search_term.sql ├── nonapp_trd_sitelink.sql ├── nonapp_snd_campaign_pacing.sql ├── nonapp_trd_search_keywords.sql ├── adh_app_prep.sql ├── nonapp_trd_audience.sql ├── adh_retail_join_lego_final.sql ├── adh_bi_calc_affinity.sql ├── adh_bi_calc_demo.sql ├── nonapp_trd_pmax_conversion.sql ├── adh_bi_join_lego_perf.sql ├── nonapp_trd_user_interest.sql ├── nonapp_trd_video.sql ├── app_trd_placement_report.sql ├── nonapp_trd_ads_perf.sql ├── app_trd_recommendations.sql ├── adh_pure_join_lego_perf.sql ├── app_trd_geo_perf_report.sql ├── app_trd_geo_conv_report.sql ├── adh_bi_calc_video_asset.sql ├── adh_branding_reach_frequency.sql ├── adh_pure_calc_asset_affinity.sql ├── adh_pure_calc_asset_demo.sql ├── nonapp_trd_account.sql ├── nonapp_trd_pmax.sql ├── base_snd_geo_perf_report.sql ├── app_snd_campaign_conv_report.sql ├── app_snd_ads_approval_all.sql └── adh_branding_conversion_uplift_MH.sql ├── package.json ├── index.js └── CONTRIBUTING.md /config/task_customized_empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "trigger_customized_task": { 3 | "type": "knot" 4 | } 5 | } -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.3.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.4.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.5.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.6.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.2.3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.2.3.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/step3.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/step3.1.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.2.2.1.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.2.2.1.1.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/3.2.2.1.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/3.2.2.1.2.png -------------------------------------------------------------------------------- /tool/sheet_installer/images_for_readme/step3.2.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ads-bi-suite/HEAD/tool/sheet_installer/images_for_readme/step3.2.1.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | *.iml 3 | node_modules/ 4 | .* 5 | libs/ 6 | config.json 7 | *.key.json 8 | *.token.json 9 | deploy_with_no_interaction/test_deploy.sh 10 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | # Release Notes 2 | 3 | ## 16.0.1 (2024-05-15) 4 | 5 | ### New Features 6 | 7 | - 2024, May - Upgrade Google Ads API to v16. 8 | - 2023, Dec - Upgrade Google Ads API to v14. 9 | - 2023, June - Upgrade Google Ads API to v13. 10 | - 2023, March - Upgrade Google Ads API to v12. 11 | -------------------------------------------------------------------------------- /tool/sheet_installer/solutions_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "oec": { 3 | "source": "./src/oec", 4 | "env": { 5 | "prod": { 6 | "scriptId": "13Nnji-Fdx61PhZsFcu_RCfIdoi6JwReckr5FVb0-yMIngdzzfdhRFrBF", 7 | "parentId": "1sQ1cPGZau5iKjugtIWsoIIOeGdI8BT1FFShxw05kntI" 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /tool/sheet_installer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oec", 3 | "version": "16.0.1", 4 | "description": "Google Sheets based installer for OEC", 5 | "author": "Google Inc.", 6 | "license": "Apache-2.0", 7 | "devDependencies": { 8 | "@google/clasp": "^2.4.2" 9 | }, 10 | "dependencies": { 11 | "@google-cloud/sheets-based-installer": "^1.7.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /config/task_customized_example.json: -------------------------------------------------------------------------------- 1 | { 2 | "trigger_customized_task": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": ["customized_query_task1", "customized_query_task2"] 6 | } 7 | }, 8 | "customized_query_task1": { 9 | "taskId": "query_general", 10 | "appendedParameters": { 11 | "queryName": "customized_query_1", 12 | "tableId": "customized_query_1" 13 | } 14 | }, 15 | "customized_query_task2": { 16 | "taskId": "query_general", 17 | "appendedParameters": { 18 | "queryName": "customized_query_2", 19 | "tableId": "customized_query_2" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gcloudignore: -------------------------------------------------------------------------------- 1 | # This file specifies files that are *not* uploaded to Google Cloud Platform 2 | # using gcloud. It follows the same syntax as .gitignore, with the addition of 3 | # "#!include" directives (which insert the entries of the given .gitignore-style 4 | # file at that point). 5 | # 6 | # For more information, run: 7 | # $ gcloud topic gcloudignore 8 | # 9 | .gcloudignore 10 | # If you would like to upload your .git directory, .gitignore file or files 11 | # from your .gitignore file, remove the corresponding line 12 | # below: 13 | .git 14 | .gitignore 15 | *.iml 16 | sql 17 | config 18 | deploy.sh 19 | terraform 20 | tool 21 | tests 22 | package-lock.json 23 | node_modules 24 | oauth_health_checker 25 | deploy_with_no_interaction -------------------------------------------------------------------------------- /sql/adh_retail_prep.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT Ad_group_id, User_interest, Status 16 | FROM `${legoDatasetId}.nonapp_trd_user_interest` 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /config/task_trdpty.json: -------------------------------------------------------------------------------- 1 | { 2 | "trdpty_load_reports": { 3 | "type": "knot", 4 | "next": [ 5 | { 6 | "taskId": "trdpty_sql_template", 7 | "appendedParameters": { 8 | "destinationTable": "trdpty_scoreboard", 9 | "sqlSyntax": "SELECT * FROM ${datasetId}.trdpty_scoreboard_input" 10 | } 11 | } 12 | ] 13 | }, 14 | "trdpty_sql_template": { 15 | "type": "query", 16 | "source": { 17 | "sql": "${sqlSyntax}", 18 | "external": true 19 | }, 20 | "destination": { 21 | "table": { 22 | "projectId": "${projectId}", 23 | "datasetId": "${datasetId}", 24 | "tableId": "${destinationTable}$${partitionDay}" 25 | }, 26 | "writeDisposition": "WRITE_TRUNCATE" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_retail_prep.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT Ad_group_id, User_interest, Status 16 | FROM `${legoDatasetId}.nonapp_trd_user_interest` 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apps-ads-reporting", 3 | "version": "16.0.1", 4 | "author": "lushu@google.com, chjerry@google.com, liulena@google.com, ritawang@google.com, mikawang@google.com", 5 | "files": [ 6 | "src/" 7 | ], 8 | "main": "index.js", 9 | "dependencies": { 10 | "@google-cloud/data-tasks-coordinator": "2.1.1", 11 | "@google-cloud/gmp-googleads-connector": "4.4.2" 12 | }, 13 | "scripts": { 14 | "test": "node node_modules/jasmine/bin/jasmine" 15 | }, 16 | "cloud-repo-tools": { 17 | "requiresKeyFile": true, 18 | "requiresProjectId": true 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "https://professional-services.googlesource.com/solutions/ads-bi-suite" 23 | }, 24 | "keywords": [], 25 | "license": "Apache-2.0", 26 | "description": "" 27 | } 28 | -------------------------------------------------------------------------------- /sql/workflow_active_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | customer.id AS customerId, 17 | _TABLE_SUFFIX AS loginCustomerId 18 | FROM `${datasetId}.report_base_account_performance_*` 19 | WHERE 20 | metrics.cost_micros > 0 21 | AND DATE(_PARTITIONTIME) = PARSE_DATE('%Y%m%d', '${partitionDay}') 22 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/workflow_active_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | customer.id AS customerId, 17 | _TABLE_SUFFIX AS loginCustomerId 18 | FROM `${datasetId}.report_base_account_performance_*` 19 | WHERE 20 | metrics.cost_micros > 0 21 | AND DATE(_PARTITIONTIME) = PARSE_DATE('%Y%m%d', '${partitionDay}') 22 | -------------------------------------------------------------------------------- /sql/base_snd_account_label.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT a.customer.id, b.label.name 16 | FROM `${datasetId}.report_base_customer_label` a 17 | LEFT JOIN `${datasetId}.report_base_labels` b 18 | ON a.customer_label.label = b.label.resource_name 19 | WHERE 20 | DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 21 | AND DATE(b._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/make_email.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | Email AS ( 17 | SELECT DISTINCT `id`, email 18 | FROM ${datasetId}.trdpty_agency_email 19 | WHERE DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 20 | ) 21 | SELECT OriginalTable.*, Email.email AS email 22 | FROM ${datasetId}.${queryName}_with_label OriginalTable 23 | LEFT JOIN Email 24 | ON CAST(OriginalTable.customer_id AS STRING) = Email.`id` -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/base_snd_account_label.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT a.customer.id, b.label.name 16 | FROM `${datasetId}.report_base_customer_label` a 17 | LEFT JOIN `${datasetId}.report_base_labels` b 18 | ON a.customer_label.label = b.label.resource_name 19 | WHERE 20 | DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 21 | AND DATE(b._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/make_email.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | Email AS ( 17 | SELECT DISTINCT `id`, email 18 | FROM ${datasetId}.trdpty_agency_email 19 | WHERE DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 20 | ) 21 | SELECT OriginalTable.*, Email.email AS email 22 | FROM ${datasetId}.${queryName}_with_label OriginalTable 23 | LEFT JOIN Email 24 | ON CAST(OriginalTable.customer_id AS STRING) = Email.`id` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | /** 15 | * @fileoverview Tentacles deployment file. 16 | */ 17 | 'use strict'; 18 | const {cloudfunctions: {convertEnvPathToAbsolute}} = require( 19 | '@google-cloud/nodejs-common'); 20 | 21 | convertEnvPathToAbsolute('OAUTH2_TOKEN_JSON', __dirname); 22 | convertEnvPathToAbsolute('API_SERVICE_ACCOUNT', __dirname); 23 | 24 | Object.assign(module.exports, 25 | require('@google-cloud/gmp-googleads-connector'), 26 | require('@google-cloud/data-tasks-coordinator')); 27 | -------------------------------------------------------------------------------- /sql/adh_bi_load_data.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE bi AS ( 16 | SELECT 17 | UPPER(TO_HEX(MD5(UPPER(device_id)))) AS device_id, 18 | install_date, 19 | app_id, 20 | platform, 21 | country, 22 | CASE 23 | WHEN number_of_installs > 1 THEN 'reinstall user' 24 | WHEN number_of_installs = 1 THEN 'new user' 25 | END AS user_type, 26 | day2_retention, 27 | day7_retention, 28 | day30_retention, 29 | day2_revenue, 30 | day7_revenue, 31 | day30_revenue, 32 | number_of_installs 33 | FROM 34 | `${biDatasetId}.${biTableId}_${partitionDay}` 35 | ) -------------------------------------------------------------------------------- /sql/app_trd_ad_group_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.*, 17 | adgroup_id, 18 | adgroup_name, 19 | adg.adgroup_status, 20 | segments_ad_network_type, 21 | adg_impressions, 22 | adg_clicks, 23 | adg_cost, 24 | adg_installs, 25 | adg_in_app_actions, 26 | adg_conversions_value, 27 | headline, 28 | description, 29 | image, 30 | video, 31 | headline_l, 32 | description_l, 33 | image_l, 34 | video_l 35 | FROM `${datasetId}.app_snd_ad_group_perf_report` adg 36 | INNER JOIN 37 | `${datasetId}.base_snd_campaigns` camp 38 | USING ( 39 | campaign_id, 40 | segments_date) -------------------------------------------------------------------------------- /sql/app_trd_campaign_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | camp.*, 17 | segments_conversion_action_name, 18 | event_name, 19 | include_in_conversion, 20 | count_type, 21 | segments_conversion_source, 22 | segments_conversion_action, 23 | metrics_conversions_value, 24 | metrics_conversions, 25 | metrics_all_conversions_value, 26 | metrics_all_conversions, 27 | segments_ad_network_type, 28 | installs, 29 | in_app_actions 30 | FROM 31 | `${datasetId}.app_snd_campaign_conv_report` r 32 | INNER JOIN 33 | `${datasetId}.base_snd_campaigns` camp 34 | USING ( 35 | campaign_id, 36 | segments_date) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_bi_load_data.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE bi AS ( 16 | SELECT 17 | UPPER(TO_HEX(MD5(UPPER(device_id)))) AS device_id, 18 | install_date, 19 | app_id, 20 | platform, 21 | country, 22 | CASE 23 | WHEN number_of_installs > 1 THEN 'reinstall user' 24 | WHEN number_of_installs = 1 THEN 'new user' 25 | END AS user_type, 26 | day2_retention, 27 | day7_retention, 28 | day30_retention, 29 | day2_revenue, 30 | day7_revenue, 31 | day30_revenue, 32 | number_of_installs 33 | FROM 34 | `${biDatasetId}.${biTableId}_${partitionDay}` 35 | ) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_ad_group_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.*, 17 | adgroup_id, 18 | adgroup_name, 19 | adg.adgroup_status, 20 | segments_ad_network_type, 21 | adg_impressions, 22 | adg_clicks, 23 | adg_cost, 24 | adg_installs, 25 | adg_in_app_actions, 26 | adg_conversions_value, 27 | headline, 28 | description, 29 | image, 30 | video, 31 | headline_l, 32 | description_l, 33 | image_l, 34 | video_l 35 | FROM `${datasetId}.app_snd_ad_group_perf_report` adg 36 | INNER JOIN 37 | `${datasetId}.base_snd_campaigns` camp 38 | USING ( 39 | campaign_id, 40 | segments_date) -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We'd love to accept your patches and contributions to this project. 4 | 5 | ## Before you begin 6 | 7 | ### Sign our Contributor License Agreement 8 | 9 | Contributions to this project must be accompanied by a 10 | [Contributor License Agreement](https://cla.developers.google.com/about) (CLA). 11 | You (or your employer) retain the copyright to your contribution; this simply 12 | gives us permission to use and redistribute your contributions as part of the 13 | project. 14 | 15 | If you or your current employer have already signed the Google CLA (even if it 16 | was for a different project), you probably don't need to do it again. 17 | 18 | Visit to see your current agreements or to 19 | sign a new one. 20 | 21 | ### Review our community guidelines 22 | 23 | This project follows 24 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/). 25 | 26 | ## Contribution process 27 | 28 | ### Code reviews 29 | 30 | All submissions, including submissions by project members, require review. We 31 | use GitHub pull requests for this purpose. Consult 32 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 33 | information on using pull requests. 34 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_campaign_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | camp.*, 17 | segments_conversion_action_name, 18 | event_name, 19 | include_in_conversion, 20 | count_type, 21 | segments_conversion_source, 22 | segments_conversion_action, 23 | metrics_conversions_value, 24 | metrics_conversions, 25 | metrics_all_conversions_value, 26 | metrics_all_conversions, 27 | segments_ad_network_type, 28 | installs, 29 | in_app_actions 30 | FROM 31 | `${datasetId}.app_snd_campaign_conv_report` r 32 | INNER JOIN 33 | `${datasetId}.base_snd_campaigns` camp 34 | USING ( 35 | campaign_id, 36 | segments_date) -------------------------------------------------------------------------------- /sql/adh_retail_join_lego_init.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | * 17 | FROM ( ( 18 | SELECT * 19 | FROM 20 | `${datasetId}.adh_retail_calc_in_market_${partitionDay}` 21 | WHERE 22 | convs_sum_users > 0) 23 | UNION ALL ( 24 | SELECT * 25 | FROM 26 | `${datasetId}.adh_retail_calc_affinity_${partitionDay}` 27 | WHERE 28 | convs_sum_users > 0) ) AS a 29 | LEFT JOIN 30 | `${datasetId}.adh_config_prep_${partitionDay}` AS b 31 | ON 32 | a.adgroup_id = b.adGroupId 33 | LEFT JOIN 34 | `${datasetId}.adh_retail_prep_${partitionDay}` AS c 35 | ON 36 | a.adgroup_id = c.Ad_group_id 37 | AND a.audience_name = c.User_interest 38 | WHERE 39 | a.adgroup_id IS NOT NULL -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_retail_join_lego_init.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | * 17 | FROM ( ( 18 | SELECT * 19 | FROM 20 | `${datasetId}.adh_retail_calc_in_market_${partitionDay}` 21 | WHERE 22 | convs_sum_users > 0) 23 | UNION ALL ( 24 | SELECT * 25 | FROM 26 | `${datasetId}.adh_retail_calc_affinity_${partitionDay}` 27 | WHERE 28 | convs_sum_users > 0) ) AS a 29 | LEFT JOIN 30 | `${datasetId}.adh_config_prep_${partitionDay}` AS b 31 | ON 32 | a.adgroup_id = b.adGroupId 33 | LEFT JOIN 34 | `${datasetId}.adh_retail_prep_${partitionDay}` AS c 35 | ON 36 | a.adgroup_id = c.Ad_group_id 37 | AND a.audience_name = c.User_interest 38 | WHERE 39 | a.adgroup_id IS NOT NULL -------------------------------------------------------------------------------- /sql/nonapp_snd_campaign_ads_approval.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | customer.id AS customer_id, 17 | campaign.id AS campaign_id, 18 | campaign.name AS campaign_name, 19 | COUNT( 20 | IF( 21 | ad_group_ad.policy_summary.approval_status LIKE 'DISAPPROVED', 22 | ad_group_ad.policy_summary.approval_status, 23 | NULL)) AS disapproved_ads, 24 | COUNT( 25 | IF( 26 | ad_group_ad.policy_summary.review_status LIKE 'REVIEW_IN_PROGRESS', 27 | ad_group_ad.policy_summary.approval_status, 28 | NULL)) AS underreview_ads, 29 | COUNT(ad_group_ad.ad.id) AS all_ads 30 | FROM `${datasetId}.report_base_campaign_ads_approval` 31 | WHERE date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 32 | GROUP BY customer_id, campaign_id, campaign_name -------------------------------------------------------------------------------- /sql/nonapp_trd_geo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | campaign_id Campaign_ID, 17 | customer_id Customer_ID, 18 | currency Currency, 19 | customer_descriptive_name Account, 20 | campaign_name Campaign, 21 | campaign_status Campaign_status, 22 | campaign_advertising_channel_type AS Campaign_type, 23 | campaign_advertising_channel_sub_type AS Campaign_sub_type, 24 | segments_week Week, 25 | geo_target_constant_canonical_name Country_Territory, 26 | geographic_view_country_criterion_id, 27 | segments_ad_network_type Ad_network_type, 28 | metrics_clicks Clicks, 29 | metrics_conversions_value Conv_value, 30 | metrics_impressions Impressions, 31 | metrics_conversions Conversions, 32 | metrics_cost Cost 33 | FROM `${datasetId}.base_snd_geo_perf_report` -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_snd_campaign_ads_approval.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | customer.id AS customer_id, 17 | campaign.id AS campaign_id, 18 | campaign.name AS campaign_name, 19 | COUNT( 20 | IF( 21 | ad_group_ad.policy_summary.approval_status LIKE 'DISAPPROVED', 22 | ad_group_ad.policy_summary.approval_status, 23 | NULL)) AS disapproved_ads, 24 | COUNT( 25 | IF( 26 | ad_group_ad.policy_summary.review_status LIKE 'REVIEW_IN_PROGRESS', 27 | ad_group_ad.policy_summary.approval_status, 28 | NULL)) AS underreview_ads, 29 | COUNT(ad_group_ad.ad.id) AS all_ads 30 | FROM `${datasetId}.report_base_campaign_ads_approval` 31 | WHERE date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 32 | GROUP BY customer_id, campaign_id, campaign_name -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_geo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | campaign_id Campaign_ID, 17 | customer_id Customer_ID, 18 | currency Currency, 19 | customer_descriptive_name Account, 20 | campaign_name Campaign, 21 | campaign_status Campaign_status, 22 | campaign_advertising_channel_type AS Campaign_type, 23 | campaign_advertising_channel_sub_type AS Campaign_sub_type, 24 | segments_week Week, 25 | geo_target_constant_canonical_name Country_Territory, 26 | geographic_view_country_criterion_id, 27 | segments_ad_network_type Ad_network_type, 28 | metrics_clicks Clicks, 29 | metrics_conversions_value Conv_value, 30 | metrics_impressions Impressions, 31 | metrics_conversions Conversions, 32 | metrics_cost Cost 33 | FROM `${datasetId}.base_snd_geo_perf_report` -------------------------------------------------------------------------------- /sql/nonapp_trd_time.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.segments.hour AS Hour_of_day, 24 | a.segments.day_of_week AS Day_of_week, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value 31 | FROM `${datasetId}.report_nonapp_campaign_perf_all_time` a 32 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_ads_approval.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | a.customer.id AS Customer_ID, 17 | a.campaign.id AS Campaign_ID, 18 | a.ad_group_ad.ad.id, 19 | a.ad_group_ad.policy_summary.approval_status AS Approval_status, 20 | a.ad_group_ad.policy_summary.review_status AS Review_status, 21 | a.ad_group_ad.ad.type AS Ad_type, 22 | policy.topic AS policy_topic, 23 | policy.type AS policy_type, 24 | a.campaign.name AS Campaign_name, 25 | a.customer.descriptive_name AS Account, 26 | a.campaign.status AS Campaign_status, 27 | a.campaign.advertising_channel_type AS Campaign_type, 28 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type 29 | FROM 30 | `${datasetId}.report_base_campaign_ads_approval` a, 31 | UNNEST(ad_group_ad.policy_summary.policy_topic_entries) AS policy 32 | WHERE date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_time.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.segments.hour AS Hour_of_day, 24 | a.segments.day_of_week AS Day_of_week, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value 31 | FROM `${datasetId}.report_nonapp_campaign_perf_all_time` a 32 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_ads_approval.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | a.customer.id AS Customer_ID, 17 | a.campaign.id AS Campaign_ID, 18 | a.ad_group_ad.ad.id, 19 | a.ad_group_ad.policy_summary.approval_status AS Approval_status, 20 | a.ad_group_ad.policy_summary.review_status AS Review_status, 21 | a.ad_group_ad.ad.type AS Ad_type, 22 | policy.topic AS policy_topic, 23 | policy.type AS policy_type, 24 | a.campaign.name AS Campaign_name, 25 | a.customer.descriptive_name AS Account, 26 | a.campaign.status AS Campaign_status, 27 | a.campaign.advertising_channel_type AS Campaign_type, 28 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type 29 | FROM 30 | `${datasetId}.report_base_campaign_ads_approval` a, 31 | UNNEST(ad_group_ad.policy_summary.policy_topic_entries) AS policy 32 | WHERE date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_gender.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.ad_group_criterion.gender.type AS Gender, 24 | a.customer.currency_code AS Currency, 25 | a.metrics.clicks AS Clicks, 26 | a.metrics.impressions AS Impressions, 27 | a.metrics.cost_micros / 1000000 AS Cost, 28 | a.metrics.conversions AS Conversions, 29 | a.metrics.conversions_value AS Conv_value, 30 | a.metrics.all_conversions AS All_conversions, 31 | a.metrics.all_conversions_value AS All_conv_value 32 | FROM `${datasetId}.report_nonapp_campaign_perf_gender` a 33 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_age.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.ad_group_criterion.age_range.type AS Age_range, 24 | a.customer.currency_code AS Currency, 25 | a.metrics.clicks AS Clicks, 26 | a.metrics.impressions AS Impressions, 27 | a.metrics.cost_micros / 1000000 AS Cost, 28 | a.metrics.conversions AS Conversions, 29 | a.metrics.conversions_value AS Conv_value, 30 | a.metrics.all_conversions AS All_conversions, 31 | a.metrics.all_conversions_value AS All_conv_value, 32 | FROM `${datasetId}.report_nonapp_campaign_perf_age_range` a 33 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_gender.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.ad_group_criterion.gender.type AS Gender, 24 | a.customer.currency_code AS Currency, 25 | a.metrics.clicks AS Clicks, 26 | a.metrics.impressions AS Impressions, 27 | a.metrics.cost_micros / 1000000 AS Cost, 28 | a.metrics.conversions AS Conversions, 29 | a.metrics.conversions_value AS Conv_value, 30 | a.metrics.all_conversions AS All_conversions, 31 | a.metrics.all_conversions_value AS All_conv_value 32 | FROM `${datasetId}.report_nonapp_campaign_perf_gender` a 33 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/app_trd_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | rec.*, 17 | r.metrics.cost_micros, 18 | r.metrics.impressions, 19 | r.metrics.clicks, 20 | r.metrics.conversions, 21 | r.metrics.conversions_value, 22 | r.metrics.all_conversions, 23 | r.metrics.all_conversions_value, 24 | r.metrics.video_views, 25 | r.customer.id, 26 | r.customer.currency_code, 27 | r.customer.descriptive_name, 28 | r.customer.optimization_score, 29 | r.customer.optimization_score_weight 30 | FROM 31 | `${datasetId}.report_base_account_performance_*` r 32 | INNER JOIN 33 | ( 34 | SELECT 35 | customer.id customer_id, 36 | segments.date segments_date, 37 | MAX(_PARTITIONTIME) PARTITIONTIME 38 | FROM 39 | `${datasetId}.report_base_account_performance_*` 40 | GROUP BY 41 | 1, 2 42 | ) rec 43 | ON 44 | r.customer.id = rec.customer_id 45 | AND r.segments.date = rec.segments_date 46 | AND r._PARTITIONTIME = rec.PARTITIONTIME 47 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_age.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.ad_group_criterion.age_range.type AS Age_range, 24 | a.customer.currency_code AS Currency, 25 | a.metrics.clicks AS Clicks, 26 | a.metrics.impressions AS Impressions, 27 | a.metrics.cost_micros / 1000000 AS Cost, 28 | a.metrics.conversions AS Conversions, 29 | a.metrics.conversions_value AS Conv_value, 30 | a.metrics.all_conversions AS All_conversions, 31 | a.metrics.all_conversions_value AS All_conv_value, 32 | FROM `${datasetId}.report_nonapp_campaign_perf_age_range` a 33 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_feed_item_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.segments.product_item_id AS Product_ID, 24 | a.segments.product_title AS Product_title, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_all_feed_item` a 34 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | rec.*, 17 | r.metrics.cost_micros, 18 | r.metrics.impressions, 19 | r.metrics.clicks, 20 | r.metrics.conversions, 21 | r.metrics.conversions_value, 22 | r.metrics.all_conversions, 23 | r.metrics.all_conversions_value, 24 | r.metrics.video_views, 25 | r.customer.id, 26 | r.customer.currency_code, 27 | r.customer.descriptive_name, 28 | r.customer.optimization_score, 29 | r.customer.optimization_score_weight 30 | FROM 31 | `${datasetId}.report_base_account_performance_*` r 32 | INNER JOIN 33 | ( 34 | SELECT 35 | customer.id customer_id, 36 | segments.date segments_date, 37 | MAX(_PARTITIONTIME) PARTITIONTIME 38 | FROM 39 | `${datasetId}.report_base_account_performance_*` 40 | GROUP BY 41 | 1, 2 42 | ) rec 43 | ON 44 | r.customer.id = rec.customer_id 45 | AND r.segments.date = rec.segments_date 46 | AND r._PARTITIONTIME = rec.PARTITIONTIME 47 | -------------------------------------------------------------------------------- /sql/nonapp_trd_dsa.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.dynamic_search_ads_search_term_view.search_term AS Search_term, 24 | a.dynamic_search_ads_search_term_view.landing_page AS Landing_page, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_dsa` a 34 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_feed_item_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.segments.product_item_id AS Product_ID, 24 | a.segments.product_title AS Product_title, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_all_feed_item` a 34 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_dsa.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.dynamic_search_ads_search_term_view.search_term AS Search_term, 24 | a.dynamic_search_ads_search_term_view.landing_page AS Landing_page, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_dsa` a 34 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_placement.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.group_placement_view.placement_type AS Placement_type, 24 | a.group_placement_view.display_name AS Placement_name, 25 | a.group_placement_view.target_url AS Target_URL, 26 | a.customer.currency_code AS Currency, 27 | a.metrics.clicks AS Clicks, 28 | a.metrics.impressions AS Impressions, 29 | a.metrics.cost_micros / 1000000 AS Cost, 30 | a.metrics.conversions AS Conversions, 31 | a.metrics.conversions_value AS Conv_value, 32 | a.metrics.all_conversions AS All_conversions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_base_detail_placement_view` a 35 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_search_term.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.search_term_view.search_term AS Search_term, 24 | a.segments.search_term_match_type AS Search_term_match_type, 25 | a.search_term_view.status AS Search_term_status, 26 | a.customer.currency_code AS Currency, 27 | a.metrics.clicks AS Clicks, 28 | a.metrics.impressions AS Impressions, 29 | a.metrics.cost_micros / 1000000 AS Cost, 30 | a.metrics.conversions AS Conversions, 31 | a.metrics.conversions_value AS Conv_value, 32 | a.metrics.all_conversions AS All_conversions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_nonapp_campaign_perf_search_search_term` a 35 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_placement.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.group_placement_view.placement_type AS Placement_type, 24 | a.group_placement_view.display_name AS Placement_name, 25 | a.group_placement_view.target_url AS Target_URL, 26 | a.customer.currency_code AS Currency, 27 | a.metrics.clicks AS Clicks, 28 | a.metrics.impressions AS Impressions, 29 | a.metrics.cost_micros / 1000000 AS Cost, 30 | a.metrics.conversions AS Conversions, 31 | a.metrics.conversions_value AS Conv_value, 32 | a.metrics.all_conversions AS All_conversions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_base_detail_placement_view` a 35 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_search_term.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | a.search_term_view.search_term AS Search_term, 24 | a.segments.search_term_match_type AS Search_term_match_type, 25 | a.search_term_view.status AS Search_term_status, 26 | a.customer.currency_code AS Currency, 27 | a.metrics.clicks AS Clicks, 28 | a.metrics.impressions AS Impressions, 29 | a.metrics.cost_micros / 1000000 AS Cost, 30 | a.metrics.conversions AS Conversions, 31 | a.metrics.conversions_value AS Conv_value, 32 | a.metrics.all_conversions AS All_conversions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_nonapp_campaign_perf_search_search_term` a 35 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_trd_sitelink.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.extension_feed_item.sitelink_feed_item.line2 AS Sitelink2, 17 | a.extension_feed_item.sitelink_feed_item.line1 AS Sitelink1, 18 | a.campaign.advertising_channel_type AS Campaign_type, 19 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 20 | a.metrics.conversions AS Conversions, 21 | a.customer.currency_code AS Currency, 22 | a.campaign.id AS Campaign_id, 23 | a.metrics.clicks AS Clicks, 24 | a.metrics.conversions_value AS Conv_value, 25 | a.metrics.impressions AS Impressions, 26 | a.extension_feed_item.sitelink_feed_item.link_text AS Link_text, 27 | a.campaign.name AS Campaign_name, 28 | a.customer.descriptive_name AS Account, 29 | a.campaign.status AS Campaign_status, 30 | a.customer.id AS Customer_ID, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.all_conversions AS All_converdsions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_nonapp_campaign_perf_search_extensions` a 35 | WHERE date(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_sitelink.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.extension_feed_item.sitelink_feed_item.line2 AS Sitelink2, 17 | a.extension_feed_item.sitelink_feed_item.line1 AS Sitelink1, 18 | a.campaign.advertising_channel_type AS Campaign_type, 19 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 20 | a.metrics.conversions AS Conversions, 21 | a.customer.currency_code AS Currency, 22 | a.campaign.id AS Campaign_id, 23 | a.metrics.clicks AS Clicks, 24 | a.metrics.conversions_value AS Conv_value, 25 | a.metrics.impressions AS Impressions, 26 | a.extension_feed_item.sitelink_feed_item.link_text AS Link_text, 27 | a.campaign.name AS Campaign_name, 28 | a.customer.descriptive_name AS Account, 29 | a.campaign.status AS Campaign_status, 30 | a.customer.id AS Customer_ID, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.all_conversions AS All_converdsions, 33 | a.metrics.all_conversions_value AS All_conv_value 34 | FROM `${datasetId}.report_nonapp_campaign_perf_search_extensions` a 35 | WHERE date(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/nonapp_snd_campaign_pacing.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | p.campaign.id, 17 | AVG(p.campaign_budget.amount_micros) / 1e6 AS budget, 18 | spend_7d, 19 | safe_divide(AVG(spend_7d), AVG(p.campaign_budget.amount_micros / 1e6)) AS budget_utilization 20 | FROM `${datasetId}.report_base_campaigns` p 21 | LEFT JOIN 22 | ( 23 | SELECT c.id, c.name, AVG(cost_micros) / 1e6 AS spend_7d, 24 | FROM 25 | ( 26 | SELECT campaign.id, campaign.name, segments.date, SUM(metrics.cost_micros) AS cost_micros 27 | FROM `${datasetId}.report_base_campaign_performance` 28 | WHERE 29 | date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 30 | AND segments.date < PARSE_DATE('%Y%m%d', '${partitionDay}') 31 | AND segments.date > date_sub(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL 8 day) 32 | GROUP BY 1, 2, 3 33 | ) c 34 | GROUP BY 1, 2 35 | ) t 36 | ON p.campaign.id = t.id 37 | WHERE 38 | date(_partitionTime) <= PARSE_DATE('%Y%m%d', '${partitionDay}') 39 | AND date(_partitionTime) > date_sub(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL 7 day) 40 | GROUP BY campaign.id, spend_7d -------------------------------------------------------------------------------- /sql/nonapp_trd_search_keywords.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.ad_group.name AS Ad_group_name, 19 | a.ad_group.id AS Ad_group_id, 20 | a.campaign.name AS Campaign, 21 | a.campaign.id AS Campaign_ID, 22 | a.campaign.status AS Campaign_status, 23 | a.campaign.advertising_channel_type AS Campaign_type, 24 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 25 | a.ad_group_criterion.keyword.text AS Keyword, 26 | a.ad_group_criterion.keyword.match_type AS Keyword_match_type, 27 | a.ad_group_criterion.quality_info.quality_score AS Keyword_QS, 28 | a.customer.currency_code AS Currency, 29 | a.metrics.clicks AS Clicks, 30 | a.metrics.impressions AS Impressions, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.conversions AS Conversions, 33 | a.metrics.conversions_value AS Conv_value, 34 | a.metrics.all_conversions AS All_conversions, 35 | a.metrics.all_conversions_value AS All_conv_value 36 | FROM `${datasetId}.report_nonapp_campaign_perf_search_keywords` a 37 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 38 | -------------------------------------------------------------------------------- /sql/adh_app_prep.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | DISTINCT lego.campaign_id, 17 | lego.app_id, 18 | lego.conversion_id, 19 | FROM ( 20 | SELECT 21 | DISTINCT camp.campaign.id campaign_id, 22 | camp.campaign.app_campaign_setting.app_id app_id, 23 | SPLIT( segments.conversion_action ,"/")[ 24 | OFFSET 25 | (3)] conversion_id, 26 | MAX(conv.segments.date) segments_date 27 | FROM 28 | `${legoDatasetId}.report_base_campaign_conversion` conv 29 | LEFT JOIN 30 | `${legoDatasetId}.report_base_campaigns` camp 31 | ON 32 | conv.campaign.id = camp.campaign.id 33 | WHERE 34 | segments.conversion_action_category = "DOWNLOAD" 35 | AND metrics.conversions > 0 36 | AND camp.campaign.app_campaign_setting.app_id IS NOT NULL 37 | GROUP BY 38 | 1, 39 | 2, 40 | 3) lego 41 | INNER JOIN ( 42 | SELECT 43 | campaign.id campaign_id, 44 | MAX(segments.date) segments_date 45 | FROM 46 | `${legoDatasetId}.report_base_campaign_conversion` 47 | WHERE 48 | segments.conversion_action_category = "DOWNLOAD" 49 | AND metrics.conversions > 0 50 | GROUP BY 51 | 1) 52 | USING 53 | (campaign_id, 54 | segments_date) -------------------------------------------------------------------------------- /sql/nonapp_trd_audience.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | b.name AS Audience, 24 | b.type AS Audience_type, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_all_audience` a 34 | LEFT JOIN 35 | ( 36 | SELECT user_list.resource_name AS user_list, user_list.name, user_list.type 37 | FROM `${datasetId}.report_nonapp_user_lists` 38 | ) b 39 | ON a.ad_group_criterion.user_list.user_list = b.user_list 40 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_snd_campaign_pacing.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | p.campaign.id, 17 | AVG(p.campaign_budget.amount_micros) / 1e6 AS budget, 18 | spend_7d, 19 | safe_divide(AVG(spend_7d), AVG(p.campaign_budget.amount_micros / 1e6)) AS budget_utilization 20 | FROM `${datasetId}.report_base_campaigns` p 21 | LEFT JOIN 22 | ( 23 | SELECT c.id, c.name, AVG(cost_micros) / 1e6 AS spend_7d, 24 | FROM 25 | ( 26 | SELECT campaign.id, campaign.name, segments.date, SUM(metrics.cost_micros) AS cost_micros 27 | FROM `${datasetId}.report_base_campaign_performance` 28 | WHERE 29 | date(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 30 | AND segments.date < PARSE_DATE('%Y%m%d', '${partitionDay}') 31 | AND segments.date > date_sub(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL 8 day) 32 | GROUP BY 1, 2, 3 33 | ) c 34 | GROUP BY 1, 2 35 | ) t 36 | ON p.campaign.id = t.id 37 | WHERE 38 | date(_partitionTime) <= PARSE_DATE('%Y%m%d', '${partitionDay}') 39 | AND date(_partitionTime) > date_sub(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL 7 day) 40 | GROUP BY campaign.id, spend_7d -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_search_keywords.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.ad_group.name AS Ad_group_name, 19 | a.ad_group.id AS Ad_group_id, 20 | a.campaign.name AS Campaign, 21 | a.campaign.id AS Campaign_ID, 22 | a.campaign.status AS Campaign_status, 23 | a.campaign.advertising_channel_type AS Campaign_type, 24 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 25 | a.ad_group_criterion.keyword.text AS Keyword, 26 | a.ad_group_criterion.keyword.match_type AS Keyword_match_type, 27 | a.ad_group_criterion.quality_info.quality_score AS Keyword_QS, 28 | a.customer.currency_code AS Currency, 29 | a.metrics.clicks AS Clicks, 30 | a.metrics.impressions AS Impressions, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.conversions AS Conversions, 33 | a.metrics.conversions_value AS Conv_value, 34 | a.metrics.all_conversions AS All_conversions, 35 | a.metrics.all_conversions_value AS All_conv_value 36 | FROM `${datasetId}.report_nonapp_campaign_perf_search_keywords` a 37 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 38 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_app_prep.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | DISTINCT lego.campaign_id, 17 | lego.app_id, 18 | lego.conversion_id, 19 | FROM ( 20 | SELECT 21 | DISTINCT camp.campaign.id campaign_id, 22 | camp.campaign.app_campaign_setting.app_id app_id, 23 | SPLIT( segments.conversion_action ,"/")[ 24 | OFFSET 25 | (3)] conversion_id, 26 | MAX(conv.segments.date) segments_date 27 | FROM 28 | `${legoDatasetId}.report_base_campaign_conversion` conv 29 | LEFT JOIN 30 | `${legoDatasetId}.report_base_campaigns` camp 31 | ON 32 | conv.campaign.id = camp.campaign.id 33 | WHERE 34 | segments.conversion_action_category = "DOWNLOAD" 35 | AND metrics.conversions > 0 36 | AND camp.campaign.app_campaign_setting.app_id IS NOT NULL 37 | GROUP BY 38 | 1, 39 | 2, 40 | 3) lego 41 | INNER JOIN ( 42 | SELECT 43 | campaign.id campaign_id, 44 | MAX(segments.date) segments_date 45 | FROM 46 | `${legoDatasetId}.report_base_campaign_conversion` 47 | WHERE 48 | segments.conversion_action_category = "DOWNLOAD" 49 | AND metrics.conversions > 0 50 | GROUP BY 51 | 1) 52 | USING 53 | (campaign_id, 54 | segments_date) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_audience.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | b.name AS Audience, 24 | b.type AS Audience_type, 25 | a.customer.currency_code AS Currency, 26 | a.metrics.clicks AS Clicks, 27 | a.metrics.impressions AS Impressions, 28 | a.metrics.cost_micros / 1000000 AS Cost, 29 | a.metrics.conversions AS Conversions, 30 | a.metrics.conversions_value AS Conv_value, 31 | a.metrics.all_conversions AS All_conversions, 32 | a.metrics.all_conversions_value AS All_conv_value 33 | FROM `${datasetId}.report_nonapp_campaign_perf_all_audience` a 34 | LEFT JOIN 35 | ( 36 | SELECT user_list.resource_name AS user_list, user_list.name, user_list.type 37 | FROM `${datasetId}.report_nonapp_user_lists` 38 | ) b 39 | ON a.ad_group_criterion.user_list.user_list = b.user_list 40 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/adh_retail_join_lego_final.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | 16 | SELECT 17 | d.adgroup_id, 18 | d.type, 19 | d.audience_name, 20 | d.audience_category, 21 | d.impressions, 22 | d.clicks, 23 | d.unique_users, 24 | d.clk_unique_users, 25 | d.convs_sum_users, 26 | d.click_cost_sum_users, 27 | d.imp_cost_sum_users, 28 | d.adGroupLabel as adgroup_label, 29 | d.status, 30 | exists_in_other_adgroup 31 | FROM 32 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` AS d 33 | LEFT JOIN ( 34 | SELECT 35 | DISTINCT * 36 | FROM ( 37 | SELECT 38 | a.*, 39 | b.ad_group_id AS exists_in_other_adgroup 40 | FROM ( 41 | SELECT 42 | * 43 | FROM 44 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` 45 | WHERE 46 | status IS NULL) AS a 47 | LEFT JOIN 48 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` AS b 49 | ON 50 | a.adGroupLabel = b.adGroupLabel 51 | AND a.audience_name = b.audience_name 52 | AND a.audience_category = b.audience_category 53 | AND b.ad_group_id IS NOT NULL ) 54 | WHERE 55 | exists_in_other_adgroup != adgroup_id ) AS c 56 | ON 57 | c.adgroup_id = d.adgroup_id 58 | AND c.audience_name = d.audience_name 59 | AND c.audience_category = d.audience_category -------------------------------------------------------------------------------- /config/workflow_nonapplite.json: -------------------------------------------------------------------------------- 1 | { 2 | "download_mcc_reports_impl": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": [ 6 | "base_geo_target_constant", 7 | "base_language_constant", 8 | "base_labels" 9 | ] 10 | } 11 | }, 12 | "download_reports_impl": { 13 | "type": "knot", 14 | "embedded": { 15 | "dueTime": 40, 16 | "tasks": [ 17 | "base_account_budget", 18 | "base_account_change_event", 19 | "base_campaign_ads_approval", 20 | "base_campaign_conversion", 21 | "base_campaign_criterion", 22 | "base_campaign_performance", 23 | "base_campaigns", 24 | "base_customer_label", 25 | "base_geographic_view" 26 | ] 27 | }, 28 | "errorOptions": { 29 | "ignoreError": true 30 | } 31 | }, 32 | "load_reports_impl": { 33 | "type": "knot", 34 | "embedded": { 35 | "tasks": ["baselite_load_reports"] 36 | } 37 | }, 38 | "trigger_snd_query_impl": { 39 | "type": "knot", 40 | "embedded": { 41 | "tasks": ["base_snd_query", "nonapp_snd_query"] 42 | }, 43 | "next": "trigger_trd_query_impl" 44 | }, 45 | "trigger_trd_query_impl": { 46 | "type": "knot", 47 | "embedded": { 48 | "tasks": ["nonapplite_trd_query"] 49 | }, 50 | "next": "trigger_fourth_query_impl" 51 | }, 52 | "trigger_fourth_query_impl": { 53 | "type": "knot", 54 | "appendedParameters": { 55 | "markTaskId": "mark_label" 56 | }, 57 | "embedded": { 58 | "tasks": ["nonapplite_fourth_query"] 59 | }, 60 | "next": "trigger_customized_task" 61 | }, 62 | "trigger_mark_email_impl": { 63 | "type": "knot", 64 | "appendedParameters": { 65 | "markTaskId": "mark_email" 66 | }, 67 | "embedded": { 68 | "tasks": ["nonapplite_fourth_query"] 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_retail_join_lego_final.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | 16 | SELECT 17 | d.adgroup_id, 18 | d.type, 19 | d.audience_name, 20 | d.audience_category, 21 | d.impressions, 22 | d.clicks, 23 | d.unique_users, 24 | d.clk_unique_users, 25 | d.convs_sum_users, 26 | d.click_cost_sum_users, 27 | d.imp_cost_sum_users, 28 | d.adGroupLabel as adgroup_label, 29 | d.status, 30 | exists_in_other_adgroup 31 | FROM 32 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` AS d 33 | LEFT JOIN ( 34 | SELECT 35 | DISTINCT * 36 | FROM ( 37 | SELECT 38 | a.*, 39 | b.ad_group_id AS exists_in_other_adgroup 40 | FROM ( 41 | SELECT 42 | * 43 | FROM 44 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` 45 | WHERE 46 | status IS NULL) AS a 47 | LEFT JOIN 48 | `${datasetId}.adh_retail_join_lego_init_${partitionDay}` AS b 49 | ON 50 | a.adGroupLabel = b.adGroupLabel 51 | AND a.audience_name = b.audience_name 52 | AND a.audience_category = b.audience_category 53 | AND b.ad_group_id IS NOT NULL ) 54 | WHERE 55 | exists_in_other_adgroup != adgroup_id ) AS c 56 | ON 57 | c.adgroup_id = d.adgroup_id 58 | AND c.audience_name = d.audience_name 59 | AND c.audience_category = d.audience_category -------------------------------------------------------------------------------- /sql/adh_bi_calc_affinity.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE affinity AS ( 16 | SELECT 17 | UPPER(device_id_md5) AS device_id, 18 | b.app_id, 19 | affinity_name, 20 | query_id.time_usec AS query_time 21 | FROM 22 | adh.google_ads_impressions_rdid impr, 23 | UNNEST (affinity) AS affinity_id 24 | LEFT JOIN adh.affinity USING (affinity_id) 25 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 26 | ON b.campaign_id = impr.campaign_id 27 | WHERE 28 | device_id_md5 IS NOT NULL 29 | ); 30 | SELECT 31 | user_type, 32 | platform, 33 | app_id, 34 | affinity_name, 35 | COUNT(distinct device_id) AS users, 36 | COUNT(device_id) AS total_grouped_users, 37 | SUM( 38 | IFNULL(day2_retention, 0) 39 | ) AS day2_retention, 40 | SUM( 41 | IFNULL(day7_retention, 0) 42 | ) AS day7_retention, 43 | SUM( 44 | IFNULL(day30_retention, 0) 45 | ) AS day30_retention, 46 | SUM( 47 | IFNULL(day2_revenue, 0) 48 | ) AS day2_revenue, 49 | SUM( 50 | IFNULL(day7_revenue, 0) 51 | ) AS day7_revenue, 52 | SUM( 53 | IFNULL(day30_revenue, 0) 54 | ) AS day30_revenue 55 | FROM 56 | tmp.bi 57 | LEFT JOIN tmp.affinity aff USING (device_id, app_id) 58 | WHERE 59 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 60 | GROUP BY 61 | 1, 62 | 2, 63 | 3, 4 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_bi_calc_affinity.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE affinity AS ( 16 | SELECT 17 | UPPER(device_id_md5) AS device_id, 18 | b.app_id, 19 | affinity_name, 20 | query_id.time_usec AS query_time 21 | FROM 22 | adh.google_ads_impressions_rdid impr, 23 | UNNEST (affinity) AS affinity_id 24 | LEFT JOIN adh.affinity USING (affinity_id) 25 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 26 | ON b.campaign_id = impr.campaign_id 27 | WHERE 28 | device_id_md5 IS NOT NULL 29 | ); 30 | SELECT 31 | user_type, 32 | platform, 33 | app_id, 34 | affinity_name, 35 | COUNT(distinct device_id) AS users, 36 | COUNT(device_id) AS total_grouped_users, 37 | SUM( 38 | IFNULL(day2_retention, 0) 39 | ) AS day2_retention, 40 | SUM( 41 | IFNULL(day7_retention, 0) 42 | ) AS day7_retention, 43 | SUM( 44 | IFNULL(day30_retention, 0) 45 | ) AS day30_retention, 46 | SUM( 47 | IFNULL(day2_revenue, 0) 48 | ) AS day2_revenue, 49 | SUM( 50 | IFNULL(day7_revenue, 0) 51 | ) AS day7_revenue, 52 | SUM( 53 | IFNULL(day30_revenue, 0) 54 | ) AS day30_revenue 55 | FROM 56 | tmp.bi 57 | LEFT JOIN tmp.affinity aff USING (device_id, app_id) 58 | WHERE 59 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 60 | GROUP BY 61 | 1, 62 | 2, 63 | 3, 4 -------------------------------------------------------------------------------- /sql/adh_bi_calc_demo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE demo AS ( 16 | SELECT 17 | UPPER(device_id_md5) AS device_id, 18 | b.app_id, 19 | gender_name as gender_name, 20 | age_group_name as age_group_name, 21 | ## 22 | query_id.time_usec AS query_time, 23 | FROM 24 | adh.google_ads_impressions_rdid impr 25 | LEFT JOIN adh.gender ON demographics.gender = gender_id 26 | LEFT JOIN adh.age_group ON demographics.age_group = age_group_id 27 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 28 | ON b.campaign_id = impr.campaign_id 29 | WHERE 30 | device_id_md5 IS NOT NULL 31 | 32 | ); 33 | SELECT 34 | user_type, 35 | app_id, 36 | platform, 37 | gender_name, 38 | age_group_name, 39 | COUNT(distinct device_id) AS users, 40 | SUM( 41 | IFNULL(day2_retention, 0) 42 | ) AS day2_retention, 43 | SUM( 44 | IFNULL(day7_retention, 0) 45 | ) AS day7_retention, 46 | SUM( 47 | IFNULL(day30_retention, 0) 48 | ) AS day30_retention, 49 | SUM( 50 | IFNULL(day2_revenue, 0) 51 | ) AS day2_revenue, 52 | SUM( 53 | IFNULL(day7_revenue, 0) 54 | ) AS day7_revenue, 55 | SUM( 56 | IFNULL(day30_revenue, 0) 57 | ) AS day30_revenue 58 | FROM 59 | tmp.bi 60 | INNER JOIN tmp.demo USING (device_id, app_id) 61 | ## 62 | WHERE 63 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 64 | GROUP BY 65 | 1, 66 | 2, 67 | 3, 68 | 4,5 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_bi_calc_demo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE demo AS ( 16 | SELECT 17 | UPPER(device_id_md5) AS device_id, 18 | b.app_id, 19 | gender_name as gender_name, 20 | age_group_name as age_group_name, 21 | ## 22 | query_id.time_usec AS query_time, 23 | FROM 24 | adh.google_ads_impressions_rdid impr 25 | LEFT JOIN adh.gender ON demographics.gender = gender_id 26 | LEFT JOIN adh.age_group ON demographics.age_group = age_group_id 27 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 28 | ON b.campaign_id = impr.campaign_id 29 | WHERE 30 | device_id_md5 IS NOT NULL 31 | 32 | ); 33 | SELECT 34 | user_type, 35 | app_id, 36 | platform, 37 | gender_name, 38 | age_group_name, 39 | COUNT(distinct device_id) AS users, 40 | SUM( 41 | IFNULL(day2_retention, 0) 42 | ) AS day2_retention, 43 | SUM( 44 | IFNULL(day7_retention, 0) 45 | ) AS day7_retention, 46 | SUM( 47 | IFNULL(day30_retention, 0) 48 | ) AS day30_retention, 49 | SUM( 50 | IFNULL(day2_revenue, 0) 51 | ) AS day2_revenue, 52 | SUM( 53 | IFNULL(day7_revenue, 0) 54 | ) AS day7_revenue, 55 | SUM( 56 | IFNULL(day30_revenue, 0) 57 | ) AS day30_revenue 58 | FROM 59 | tmp.bi 60 | INNER JOIN tmp.demo USING (device_id, app_id) 61 | ## 62 | WHERE 63 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 64 | GROUP BY 65 | 1, 66 | 2, 67 | 3, 68 | 4,5 -------------------------------------------------------------------------------- /sql/nonapp_trd_pmax_conversion.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | base AS ( 17 | SELECT * 18 | FROM `${datasetId}.report_nonapp_pmax_conversion` 19 | WHERE 20 | _PARTITIONTIME IN ( 21 | SELECT MAX(_partitionTime) FROM `${datasetId}.report_nonapp_pmax_conversion` 22 | ) 23 | ), 24 | conv_value AS ( 25 | SELECT DISTINCT 26 | customer.id AS Customer_ID, 27 | sum(metrics.all_conversions_value) AS conv_value 28 | FROM base 29 | GROUP BY 1 30 | ), 31 | dda AS ( 32 | SELECT DISTINCT 33 | customer.id AS Customer_ID, 34 | STRING_AGG(conversion_action.attribution_model_settings.attribution_model) AS dda 35 | FROM base 36 | GROUP BY 1 37 | ), 38 | oci AS ( 39 | SELECT DISTINCT 40 | customer.id AS Customer_ID, 41 | STRING_AGG(conversion_action.type) AS oci 42 | FROM base 43 | GROUP BY 1 44 | ) 45 | SELECT DISTINCT 46 | customer.id AS Customer_ID, 47 | customer.currency_code AS Currency, 48 | customer.descriptive_name AS Account, 49 | CASE WHEN cv.conv_value > 0 THEN TRUE ELSE FALSE END AS has_conv_value, 50 | CASE WHEN REGEXP_CONTAINS(d.dda, 'DATA_DRIVEN') THEN TRUE ELSE FALSE END AS has_dda, 51 | CASE WHEN REGEXP_CONTAINS(o.oci, 'UPLOAD') THEN TRUE ELSE FALSE END AS has_oci 52 | FROM base b 53 | LEFT JOIN conv_value cv 54 | ON b.customer.id = cv.Customer_ID 55 | LEFT JOIN dda d 56 | ON b.customer.id = d.Customer_ID 57 | LEFT JOIN oci o 58 | ON b.customer.id = o.Customer_ID -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_pmax_conversion.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | base AS ( 17 | SELECT * 18 | FROM `${datasetId}.report_nonapp_pmax_conversion` 19 | WHERE 20 | _PARTITIONTIME IN ( 21 | SELECT MAX(_partitionTime) FROM `${datasetId}.report_nonapp_pmax_conversion` 22 | ) 23 | ), 24 | conv_value AS ( 25 | SELECT DISTINCT 26 | customer.id AS Customer_ID, 27 | sum(metrics.all_conversions_value) AS conv_value 28 | FROM base 29 | GROUP BY 1 30 | ), 31 | dda AS ( 32 | SELECT DISTINCT 33 | customer.id AS Customer_ID, 34 | STRING_AGG(conversion_action.attribution_model_settings.attribution_model) AS dda 35 | FROM base 36 | GROUP BY 1 37 | ), 38 | oci AS ( 39 | SELECT DISTINCT 40 | customer.id AS Customer_ID, 41 | STRING_AGG(conversion_action.type) AS oci 42 | FROM base 43 | GROUP BY 1 44 | ) 45 | SELECT DISTINCT 46 | customer.id AS Customer_ID, 47 | customer.currency_code AS Currency, 48 | customer.descriptive_name AS Account, 49 | CASE WHEN cv.conv_value > 0 THEN TRUE ELSE FALSE END AS has_conv_value, 50 | CASE WHEN REGEXP_CONTAINS(d.dda, 'DATA_DRIVEN') THEN TRUE ELSE FALSE END AS has_dda, 51 | CASE WHEN REGEXP_CONTAINS(o.oci, 'UPLOAD') THEN TRUE ELSE FALSE END AS has_oci 52 | FROM base b 53 | LEFT JOIN conv_value cv 54 | ON b.customer.id = cv.Customer_ID 55 | LEFT JOIN dda d 56 | ON b.customer.id = d.Customer_ID 57 | LEFT JOIN oci o 58 | ON b.customer.id = o.Customer_ID -------------------------------------------------------------------------------- /sql/adh_bi_join_lego_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | lego.*, 17 | users, 18 | day2_retention, 19 | day7_retention, 20 | day30_retention, 21 | day2_revenue, 22 | day7_revenue, 23 | day30_revenue 24 | FROM ( 25 | SELECT 26 | asset_youtube_video_asset_youtube_video_id video_id, 27 | video_title, 28 | video_duration_millis, 29 | asset_id, 30 | asset_thumbnail, 31 | campaign_app_campaign_setting_app_id, 32 | campaign_name, 33 | customer_id, 34 | customer_descriptive_name, 35 | campaign_id, 36 | campaign_app_campaign_setting_bidding_strategy_goal_type, 37 | SUM(metrics_impressions) metrics_impressions, 38 | SUM(metrics_cost) metrics_cost, 39 | SUM(metrics_conversions) metrics_conversions, 40 | SUM(metrics_clicks) metrics_clicks, 41 | SUM(metrics_all_conversions) metrics_all_conversions, 42 | SUM(metrics_all_conversions_value) metrics_all_conversions_value 43 | FROM 44 | `${legoDatasetId}.app_trd_asset_perf_report` 45 | WHERE 46 | ad_group_ad_asset_view_field_type = "YOUTUBE_VIDEO" 47 | AND segments_date BETWEEN DATE_ADD(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL (0-${dateRangeInDays}) day) 48 | AND PARSE_DATE('%Y%m%d', '${partitionDay}') 49 | GROUP BY 50 | 1, 51 | 2, 52 | 3, 53 | 4, 54 | 5, 55 | 6, 56 | 7, 57 | 8, 58 | 9, 59 | 10, 60 | 11) lego 61 | INNER JOIN 62 | `${datasetId}.adh_bi_calc_video_asset_${partitionDay}` adh 63 | USING 64 | (video_id, 65 | campaign_id) 66 | 67 | -------------------------------------------------------------------------------- /sql/nonapp_trd_user_interest.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | b.user_interest_name AS User_interest, 24 | b.user_interest_taxonomy_type AS User_interest_taxonomy, 25 | a.customer.currency_code AS Currency, 26 | a.ad_group.id AS Ad_group_id, 27 | a.ad_group.name AS Ad_group_name, 28 | a.ad_group_criterion.status AS Status, 29 | a.metrics.clicks AS Clicks, 30 | a.metrics.impressions AS Impressions, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.conversions AS Conversions, 33 | a.metrics.conversions_value AS Conv_value, 34 | a.metrics.all_conversions AS All_conversions, 35 | a.metrics.all_conversions_value AS All_conv_value 36 | FROM `${datasetId}.report_nonapp_campaign_perf_user_interest` a 37 | LEFT JOIN 38 | ( 39 | SELECT 40 | user_interest.User_interest_id AS user_interest_id, 41 | user_interest.name AS user_interest_name, 42 | user_interest.taxonomy_type AS user_interest_taxonomy_type 43 | FROM `${datasetId}.report_nonapp_user_interest` 44 | ) b 45 | ON 46 | REGEXP_EXTRACT(a.ad_group_criterion.user_interest.user_interest_category, r'[^\/]+$') 47 | = CAST(b.user_interest_id AS STRING) 48 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_bi_join_lego_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | lego.*, 17 | users, 18 | day2_retention, 19 | day7_retention, 20 | day30_retention, 21 | day2_revenue, 22 | day7_revenue, 23 | day30_revenue 24 | FROM ( 25 | SELECT 26 | asset_youtube_video_asset_youtube_video_id video_id, 27 | video_title, 28 | video_duration_millis, 29 | asset_id, 30 | asset_thumbnail, 31 | campaign_app_campaign_setting_app_id, 32 | campaign_name, 33 | customer_id, 34 | customer_descriptive_name, 35 | campaign_id, 36 | campaign_app_campaign_setting_bidding_strategy_goal_type, 37 | SUM(metrics_impressions) metrics_impressions, 38 | SUM(metrics_cost) metrics_cost, 39 | SUM(metrics_conversions) metrics_conversions, 40 | SUM(metrics_clicks) metrics_clicks, 41 | SUM(metrics_all_conversions) metrics_all_conversions, 42 | SUM(metrics_all_conversions_value) metrics_all_conversions_value 43 | FROM 44 | `${legoDatasetId}.app_trd_asset_perf_report` 45 | WHERE 46 | ad_group_ad_asset_view_field_type = "YOUTUBE_VIDEO" 47 | AND segments_date BETWEEN DATE_ADD(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL (0-${dateRangeInDays}) day) 48 | AND PARSE_DATE('%Y%m%d', '${partitionDay}') 49 | GROUP BY 50 | 1, 51 | 2, 52 | 3, 53 | 4, 54 | 5, 55 | 6, 56 | 7, 57 | 8, 58 | 9, 59 | 10, 60 | 11) lego 61 | INNER JOIN 62 | `${datasetId}.adh_bi_calc_video_asset_${partitionDay}` adh 63 | USING 64 | (video_id, 65 | campaign_id) 66 | 67 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_user_interest.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.campaign.name AS Campaign, 19 | a.campaign.id AS Campaign_ID, 20 | a.campaign.status AS Campaign_status, 21 | a.campaign.advertising_channel_type AS Campaign_type, 22 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 23 | b.user_interest_name AS User_interest, 24 | b.user_interest_taxonomy_type AS User_interest_taxonomy, 25 | a.customer.currency_code AS Currency, 26 | a.ad_group.id AS Ad_group_id, 27 | a.ad_group.name AS Ad_group_name, 28 | a.ad_group_criterion.status AS Status, 29 | a.metrics.clicks AS Clicks, 30 | a.metrics.impressions AS Impressions, 31 | a.metrics.cost_micros / 1000000 AS Cost, 32 | a.metrics.conversions AS Conversions, 33 | a.metrics.conversions_value AS Conv_value, 34 | a.metrics.all_conversions AS All_conversions, 35 | a.metrics.all_conversions_value AS All_conv_value 36 | FROM `${datasetId}.report_nonapp_campaign_perf_user_interest` a 37 | LEFT JOIN 38 | ( 39 | SELECT 40 | user_interest.User_interest_id AS user_interest_id, 41 | user_interest.name AS user_interest_name, 42 | user_interest.taxonomy_type AS user_interest_taxonomy_type 43 | FROM `${datasetId}.report_nonapp_user_interest` 44 | ) b 45 | ON 46 | REGEXP_EXTRACT(a.ad_group_criterion.user_interest.user_interest_category, r'[^\/]+$') 47 | = CAST(b.user_interest_id AS STRING) 48 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/apps_script/fx_rate_sheet.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** @fileoverview A type of data to be shown and operated in a sheet. */ 16 | 17 | 18 | /** 19 | * The sheet stores the currency exchange rate. 20 | */ 21 | class FxRateSheet extends DataTableSheet { 22 | 23 | get sheetName() { 24 | return 'fx rate'; 25 | } 26 | 27 | get columnConfiguration() { 28 | return [ 29 | { name: 'fromcur' }, 30 | { name: 'tocur' }, 31 | { name: 'rate' }, 32 | { 33 | name: COLUMN_NAME_FOR_DEFAULT_CONFIG, width: 200, 34 | format: COLUMN_STYLES.MONO_FONT, 35 | }, 36 | ]; 37 | } 38 | 39 | get datasetPropertyName() { 40 | return 'configDataset'; 41 | } 42 | 43 | get tableName() { 44 | return 'fx_rate_raw'; 45 | } 46 | 47 | get initialData() { 48 | const sources = [ 49 | 'HKD', 'TWD', 'SGD', 'MYR', 'CNY', 'AUD', 'JPY', 'INR', 'AED', 'KRW', 50 | 'CAD', 'EUR', 'GBP', 'ARS', 'KRW', 'RUB', 'VND', 'USD', 'CHF', 'GEL', 51 | 'MOP', 'PHP', 'PKR', 'TRY', 'NZD', 52 | ]; 53 | const targets = ['USD', 'AUD', 'SGD']; 54 | let index = 2; 55 | 56 | const result = []; 57 | 58 | for (let i = 0; i < targets.length; i++) { 59 | const target = targets[i]; 60 | for (let j = 0; j < sources.length; j++) { 61 | const source = sources[j]; 62 | result.push([ 63 | source, 64 | target, 65 | `=IF(A${index}=B${index}, 1, GOOGLEFINANCE("CURRENCY:"&A${index}&B${index}))` 66 | ]); 67 | index++; 68 | } 69 | } 70 | 71 | return result; 72 | } 73 | }; 74 | -------------------------------------------------------------------------------- /sql/nonapp_trd_video.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | segments.date AS Date, 17 | customer.id AS Customer_ID, 18 | video.id AS video_id, 19 | video.title AS video_title, 20 | round(video.duration_millis / 1e3, 2) AS video_duration_millis, 21 | campaign.advertising_channel_sub_type AS Campaign_type, 22 | campaign.name AS Campaign, 23 | campaign.status AS Campaign_status, 24 | customer.descriptive_name AS Account, 25 | customer.currency_code AS Currency, 26 | campaign.id AS Campaign_ID, 27 | video.channel_id AS channel_id, 28 | ad_group.id AS ad_group_id, 29 | ad_group.name AS ad_group_name, 30 | metrics.all_conversions AS metrics_all_conversions, 31 | metrics.all_conversions_value AS metrics_all_conversion_value, 32 | metrics.view_through_conversions AS metrics_view_through_conversions, 33 | metrics.impressions AS metrics_impressions, 34 | metrics.clicks AS metrics_clicks, 35 | metrics.cost_micros / 1000000 AS metrics_cost, 36 | metrics.conversions AS metrics_conversion, 37 | metrics.conversions_value AS metrics_conversions_value, 38 | metrics.video_views AS metrics_video_views, 39 | metrics.engagements AS metrics_engagemnets, 40 | metrics.video_quartile_p25_rate metrics_video_quartile_p25_rate, 41 | metrics.video_quartile_p50_rate metrics_video_quartile_p50_rate, 42 | metrics.video_quartile_p75_rate metrics_video_quartile_p75_rate, 43 | metrics.video_quartile_p100_rate metrics_video_quartile_p100_rate 44 | FROM 45 | `${datasetId}.report_base_videos` 46 | WHERE 47 | DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 48 | OR segments.date = DATE_ADD(DATE(_PARTITIONTIME), INTERVAL -31 day) -------------------------------------------------------------------------------- /sql/app_trd_placement_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.campaign_app_campaign_setting_bidding_strategy_goal_type, 17 | camp.campaign_app_campaign_setting_app_id, 18 | camp.country_code, 19 | camp.country_name, 20 | p.* 21 | FROM 22 | ( 23 | SELECT 24 | campaign.id campaign_id, 25 | campaign.name campaign_name, 26 | campaign.status campaign_status, 27 | customer.id customer_id, 28 | customer.currency_code currency, 29 | customer.descriptive_name customer_descriptive_name, 30 | campaign.advertising_channel_sub_type campaign_advertising_channel_sub_type, 31 | group_placement_view.display_name display_name, 32 | group_placement_view.placement_type placement_type, 33 | group_placement_view.target_url target_url, 34 | metrics.impressions metrics_impressions, 35 | metrics.clicks metrics_clicks, 36 | ROUND(metrics.cost_micros / 1e6, 2) metrics_cost, 37 | metrics.conversions_value metrics_conversions_value, 38 | metrics.conversions metrics_conversions, 39 | metrics.all_conversions_value metrics_all_conversions_value, 40 | metrics.all_conversions metrics_all_conversions, 41 | ROW_NUMBER() OVER (PARTITION BY campaign.id ORDER BY metrics.impressions DESC) rank 42 | FROM 43 | `${datasetId}.report_base_detail_placement_view` 44 | WHERE 45 | campaign.advertising_channel_type = "MULTI_CHANNEL" 46 | AND metrics.cost_micros > 0 47 | AND DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 48 | ) p 49 | INNER JOIN 50 | `${datasetId}.base_snd_campaigns` camp 51 | USING (campaign_id) 52 | WHERE rank < 100 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_video.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | segments.date AS Date, 17 | customer.id AS Customer_ID, 18 | video.id AS video_id, 19 | video.title AS video_title, 20 | round(video.duration_millis / 1e3, 2) AS video_duration_millis, 21 | campaign.advertising_channel_sub_type AS Campaign_type, 22 | campaign.name AS Campaign, 23 | campaign.status AS Campaign_status, 24 | customer.descriptive_name AS Account, 25 | customer.currency_code AS Currency, 26 | campaign.id AS Campaign_ID, 27 | video.channel_id AS channel_id, 28 | ad_group.id AS ad_group_id, 29 | ad_group.name AS ad_group_name, 30 | metrics.all_conversions AS metrics_all_conversions, 31 | metrics.all_conversions_value AS metrics_all_conversion_value, 32 | metrics.view_through_conversions AS metrics_view_through_conversions, 33 | metrics.impressions AS metrics_impressions, 34 | metrics.clicks AS metrics_clicks, 35 | metrics.cost_micros / 1000000 AS metrics_cost, 36 | metrics.conversions AS metrics_conversion, 37 | metrics.conversions_value AS metrics_conversions_value, 38 | metrics.video_views AS metrics_video_views, 39 | metrics.engagements AS metrics_engagemnets, 40 | metrics.video_quartile_p25_rate metrics_video_quartile_p25_rate, 41 | metrics.video_quartile_p50_rate metrics_video_quartile_p50_rate, 42 | metrics.video_quartile_p75_rate metrics_video_quartile_p75_rate, 43 | metrics.video_quartile_p100_rate metrics_video_quartile_p100_rate 44 | FROM 45 | `${datasetId}.report_base_videos` 46 | WHERE 47 | DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 48 | OR segments.date = DATE_ADD(DATE(_PARTITIONTIME), INTERVAL -31 day) -------------------------------------------------------------------------------- /sql/nonapp_trd_ads_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.customer.currency_code AS Currency, 19 | a.campaign.name AS Campaign, 20 | a.campaign.id AS Campaign_ID, 21 | a.campaign.status AS Campaign_status, 22 | a.campaign.advertising_channel_type AS Campaign_type, 23 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 24 | a.ad_group.name AS Ad_group_name, 25 | a.ad_group_ad.ad.id AS Ad_id, 26 | a.ad_group_ad.ad.name AS Ad_name, 27 | a.ad_group_ad.ad.type AS Ad_type, 28 | a.ad_group_ad.status AS Ad_status, 29 | a.ad_group_ad.ad_strength AS Ad_strength, 30 | a.ad_group_ad.ad.expanded_text_ad.headline_part1 AS Expanded_text_ad_headline_part1, 31 | a.ad_group_ad.ad.expanded_text_ad.headline_part2 AS Expanded_text_ad_headline_part2, 32 | a.ad_group_ad.ad.expanded_text_ad.path1 AS Expanded_text_ad_path1, 33 | a.ad_group_ad.ad.responsive_search_ad.path1 AS Responsive_search_ad_path1, 34 | a.ad_group_ad.ad.responsive_display_ad.long_headline.text AS Responsive_display_ad_long_headline, 35 | a.ad_group_ad.ad.text_ad.headline AS Text_ad_headline, 36 | a.ad_group_ad.ad.image_ad.image_url AS Image_ads_url, 37 | a.metrics.clicks AS Clicks, 38 | a.metrics.impressions AS Impressions, 39 | a.metrics.cost_micros / 1000000 AS Cost, 40 | a.metrics.conversions AS Conversions, 41 | a.metrics.conversions_value AS Conv_value, 42 | a.metrics.all_conversions AS All_conversions, 43 | a.metrics.all_conversions_value AS All_conv_value, 44 | FROM `${datasetId}.report_nonapp_campaign_perf_all_ad` a 45 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_placement_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.campaign_app_campaign_setting_bidding_strategy_goal_type, 17 | camp.campaign_app_campaign_setting_app_id, 18 | camp.country_code, 19 | camp.country_name, 20 | p.* 21 | FROM 22 | ( 23 | SELECT 24 | campaign.id campaign_id, 25 | campaign.name campaign_name, 26 | campaign.status campaign_status, 27 | customer.id customer_id, 28 | customer.currency_code currency, 29 | customer.descriptive_name customer_descriptive_name, 30 | campaign.advertising_channel_sub_type campaign_advertising_channel_sub_type, 31 | group_placement_view.display_name display_name, 32 | group_placement_view.placement_type placement_type, 33 | group_placement_view.target_url target_url, 34 | metrics.impressions metrics_impressions, 35 | metrics.clicks metrics_clicks, 36 | ROUND(metrics.cost_micros / 1e6, 2) metrics_cost, 37 | metrics.conversions_value metrics_conversions_value, 38 | metrics.conversions metrics_conversions, 39 | metrics.all_conversions_value metrics_all_conversions_value, 40 | metrics.all_conversions metrics_all_conversions, 41 | ROW_NUMBER() OVER (PARTITION BY campaign.id ORDER BY metrics.impressions DESC) rank 42 | FROM 43 | `${datasetId}.report_base_detail_placement_view` 44 | WHERE 45 | campaign.advertising_channel_type = "MULTI_CHANNEL" 46 | AND metrics.cost_micros > 0 47 | AND DATE(_partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') 48 | ) p 49 | INNER JOIN 50 | `${datasetId}.base_snd_campaigns` camp 51 | USING (campaign_id) 52 | WHERE rank < 100 -------------------------------------------------------------------------------- /config/workflow_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "download_mcc_reports_impl": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": [ 6 | "base_geo_target_constant", 7 | "base_language_constant", 8 | "base_labels" 9 | ] 10 | } 11 | }, 12 | "download_reports_impl": { 13 | "type": "knot", 14 | "embedded": { 15 | "dueTime": 40, 16 | "tasks": [ 17 | "base_account_budget", 18 | "base_account_change_event", 19 | "base_campaign_ads_approval", 20 | "base_campaign_conversion", 21 | "base_campaign_criterion", 22 | "base_campaign_performance", 23 | "base_campaigns", 24 | "base_customer_label", 25 | "base_detail_placement_view", 26 | "base_geographic_view", 27 | "base_videos", 28 | "app_conversion_action", 29 | "app_asset_performance", 30 | "app_geo_conversion", 31 | "app_disapprovals_ad_group_ad_asset_view", 32 | "app_ad_group", 33 | "app_ad_group_perf", 34 | "app_asset_metadata", 35 | "app_recommendations", 36 | "app_skan" 37 | ] 38 | }, 39 | "errorOptions": { 40 | "ignoreError": true 41 | } 42 | }, 43 | "load_reports_impl": { 44 | "type": "knot", 45 | "embedded": { 46 | "tasks": [ 47 | "baselite_load_reports", 48 | "base_load_reports", 49 | "app_load_reports" 50 | ] 51 | } 52 | }, 53 | "trigger_snd_query_impl": { 54 | "type": "knot", 55 | "embedded": { 56 | "tasks": ["base_snd_query", "app_snd_query"] 57 | }, 58 | "next": "trigger_trd_query_impl" 59 | }, 60 | "trigger_trd_query_impl": { 61 | "type": "knot", 62 | "embedded": { 63 | "tasks": ["app_trd_query"] 64 | }, 65 | "next": "trigger_fourth_query_impl" 66 | }, 67 | "trigger_fourth_query_impl": { 68 | "type": "knot", 69 | "appendedParameters": { 70 | "markTaskId": "mark_label" 71 | }, 72 | "embedded": { 73 | "tasks": ["app_fourth_query"] 74 | }, 75 | "next": "trigger_customized_task" 76 | }, 77 | "trigger_mark_email_impl": { 78 | "type": "knot", 79 | "appendedParameters": { 80 | "markTaskId": "mark_email" 81 | }, 82 | "embedded": { 83 | "tasks": ["app_fourth_query"] 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_ads_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer.descriptive_name AS Account, 17 | a.customer.id AS Customer_ID, 18 | a.customer.currency_code AS Currency, 19 | a.campaign.name AS Campaign, 20 | a.campaign.id AS Campaign_ID, 21 | a.campaign.status AS Campaign_status, 22 | a.campaign.advertising_channel_type AS Campaign_type, 23 | a.campaign.advertising_channel_sub_type AS Campaign_sub_type, 24 | a.ad_group.name AS Ad_group_name, 25 | a.ad_group_ad.ad.id AS Ad_id, 26 | a.ad_group_ad.ad.name AS Ad_name, 27 | a.ad_group_ad.ad.type AS Ad_type, 28 | a.ad_group_ad.status AS Ad_status, 29 | a.ad_group_ad.ad_strength AS Ad_strength, 30 | a.ad_group_ad.ad.expanded_text_ad.headline_part1 AS Expanded_text_ad_headline_part1, 31 | a.ad_group_ad.ad.expanded_text_ad.headline_part2 AS Expanded_text_ad_headline_part2, 32 | a.ad_group_ad.ad.expanded_text_ad.path1 AS Expanded_text_ad_path1, 33 | a.ad_group_ad.ad.responsive_search_ad.path1 AS Responsive_search_ad_path1, 34 | a.ad_group_ad.ad.responsive_display_ad.long_headline.text AS Responsive_display_ad_long_headline, 35 | a.ad_group_ad.ad.text_ad.headline AS Text_ad_headline, 36 | a.ad_group_ad.ad.image_ad.image_url AS Image_ads_url, 37 | a.metrics.clicks AS Clicks, 38 | a.metrics.impressions AS Impressions, 39 | a.metrics.cost_micros / 1000000 AS Cost, 40 | a.metrics.conversions AS Conversions, 41 | a.metrics.conversions_value AS Conv_value, 42 | a.metrics.all_conversions AS All_conversions, 43 | a.metrics.all_conversions_value AS All_conv_value, 44 | FROM `${datasetId}.report_nonapp_campaign_perf_all_ad` a 45 | WHERE DATE(a._partitionTime) = PARSE_DATE('%Y%m%d', '${partitionDay}') -------------------------------------------------------------------------------- /sql/app_trd_recommendations.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | camp.*, 17 | metrics.optimization_score_uplift optimization_score_uplift, 18 | metrics.optimization_score_url optimization_score_url 19 | FROM 20 | `${datasetId}.report_app_recommendations` r 21 | INNER JOIN 22 | ( 23 | SELECT 24 | campaign.id campaign_id, 25 | MAX(_PARTITIONTIME) PARTITIONTIME 26 | FROM 27 | `${datasetId}.report_app_recommendations` 28 | WHERE 29 | metrics.optimization_score_uplift IS NOT NULL 30 | GROUP BY 31 | 1 32 | ) rec 33 | ON 34 | r.campaign.id = rec.campaign_id 35 | AND r._PARTITIONTIME = rec.PARTITIONTIME 36 | INNER JOIN 37 | ( 38 | SELECT 39 | customer_descriptive_name, 40 | customer_id, 41 | currency, 42 | campaign_id, 43 | advertising_channel_sub_type, 44 | advertising_channel_type, 45 | campaign_name, 46 | campaign_status, 47 | campaign_bidding_strategy_type, 48 | campaign_app_campaign_setting_app_id, 49 | campaign_app_campaign_setting_app_store, 50 | campaign_app_campaign_setting_bidding_strategy_goal_type, 51 | language_code, 52 | country_code, 53 | campaign_budget_amount, 54 | campaign_target_roas_target_roas, 55 | campaign_target_cpa_target_cpa, 56 | campaign_optimization_score, 57 | FROM 58 | `${datasetId}.base_snd_campaigns` 59 | INNER JOIN 60 | ( 61 | SELECT 62 | campaign_id, 63 | MAX(segments_date) segments_date 64 | FROM 65 | `${datasetId}.base_snd_campaigns` 66 | GROUP BY 67 | 1 68 | ) 69 | USING ( 70 | campaign_id, 71 | segments_date) 72 | ) camp 73 | USING (campaign_id) -------------------------------------------------------------------------------- /sql/adh_pure_join_lego_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | lego.*, 17 | installs, 18 | cost_usd, 19 | targeted_users, 20 | impressions, 21 | clicks, 22 | FROM ( 23 | SELECT 24 | asset_youtube_video_asset_youtube_video_id video_id, 25 | video_title, 26 | video_duration_millis, 27 | asset_id, 28 | asset_thumbnail, 29 | campaign_app_campaign_setting_app_id, 30 | campaign_name, 31 | customer_id, 32 | customer_descriptive_name, 33 | campaign_id, 34 | campaign_app_campaign_setting_bidding_strategy_goal_type, 35 | SUM(metrics_impressions) metrics_impressions, 36 | SUM(metrics_cost) metrics_cost, 37 | SUM(metrics_conversions) metrics_conversions, 38 | SUM(metrics_clicks) metrics_clicks, 39 | SUM(metrics_all_conversions) metrics_all_conversions, 40 | SUM(metrics_all_conversions_value) metrics_all_conversions_value 41 | FROM 42 | `${legoDatasetId}.app_trd_asset_perf_report` 43 | WHERE 44 | ad_group_ad_asset_view_field_type = "YOUTUBE_VIDEO" 45 | AND segments_date BETWEEN DATE_ADD(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL (0-${dateRangeInDays}) day) 46 | AND PARSE_DATE('%Y%m%d', '${partitionDay}') 47 | GROUP BY 48 | 1, 49 | 2, 50 | 3, 51 | 4, 52 | 5, 53 | 6, 54 | 7, 55 | 8, 56 | 9, 57 | 10, 58 | 11) lego 59 | INNER JOIN 60 | (SELECT 61 | campaign_id, 62 | video_id, 63 | SUM(installs) AS installs, 64 | SUM(cost_usd) AS cost_usd, 65 | SUM(targeted_users) AS targeted_users, 66 | SUM(impressions) AS impressions, 67 | SUM(clicks) AS clicks 68 | FROM 69 | `${datasetId}.adh_pure_calc_asset_demo_${partitionDay}` 70 | GROUP BY 1,2 71 | ) adh 72 | USING 73 | (video_id, 74 | campaign_id) 75 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_recommendations.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | camp.*, 17 | metrics.optimization_score_uplift optimization_score_uplift, 18 | metrics.optimization_score_url optimization_score_url 19 | FROM 20 | `${datasetId}.report_app_recommendations` r 21 | INNER JOIN 22 | ( 23 | SELECT 24 | campaign.id campaign_id, 25 | MAX(_PARTITIONTIME) PARTITIONTIME 26 | FROM 27 | `${datasetId}.report_app_recommendations` 28 | WHERE 29 | metrics.optimization_score_uplift IS NOT NULL 30 | GROUP BY 31 | 1 32 | ) rec 33 | ON 34 | r.campaign.id = rec.campaign_id 35 | AND r._PARTITIONTIME = rec.PARTITIONTIME 36 | INNER JOIN 37 | ( 38 | SELECT 39 | customer_descriptive_name, 40 | customer_id, 41 | currency, 42 | campaign_id, 43 | advertising_channel_sub_type, 44 | advertising_channel_type, 45 | campaign_name, 46 | campaign_status, 47 | campaign_bidding_strategy_type, 48 | campaign_app_campaign_setting_app_id, 49 | campaign_app_campaign_setting_app_store, 50 | campaign_app_campaign_setting_bidding_strategy_goal_type, 51 | language_code, 52 | country_code, 53 | campaign_budget_amount, 54 | campaign_target_roas_target_roas, 55 | campaign_target_cpa_target_cpa, 56 | campaign_optimization_score, 57 | FROM 58 | `${datasetId}.base_snd_campaigns` 59 | INNER JOIN 60 | ( 61 | SELECT 62 | campaign_id, 63 | MAX(segments_date) segments_date 64 | FROM 65 | `${datasetId}.base_snd_campaigns` 66 | GROUP BY 67 | 1 68 | ) 69 | USING ( 70 | campaign_id, 71 | segments_date) 72 | ) camp 73 | USING (campaign_id) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_pure_join_lego_perf.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | lego.*, 17 | installs, 18 | cost_usd, 19 | targeted_users, 20 | impressions, 21 | clicks, 22 | FROM ( 23 | SELECT 24 | asset_youtube_video_asset_youtube_video_id video_id, 25 | video_title, 26 | video_duration_millis, 27 | asset_id, 28 | asset_thumbnail, 29 | campaign_app_campaign_setting_app_id, 30 | campaign_name, 31 | customer_id, 32 | customer_descriptive_name, 33 | campaign_id, 34 | campaign_app_campaign_setting_bidding_strategy_goal_type, 35 | SUM(metrics_impressions) metrics_impressions, 36 | SUM(metrics_cost) metrics_cost, 37 | SUM(metrics_conversions) metrics_conversions, 38 | SUM(metrics_clicks) metrics_clicks, 39 | SUM(metrics_all_conversions) metrics_all_conversions, 40 | SUM(metrics_all_conversions_value) metrics_all_conversions_value 41 | FROM 42 | `${legoDatasetId}.app_trd_asset_perf_report` 43 | WHERE 44 | ad_group_ad_asset_view_field_type = "YOUTUBE_VIDEO" 45 | AND segments_date BETWEEN DATE_ADD(PARSE_DATE('%Y%m%d', '${partitionDay}'), INTERVAL (0-${dateRangeInDays}) day) 46 | AND PARSE_DATE('%Y%m%d', '${partitionDay}') 47 | GROUP BY 48 | 1, 49 | 2, 50 | 3, 51 | 4, 52 | 5, 53 | 6, 54 | 7, 55 | 8, 56 | 9, 57 | 10, 58 | 11) lego 59 | INNER JOIN 60 | (SELECT 61 | campaign_id, 62 | video_id, 63 | SUM(installs) AS installs, 64 | SUM(cost_usd) AS cost_usd, 65 | SUM(targeted_users) AS targeted_users, 66 | SUM(impressions) AS impressions, 67 | SUM(clicks) AS clicks 68 | FROM 69 | `${datasetId}.adh_pure_calc_asset_demo_${partitionDay}` 70 | GROUP BY 1,2 71 | ) adh 72 | USING 73 | (video_id, 74 | campaign_id) 75 | -------------------------------------------------------------------------------- /config/workflow_app_nonapplite.json: -------------------------------------------------------------------------------- 1 | { 2 | "download_mcc_reports_impl": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": [ 6 | "base_geo_target_constant", 7 | "base_language_constant", 8 | "base_labels" 9 | ] 10 | } 11 | }, 12 | "download_reports_impl": { 13 | "type": "knot", 14 | "embedded": { 15 | "dueTime": 40, 16 | "tasks": [ 17 | "base_account_budget", 18 | "base_account_change_event", 19 | "base_campaign_ads_approval", 20 | "base_campaign_conversion", 21 | "base_campaign_criterion", 22 | "base_campaign_performance", 23 | "base_campaigns", 24 | "base_customer_label", 25 | "base_detail_placement_view", 26 | "base_geographic_view", 27 | "base_videos", 28 | "app_conversion_action", 29 | "app_asset_performance", 30 | "app_geo_conversion", 31 | "app_disapprovals_ad_group_ad_asset_view", 32 | "app_ad_group", 33 | "app_ad_group_perf", 34 | "app_asset_metadata", 35 | "app_recommendations", 36 | "app_skan" 37 | ] 38 | }, 39 | "errorOptions": { 40 | "ignoreError": true 41 | } 42 | }, 43 | "load_reports_impl": { 44 | "type": "knot", 45 | "embedded": { 46 | "tasks": [ 47 | "baselite_load_reports", 48 | "base_load_reports", 49 | "app_load_reports" 50 | ] 51 | } 52 | }, 53 | "trigger_snd_query_impl": { 54 | "type": "knot", 55 | "embedded": { 56 | "tasks": ["base_snd_query", "app_snd_query", "nonapp_snd_query"] 57 | }, 58 | "next": "trigger_trd_query_impl" 59 | }, 60 | "trigger_trd_query_impl": { 61 | "type": "knot", 62 | "embedded": { 63 | "tasks": ["app_trd_query", "nonapplite_trd_query"] 64 | }, 65 | "next": "trigger_fourth_query_impl" 66 | }, 67 | "trigger_fourth_query_impl": { 68 | "type": "knot", 69 | "appendedParameters": { 70 | "markTaskId": "mark_label" 71 | }, 72 | "embedded": { 73 | "tasks": ["app_fourth_query", "nonapplite_fourth_query"] 74 | }, 75 | "next": "trigger_customized_task" 76 | }, 77 | "trigger_mark_email_impl": { 78 | "type": "knot", 79 | "appendedParameters": { 80 | "markTaskId": "mark_email" 81 | }, 82 | "embedded": { 83 | "tasks": ["app_fourth_query", "nonapplite_fourth_query"] 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sql/app_trd_geo_perf_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.*, 17 | geo_target_constant_canonical_name, 18 | IFNULL(conv.installs, 0) installs, 19 | IFNULL(conv.in_app_actions, 0) in_app_actions, 20 | segments_ad_network_type segments_ad_network_type, 21 | metrics_clicks, 22 | metrics_conversions_value, 23 | metrics_impressions, 24 | metrics_conversions, 25 | metrics_cost 26 | FROM `${datasetId}.base_snd_geo_perf_report` 27 | LEFT JOIN 28 | ( 29 | SELECT 30 | campaign.id campaign_id, 31 | segments.week segments_week, 32 | segments.ad_network_type segments_ad_network_type, 33 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 34 | SUM( 35 | IF( 36 | segments.conversion_action_category = "DOWNLOAD", 37 | metrics.conversions, 38 | 0)) 39 | installs, 40 | SUM( 41 | IF( 42 | segments.conversion_action_category != "DOWNLOAD", 43 | metrics.conversions, 44 | 0)) 45 | in_app_actions 46 | FROM `${datasetId}.report_app_geo_conversion` r 47 | INNER JOIN 48 | ( 49 | SELECT 50 | campaign.id campaign_id, 51 | segments.week segments_week, 52 | MAX(DATE(_partitionTime)) partitionTime 53 | FROM 54 | `${datasetId}.report_app_geo_conversion` 55 | GROUP BY 56 | 1, 57 | 2 58 | ) t 59 | ON 60 | t.partitionTime = DATE(r._partitionTime) 61 | AND t.campaign_id = r.campaign.id 62 | AND t.segments_week = r.segments.week 63 | GROUP BY 1, 2, 3, 4 64 | ) conv 65 | USING (campaign_id, segments_week, geographic_view_country_criterion_id, segments_ad_network_type) 66 | INNER JOIN `${datasetId}.base_snd_campaigns` camp 67 | USING (campaign_id, segments_week) 68 | WHERE camp.segments_date = camp.segments_week -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_geo_perf_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | camp.*, 17 | geo_target_constant_canonical_name, 18 | IFNULL(conv.installs, 0) installs, 19 | IFNULL(conv.in_app_actions, 0) in_app_actions, 20 | segments_ad_network_type segments_ad_network_type, 21 | metrics_clicks, 22 | metrics_conversions_value, 23 | metrics_impressions, 24 | metrics_conversions, 25 | metrics_cost 26 | FROM `${datasetId}.base_snd_geo_perf_report` 27 | LEFT JOIN 28 | ( 29 | SELECT 30 | campaign.id campaign_id, 31 | segments.week segments_week, 32 | segments.ad_network_type segments_ad_network_type, 33 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 34 | SUM( 35 | IF( 36 | segments.conversion_action_category = "DOWNLOAD", 37 | metrics.conversions, 38 | 0)) 39 | installs, 40 | SUM( 41 | IF( 42 | segments.conversion_action_category != "DOWNLOAD", 43 | metrics.conversions, 44 | 0)) 45 | in_app_actions 46 | FROM `${datasetId}.report_app_geo_conversion` r 47 | INNER JOIN 48 | ( 49 | SELECT 50 | campaign.id campaign_id, 51 | segments.week segments_week, 52 | MAX(DATE(_partitionTime)) partitionTime 53 | FROM 54 | `${datasetId}.report_app_geo_conversion` 55 | GROUP BY 56 | 1, 57 | 2 58 | ) t 59 | ON 60 | t.partitionTime = DATE(r._partitionTime) 61 | AND t.campaign_id = r.campaign.id 62 | AND t.segments_week = r.segments.week 63 | GROUP BY 1, 2, 3, 4 64 | ) conv 65 | USING (campaign_id, segments_week, geographic_view_country_criterion_id, segments_ad_network_type) 66 | INNER JOIN `${datasetId}.base_snd_campaigns` camp 67 | USING (campaign_id, segments_week) 68 | WHERE camp.segments_date = camp.segments_week -------------------------------------------------------------------------------- /sql/app_trd_geo_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | campaign_id, 17 | campaign_name, 18 | campaign_status, 19 | campaign_app_campaign_setting_app_id, 20 | campaign_app_campaign_setting_bidding_strategy_goal_type, 21 | customer_id, 22 | customer_descriptive_name, 23 | conv.segments_week, 24 | segments_conversion_action_name, 25 | conv.geographic_view_country_criterion_id, 26 | geo_target_constant_canonical_name, 27 | metrics_conversions_value, 28 | metrics_conversions, 29 | metrics_all_conversions_value, 30 | metrics_all_conversions 31 | FROM 32 | ( 33 | SELECT 34 | campaign.id campaign_id, 35 | segments.week segments_week, 36 | segments.conversion_action_name segments_conversion_action_name, 37 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 38 | IFNULL(SUM(metrics.conversions_value), 0) metrics_conversions_value, 39 | IFNULL(SUM(metrics.conversions), 0) metrics_conversions, 40 | IFNULL(SUM(metrics.all_conversions_value), 0) metrics_all_conversions_value, 41 | IFNULL(SUM(metrics.all_conversions), 0) metrics_all_conversions 42 | FROM `${datasetId}.report_app_geo_conversion` r 43 | INNER JOIN 44 | ( 45 | SELECT 46 | campaign.id campaign_id, 47 | segments.week segments_week, 48 | MAX(DATE(_partitionTime)) partitionTime 49 | FROM 50 | `${datasetId}.report_app_geo_conversion` 51 | GROUP BY 52 | 1, 53 | 2 54 | ) t 55 | ON 56 | t.partitionTime = DATE(r._partitionTime) 57 | AND t.campaign_id = r.campaign.id 58 | AND t.segments_week = r.segments.week 59 | GROUP BY 1, 2, 3, 4 60 | ) conv 61 | INNER JOIN 62 | ( 63 | SELECT DISTINCT 64 | geo_target_constant.id geographic_view_country_criterion_id, 65 | geo_target_constant.canonical_name geo_target_constant_canonical_name 66 | FROM `${datasetId}.report_base_geo_target_constant` 67 | ) c 68 | USING (geographic_view_country_criterion_id) 69 | INNER JOIN `${datasetId}.base_snd_campaigns` camp 70 | USING (campaign_id, segments_week) -------------------------------------------------------------------------------- /sql/adh_bi_calc_video_asset.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE user_last_impr AS ( 16 | SELECT 17 | * 18 | FROM 19 | ( 20 | SELECT 21 | UPPER(impr.device_id_md5) AS device_id, 22 | impr.campaign_id, 23 | b.app_id, 24 | camp.campaign_name AS campaign_name, 25 | inventory_type AS inventory, 26 | creative.video_message.youtube_video_id AS video_id, 27 | creative.video_message.video_ad_duration AS video_ad_duration, 28 | ## 29 | query_id.time_usec AS query_time, 30 | ROW_NUMBER() 31 | OVER ( 32 | PARTITION BY impr.device_id_md5, b.app_id 33 | ORDER BY query_id.time_usec DESC 34 | ) AS rank 35 | FROM 36 | adh.google_ads_impressions_rdid impr 37 | LEFT JOIN adh.google_ads_adgroupcreative USING(ad_group_creative_id) 38 | LEFT JOIN adh.google_ads_creative AS creative USING (creative_id) 39 | LEFT JOIN adh.google_ads_campaign camp USING(campaign_id) 40 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 41 | ON b.campaign_id = impr.campaign_id 42 | WHERE 43 | creative.video_message.youtube_video_id IS NOT NULL 44 | AND device_id_md5 IS NOT NULL 45 | ) 46 | WHERE rank = 1 47 | ); 48 | 49 | SELECT 50 | base.video_id, 51 | base.campaign_id, 52 | base.campaign_name, 53 | base.app_id, 54 | base.inventory, 55 | COUNT(distinct device_id) AS users, 56 | SUM( 57 | IFNULL(day2_retention, 0) 58 | ) AS day2_retention, 59 | SUM( 60 | IFNULL(day7_retention, 0) 61 | ) AS day7_retention, 62 | SUM( 63 | IFNULL(day30_retention, 0) 64 | ) AS day30_retention, 65 | SUM( 66 | IFNULL(day2_revenue, 0) 67 | ) AS day2_revenue, 68 | SUM( 69 | IFNULL(day7_revenue, 0) 70 | ) AS day7_revenue, 71 | SUM( 72 | IFNULL(day30_revenue, 0) 73 | ) AS day30_revenue 74 | FROM 75 | tmp.user_last_impr base 76 | INNER JOIN tmp.bi USING (device_id,app_id) 77 | WHERE 78 | ## 79 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 80 | GROUP BY 81 | 1, 82 | 2, 83 | 3, 84 | 4,5 85 | ; -------------------------------------------------------------------------------- /config/workflow_nonapp.json: -------------------------------------------------------------------------------- 1 | { 2 | "download_mcc_reports_impl": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": [ 6 | "base_geo_target_constant", 7 | "base_language_constant", 8 | "base_labels", 9 | "nonapp_user_interest" 10 | ] 11 | } 12 | }, 13 | "download_reports_impl": { 14 | "type": "knot", 15 | "embedded": { 16 | "dueTime": 40, 17 | "tasks": [ 18 | "base_account_budget", 19 | "base_account_change_event", 20 | "base_campaign_ads_approval", 21 | "base_campaign_conversion", 22 | "base_campaign_criterion", 23 | "base_campaign_performance", 24 | "base_campaigns", 25 | "base_customer_label", 26 | "base_detail_placement_view", 27 | "base_geographic_view", 28 | "base_videos", 29 | "nonapp_campaign_perf_age_range", 30 | "nonapp_campaign_perf_all_ad", 31 | "nonapp_campaign_perf_all_audience", 32 | "nonapp_campaign_perf_all_feed_item", 33 | "nonapp_campaign_perf_all_time", 34 | "nonapp_campaign_perf_dsa", 35 | "nonapp_campaign_perf_gender", 36 | "nonapp_campaign_perf_search_extensions", 37 | "nonapp_campaign_perf_search_keywords", 38 | "nonapp_campaign_perf_search_search_term", 39 | "nonapp_campaign_perf_user_interest", 40 | "nonapp_user_lists", 41 | "nonapp_pmax_assetgroup", 42 | "nonapp_pmax_conversion" 43 | ] 44 | }, 45 | "errorOptions": { 46 | "ignoreError": true 47 | } 48 | }, 49 | "load_reports_impl": { 50 | "type": "knot", 51 | "embedded": { 52 | "tasks": [ 53 | "baselite_load_reports", 54 | "base_load_reports", 55 | "nonapp_load_reports" 56 | ] 57 | } 58 | }, 59 | "trigger_snd_query_impl": { 60 | "type": "knot", 61 | "embedded": { 62 | "tasks": ["base_snd_query", "nonapp_snd_query"] 63 | }, 64 | "next": "trigger_trd_query_impl" 65 | }, 66 | "trigger_trd_query_impl": { 67 | "type": "knot", 68 | "embedded": { 69 | "tasks": ["nonapplite_trd_query", "nonapp_trd_query"] 70 | }, 71 | "next": "trigger_fourth_query_impl" 72 | }, 73 | "trigger_fourth_query_impl": { 74 | "type": "knot", 75 | "appendedParameters": { 76 | "markTaskId": "mark_label" 77 | }, 78 | "embedded": { 79 | "tasks": ["nonapplite_fourth_query", "nonapp_fourth_query"] 80 | }, 81 | "next": "trigger_customized_task" 82 | }, 83 | "trigger_mark_email_impl": { 84 | "type": "knot", 85 | "appendedParameters": { 86 | "markTaskId": "mark_email" 87 | }, 88 | "embedded": { 89 | "tasks": ["nonapplite_fourth_query", "nonapp_fourth_query"] 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_trd_geo_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | campaign_id, 17 | campaign_name, 18 | campaign_status, 19 | campaign_app_campaign_setting_app_id, 20 | campaign_app_campaign_setting_bidding_strategy_goal_type, 21 | customer_id, 22 | customer_descriptive_name, 23 | conv.segments_week, 24 | segments_conversion_action_name, 25 | conv.geographic_view_country_criterion_id, 26 | geo_target_constant_canonical_name, 27 | metrics_conversions_value, 28 | metrics_conversions, 29 | metrics_all_conversions_value, 30 | metrics_all_conversions 31 | FROM 32 | ( 33 | SELECT 34 | campaign.id campaign_id, 35 | segments.week segments_week, 36 | segments.conversion_action_name segments_conversion_action_name, 37 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 38 | IFNULL(SUM(metrics.conversions_value), 0) metrics_conversions_value, 39 | IFNULL(SUM(metrics.conversions), 0) metrics_conversions, 40 | IFNULL(SUM(metrics.all_conversions_value), 0) metrics_all_conversions_value, 41 | IFNULL(SUM(metrics.all_conversions), 0) metrics_all_conversions 42 | FROM `${datasetId}.report_app_geo_conversion` r 43 | INNER JOIN 44 | ( 45 | SELECT 46 | campaign.id campaign_id, 47 | segments.week segments_week, 48 | MAX(DATE(_partitionTime)) partitionTime 49 | FROM 50 | `${datasetId}.report_app_geo_conversion` 51 | GROUP BY 52 | 1, 53 | 2 54 | ) t 55 | ON 56 | t.partitionTime = DATE(r._partitionTime) 57 | AND t.campaign_id = r.campaign.id 58 | AND t.segments_week = r.segments.week 59 | GROUP BY 1, 2, 3, 4 60 | ) conv 61 | INNER JOIN 62 | ( 63 | SELECT DISTINCT 64 | geo_target_constant.id geographic_view_country_criterion_id, 65 | geo_target_constant.canonical_name geo_target_constant_canonical_name 66 | FROM `${datasetId}.report_base_geo_target_constant` 67 | ) c 68 | USING (geographic_view_country_criterion_id) 69 | INNER JOIN `${datasetId}.base_snd_campaigns` camp 70 | USING (campaign_id, segments_week) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_bi_calc_video_asset.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE user_last_impr AS ( 16 | SELECT 17 | * 18 | FROM 19 | ( 20 | SELECT 21 | UPPER(impr.device_id_md5) AS device_id, 22 | impr.campaign_id, 23 | b.app_id, 24 | camp.campaign_name AS campaign_name, 25 | inventory_type AS inventory, 26 | creative.video_message.youtube_video_id AS video_id, 27 | creative.video_message.video_ad_duration AS video_ad_duration, 28 | ## 29 | query_id.time_usec AS query_time, 30 | ROW_NUMBER() 31 | OVER ( 32 | PARTITION BY impr.device_id_md5, b.app_id 33 | ORDER BY query_id.time_usec DESC 34 | ) AS rank 35 | FROM 36 | adh.google_ads_impressions_rdid impr 37 | LEFT JOIN adh.google_ads_adgroupcreative USING(ad_group_creative_id) 38 | LEFT JOIN adh.google_ads_creative AS creative USING (creative_id) 39 | LEFT JOIN adh.google_ads_campaign camp USING(campaign_id) 40 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 41 | ON b.campaign_id = impr.campaign_id 42 | WHERE 43 | creative.video_message.youtube_video_id IS NOT NULL 44 | AND device_id_md5 IS NOT NULL 45 | ) 46 | WHERE rank = 1 47 | ); 48 | 49 | SELECT 50 | base.video_id, 51 | base.campaign_id, 52 | base.campaign_name, 53 | base.app_id, 54 | base.inventory, 55 | COUNT(distinct device_id) AS users, 56 | SUM( 57 | IFNULL(day2_retention, 0) 58 | ) AS day2_retention, 59 | SUM( 60 | IFNULL(day7_retention, 0) 61 | ) AS day7_retention, 62 | SUM( 63 | IFNULL(day30_retention, 0) 64 | ) AS day30_retention, 65 | SUM( 66 | IFNULL(day2_revenue, 0) 67 | ) AS day2_revenue, 68 | SUM( 69 | IFNULL(day7_revenue, 0) 70 | ) AS day7_revenue, 71 | SUM( 72 | IFNULL(day30_revenue, 0) 73 | ) AS day30_revenue 74 | FROM 75 | tmp.user_last_impr base 76 | INNER JOIN tmp.bi USING (device_id,app_id) 77 | WHERE 78 | ## 79 | UNIX_MICROS(TIMESTAMP(install_date)) >= query_time 80 | GROUP BY 81 | 1, 82 | 2, 83 | 3, 84 | 4,5 85 | ; -------------------------------------------------------------------------------- /sql/adh_branding_reach_frequency.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE impressions AS ( 16 | SELECT user_id, campaign_id, count(*) as freq, sum(advertiser_impression_cost_usd) as imp_cost 17 | FROM adh.google_ads_impressions 18 | WHERE user_id IS NOT NULL 19 | AND (CAST(campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 20 | GROUP BY 1 ,2 21 | ); 22 | CREATE TABLE clicks AS ( 23 | SELECT 24 | user_id, 25 | impression_data.campaign_id, 26 | SUM(advertiser_click_cost_usd) AS cost, 27 | COUNT(click_id.time_usec) AS clks 28 | FROM 29 | adh.google_ads_clicks 30 | WHERE user_id IS NOT NULL 31 | AND 32 | (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 33 | GROUP BY 1,2 34 | ); 35 | CREATE TABLE conversions AS ( 36 | SELECT 37 | user_id, 38 | impression_data.campaign_id, 39 | count(conversion_id.time_usec) AS convs 40 | FROM 41 | adh.google_ads_conversions 42 | WHERE user_id IS NOT NULL 43 | AND CAST(conversion_type AS STRING) IN UNNEST(SPLIT("${conversionId}")) 44 | AND 45 | (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 46 | GROUP BY 1,2 47 | ); 48 | SELECT 49 | "${analysisName}" AS analysisName, 50 | imp.campaign_id, 51 | t.campaign_name, 52 | imp.freq, 53 | sum(imp.freq) AS impression, 54 | count(distinct imp.user_id) AS unique_reach, 55 | sum(ck.cost) AS clk_cost, 56 | sum(imp.imp_cost) AS imp_cost, 57 | sum(IFNULL(ck.cost,0)+IFNULL(imp.imp_cost,0)) AS total_cost, 58 | sum(ck.clks) AS click, 59 | sum(conv.convs) AS conversion 60 | FROM 61 | tmp.impressions imp 62 | LEFT JOIN 63 | adh.google_ads_campaign t ON imp.campaign_id = t.campaign_id 64 | LEFT JOIN 65 | tmp.clicks ck ON imp.user_id = ck.user_id AND imp.campaign_id = ck.campaign_id 66 | LEFT JOIN 67 | tmp.conversions conv ON imp.user_id = conv.user_id AND imp.campaign_id = conv.campaign_id 68 | GROUP BY 69 | 1,2,3,4 70 | ORDER BY 71 | freq ASC -------------------------------------------------------------------------------- /config/config_api.json: -------------------------------------------------------------------------------- 1 | { 2 | "PB": { 3 | "lego": { 4 | "qps": 1, 5 | "topic": "#PROJECT_NAMESPACE#-monitor", 6 | "message": { 7 | "customerId": "${customerId}", 8 | "loginCustomerId": "${loginCustomerId}", 9 | "developerToken": "${developerToken}", 10 | "partitionDay": "${partitionDay}", 11 | "fromDate": "${fromDate}" 12 | }, 13 | "attributes": { 14 | "taskId": "${taskId}", 15 | "multipleTag": "${multipleTag}" 16 | } 17 | }, 18 | "mcc": { 19 | "qps": 5, 20 | "topic": "#PROJECT_NAMESPACE#-monitor", 21 | "message": { 22 | "timezone": "${timezone}", 23 | "partitionDay": "${partitionDay}", 24 | "fromDate": "${fromDate}", 25 | "datasetId": "${datasetId}", 26 | "mccCid": "${mccCid}", 27 | "developerToken": "${developerToken}" 28 | }, 29 | "attributes": { 30 | "taskId": "${taskId}", 31 | "multipleTag": "${multipleTag}" 32 | } 33 | }, 34 | "account": { 35 | "qps": 20, 36 | "numberOfThreads": 10, 37 | "topic": "#PROJECT_NAMESPACE#-monitor", 38 | "message": { 39 | "customerId": "${customer_client.id}", 40 | "loginCustomerId": "${mccCid}", 41 | "developerToken": "${developerToken}", 42 | "partitionDay": "${partitionDay}", 43 | "fromDate": "${fromDate}" 44 | }, 45 | "attributes": { 46 | "taskId": "${taskId}", 47 | "multipleTag": "${multipleTag}" 48 | } 49 | }, 50 | "adh": { 51 | "qps": 1, 52 | "topic": "#PROJECT_NAMESPACE#-monitor", 53 | "message": { 54 | "adhDatasetId": "${adhDatasetId}", 55 | "endDate": "${endDate}", 56 | "dateRangeInDays": "${dateRangeInDays}", 57 | "adhCustomerId": "${adhCustomerId}", 58 | "analysisName":"${analysisName}", 59 | "version":"${version}", 60 | "customerId":"${customerId}", 61 | "campaignId":"${campaignId}", 62 | "conversionId": "${conversionId}", 63 | "ytCampaignId": "${ytCampaignId}", 64 | "ytCustomerId": "${ytCustomerId}", 65 | "mediaPlanId": "${mediaPlanId}", 66 | "partitionDay": "${partitionDay}" 67 | }, 68 | "attributes": { 69 | "taskId": "${taskId}", 70 | "multipleTag": "${multipleTag}" 71 | } 72 | }, 73 | "youtubeChannel": { 74 | "qps": 20, 75 | "numberOfThreads": 10, 76 | "topic": "#PROJECT_NAMESPACE#-monitor", 77 | "message": { 78 | "partitionDay": "${partitionDay}", 79 | "channelId": "${channelId}", 80 | "batchId": "${batchId}" 81 | }, 82 | "attributes": { 83 | "taskId": "${taskId}", 84 | "multipleTag": "${multipleTag}" 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_branding_reach_frequency.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE impressions AS ( 16 | SELECT user_id, campaign_id, count(*) as freq, sum(advertiser_impression_cost_usd) as imp_cost 17 | FROM adh.google_ads_impressions 18 | WHERE user_id IS NOT NULL 19 | AND (CAST(campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 20 | GROUP BY 1 ,2 21 | ); 22 | CREATE TABLE clicks AS ( 23 | SELECT 24 | user_id, 25 | impression_data.campaign_id, 26 | SUM(advertiser_click_cost_usd) AS cost, 27 | COUNT(click_id.time_usec) AS clks 28 | FROM 29 | adh.google_ads_clicks 30 | WHERE user_id IS NOT NULL 31 | AND 32 | (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 33 | GROUP BY 1,2 34 | ); 35 | CREATE TABLE conversions AS ( 36 | SELECT 37 | user_id, 38 | impression_data.campaign_id, 39 | count(conversion_id.time_usec) AS convs 40 | FROM 41 | adh.google_ads_conversions 42 | WHERE user_id IS NOT NULL 43 | AND CAST(conversion_type AS STRING) IN UNNEST(SPLIT("${conversionId}")) 44 | AND 45 | (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 46 | GROUP BY 1,2 47 | ); 48 | SELECT 49 | "${analysisName}" AS analysisName, 50 | imp.campaign_id, 51 | t.campaign_name, 52 | imp.freq, 53 | sum(imp.freq) AS impression, 54 | count(distinct imp.user_id) AS unique_reach, 55 | sum(ck.cost) AS clk_cost, 56 | sum(imp.imp_cost) AS imp_cost, 57 | sum(IFNULL(ck.cost,0)+IFNULL(imp.imp_cost,0)) AS total_cost, 58 | sum(ck.clks) AS click, 59 | sum(conv.convs) AS conversion 60 | FROM 61 | tmp.impressions imp 62 | LEFT JOIN 63 | adh.google_ads_campaign t ON imp.campaign_id = t.campaign_id 64 | LEFT JOIN 65 | tmp.clicks ck ON imp.user_id = ck.user_id AND imp.campaign_id = ck.campaign_id 66 | LEFT JOIN 67 | tmp.conversions conv ON imp.user_id = conv.user_id AND imp.campaign_id = conv.campaign_id 68 | GROUP BY 69 | 1,2,3,4 70 | ORDER BY 71 | freq ASC -------------------------------------------------------------------------------- /sql/adh_pure_calc_asset_affinity.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE installed_users 16 | AS ( 17 | SELECT * 18 | FROM 19 | ( 20 | SELECT 21 | impression_id, 22 | b.app_id, 23 | user_id, 24 | ROW_NUMBER() 25 | OVER ( 26 | PARTITION BY user_id, b.app_id 27 | ORDER BY query_id.time_usec DESC 28 | ) AS rank 29 | FROM adh.google_ads_conversions a 30 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 31 | ON 32 | b.campaign_id = a.impression_data.campaign_id 33 | AND b.conversion_id = CAST(a.conversion_type AS string) 34 | WHERE user_id != '0' 35 | AND conversion_attribution_model_type = 'LAST_CLICK' 36 | ) 37 | WHERE rank = 1 38 | ); 39 | 40 | SELECT 41 | impr.customer_id, 42 | impr.campaign_id, 43 | camp.campaign_name, 44 | prep.app_id, 45 | location.country, 46 | aff.affinity_name, 47 | aff.affinity_category, 48 | creative.video_message.youtube_video_id AS video_id, 49 | creative.video_message.video_ad_duration AS video_ad_duration, 50 | COUNT(DISTINCT impr.user_id) target_users, 51 | SUM(IFNULL(impr.advertiser_impression_cost_usd, 0)) + SUM(IFNULL(clk.advertiser_cost_usd, 0)) AS cost_usd, 52 | SUM(clk.num_clicks) AS clicks, 53 | COUNT(impr.query_id.time_usec) AS impressions, 54 | COUNT(DISTINCT conv.user_id) installs 55 | FROM adh.google_ads_impressions impr 56 | CROSS JOIN UNNEST(affinity) AS affinity_id 57 | LEFT JOIN adh.google_ads_campaign camp 58 | USING (campaign_id) 59 | LEFT JOIN adh.google_ads_creative_conversions clk USING (impression_id) 60 | LEFT JOIN tmp.installed_users conv 61 | ON impr.impression_id = conv.impression_id 62 | LEFT JOIN adh.affinity aff 63 | USING (affinity_id) 64 | LEFT JOIN adh.google_ads_adgroup adg 65 | USING (adgroup_id) 66 | LEFT JOIN adh.google_ads_adgroupcreative 67 | USING (ad_group_creative_id) 68 | LEFT JOIN adh.google_ads_creative creative 69 | USING (creative_id) 70 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` prep 71 | ON prep.campaign_id = impr.campaign_id 72 | WHERE impr.user_id != '0' 73 | AND creative.video_message.youtube_video_id != '' 74 | AND creative.video_message.youtube_video_id IS NOT NULL 75 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_pure_calc_asset_affinity.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE installed_users 16 | AS ( 17 | SELECT * 18 | FROM 19 | ( 20 | SELECT 21 | impression_id, 22 | b.app_id, 23 | user_id, 24 | ROW_NUMBER() 25 | OVER ( 26 | PARTITION BY user_id, b.app_id 27 | ORDER BY query_id.time_usec DESC 28 | ) AS rank 29 | FROM adh.google_ads_conversions a 30 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 31 | ON 32 | b.campaign_id = a.impression_data.campaign_id 33 | AND b.conversion_id = CAST(a.conversion_type AS string) 34 | WHERE user_id != '0' 35 | AND conversion_attribution_model_type = 'LAST_CLICK' 36 | ) 37 | WHERE rank = 1 38 | ); 39 | 40 | SELECT 41 | impr.customer_id, 42 | impr.campaign_id, 43 | camp.campaign_name, 44 | prep.app_id, 45 | location.country, 46 | aff.affinity_name, 47 | aff.affinity_category, 48 | creative.video_message.youtube_video_id AS video_id, 49 | creative.video_message.video_ad_duration AS video_ad_duration, 50 | COUNT(DISTINCT impr.user_id) target_users, 51 | SUM(IFNULL(impr.advertiser_impression_cost_usd, 0)) + SUM(IFNULL(clk.advertiser_cost_usd, 0)) AS cost_usd, 52 | SUM(clk.num_clicks) AS clicks, 53 | COUNT(impr.query_id.time_usec) AS impressions, 54 | COUNT(DISTINCT conv.user_id) installs 55 | FROM adh.google_ads_impressions impr 56 | CROSS JOIN UNNEST(affinity) AS affinity_id 57 | LEFT JOIN adh.google_ads_campaign camp 58 | USING (campaign_id) 59 | LEFT JOIN adh.google_ads_creative_conversions clk USING (impression_id) 60 | LEFT JOIN tmp.installed_users conv 61 | ON impr.impression_id = conv.impression_id 62 | LEFT JOIN adh.affinity aff 63 | USING (affinity_id) 64 | LEFT JOIN adh.google_ads_adgroup adg 65 | USING (adgroup_id) 66 | LEFT JOIN adh.google_ads_adgroupcreative 67 | USING (ad_group_creative_id) 68 | LEFT JOIN adh.google_ads_creative creative 69 | USING (creative_id) 70 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` prep 71 | ON prep.campaign_id = impr.campaign_id 72 | WHERE impr.user_id != '0' 73 | AND creative.video_message.youtube_video_id != '' 74 | AND creative.video_message.youtube_video_id IS NOT NULL 75 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9 -------------------------------------------------------------------------------- /sql/adh_pure_calc_asset_demo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE installed_users 16 | AS ( 17 | SELECT * 18 | FROM 19 | ( 20 | SELECT 21 | impression_id, 22 | b.app_id, 23 | user_id, 24 | ROW_NUMBER() 25 | OVER ( 26 | PARTITION BY user_id, b.app_id 27 | ORDER BY query_id.time_usec DESC 28 | ) AS rank 29 | FROM adh.google_ads_conversions a 30 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 31 | ON 32 | b.campaign_id = a.impression_data.campaign_id 33 | AND b.conversion_id = CAST(a.conversion_type AS string) 34 | WHERE user_id !='0' 35 | AND conversion_attribution_model_type = 'LAST_CLICK' 36 | ) 37 | WHERE rank = 1 38 | ); 39 | 40 | SELECT 41 | impr.customer_id, 42 | impr.campaign_id, 43 | camp.campaign_name, 44 | gender_name AS gender_id, 45 | age_group_name, 46 | prep.app_id, 47 | location.country, 48 | creative.video_message.youtube_video_id AS video_id, 49 | creative.video_message.video_ad_duration AS video_ad_duration, 50 | COUNT(impr.query_id.time_usec) AS impressions, 51 | SUM(clk.num_clicks) AS clicks, 52 | COUNT(DISTINCT impr.user_id) AS targeted_users, 53 | SUM(IFNULL(impr.advertiser_impression_cost_usd, 0)) + SUM(IFNULL(clk.advertiser_cost_usd, 0)) AS cost_usd, 54 | COUNT(DISTINCT conv.user_id) AS installs 55 | FROM adh.google_ads_impressions impr 56 | LEFT JOIN adh.google_ads_campaign camp 57 | USING (campaign_id) 58 | LEFT JOIN adh.google_ads_adgroup adg 59 | USING (adgroup_id) 60 | LEFT JOIN adh.google_ads_creative_conversions clk USING (impression_id) 61 | LEFT JOIN adh.gender 62 | ON demographics.gender = gender_id 63 | LEFT JOIN adh.age_group 64 | ON demographics.age_group = age_group_id 65 | LEFT JOIN adh.google_ads_adgroupcreative 66 | USING (ad_group_creative_id) 67 | LEFT JOIN adh.google_ads_creative creative 68 | USING (creative_id) 69 | LEFT JOIN tmp.installed_users conv 70 | ON impr.impression_id = conv.impression_id 71 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` prep 72 | ON prep.campaign_id = impr.campaign_id 73 | WHERE impr.user_id !='0' 74 | AND creative.video_message.youtube_video_id != '' 75 | AND creative.video_message.youtube_video_id IS NOT NULL 76 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_pure_calc_asset_demo.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | CREATE TABLE installed_users 16 | AS ( 17 | SELECT * 18 | FROM 19 | ( 20 | SELECT 21 | impression_id, 22 | b.app_id, 23 | user_id, 24 | ROW_NUMBER() 25 | OVER ( 26 | PARTITION BY user_id, b.app_id 27 | ORDER BY query_id.time_usec DESC 28 | ) AS rank 29 | FROM adh.google_ads_conversions a 30 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` b 31 | ON 32 | b.campaign_id = a.impression_data.campaign_id 33 | AND b.conversion_id = CAST(a.conversion_type AS string) 34 | WHERE user_id !='0' 35 | AND conversion_attribution_model_type = 'LAST_CLICK' 36 | ) 37 | WHERE rank = 1 38 | ); 39 | 40 | SELECT 41 | impr.customer_id, 42 | impr.campaign_id, 43 | camp.campaign_name, 44 | gender_name AS gender_id, 45 | age_group_name, 46 | prep.app_id, 47 | location.country, 48 | creative.video_message.youtube_video_id AS video_id, 49 | creative.video_message.video_ad_duration AS video_ad_duration, 50 | COUNT(impr.query_id.time_usec) AS impressions, 51 | SUM(clk.num_clicks) AS clicks, 52 | COUNT(DISTINCT impr.user_id) AS targeted_users, 53 | SUM(IFNULL(impr.advertiser_impression_cost_usd, 0)) + SUM(IFNULL(clk.advertiser_cost_usd, 0)) AS cost_usd, 54 | COUNT(DISTINCT conv.user_id) AS installs 55 | FROM adh.google_ads_impressions impr 56 | LEFT JOIN adh.google_ads_campaign camp 57 | USING (campaign_id) 58 | LEFT JOIN adh.google_ads_adgroup adg 59 | USING (adgroup_id) 60 | LEFT JOIN adh.google_ads_creative_conversions clk USING (impression_id) 61 | LEFT JOIN adh.gender 62 | ON demographics.gender = gender_id 63 | LEFT JOIN adh.age_group 64 | ON demographics.age_group = age_group_id 65 | LEFT JOIN adh.google_ads_adgroupcreative 66 | USING (ad_group_creative_id) 67 | LEFT JOIN adh.google_ads_creative creative 68 | USING (creative_id) 69 | LEFT JOIN tmp.installed_users conv 70 | ON impr.impression_id = conv.impression_id 71 | INNER JOIN `${datasetId}.adh_app_prep_${partitionDay}` prep 72 | ON prep.campaign_id = impr.campaign_id 73 | WHERE impr.user_id !='0' 74 | AND creative.video_message.youtube_video_id != '' 75 | AND creative.video_message.youtube_video_id IS NOT NULL 76 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9 -------------------------------------------------------------------------------- /sql/nonapp_trd_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer_descriptive_name Account, 17 | c.customer_id Customer_ID, 18 | a.currency Currency, 19 | b.budget_approved Budget_approved, 20 | b.budget_served Budget_served, 21 | b.budget_start_time Budget_start_time, 22 | b.budget_end_time Budget_end_time, 23 | b.budget_remain Budget_remain, 24 | b.spending_limit Spending_limit, 25 | b.purchase_order_number Purchase_order_number, 26 | CASE 27 | WHEN Budget_start_time IS NOT NULL THEN Budget_last 28 | WHEN Budget_start_time IS NULL THEN 0 29 | ELSE 0 30 | END Budget_last_days, 31 | w.week1_cost AS Week1_cost, 32 | w.week2_cost AS Week2_cost, 33 | w.week1_clicks AS Week1_clicks, 34 | w.week2_clicks AS Week2_clicks, 35 | w.week1_conversion_value AS Week1_conversion_value, 36 | w.week2_conversion_value AS Week2_conversion_value, 37 | w.week1_all_conversion_value AS Week1_all_conversion_value, 38 | w.week2_all_conversion_value AS Week2_all_conversion_value, 39 | w.week1_conversions AS Week1_conversions, 40 | w.week2_conversions AS Week2_conversions, 41 | w.week1_impressions AS Week1_impressions, 42 | w.week2_impressions AS Week2_impressions, 43 | c.segments_date Date, 44 | sum(c.metrics_clicks) Clicks, 45 | sum(c.metrics_impressions) Impressions, 46 | sum(c.metrics_cost) Cost, 47 | sum(c.metrics_conversions) Conversions, 48 | sum(c.metrics_conversions_value) Conv_value, 49 | sum(c.metrics_all_conversions) All_conversions, 50 | sum(c.metrics_all_conversions_value) All_conv_value, 51 | sum(c.metrics_conversions_by_conversion_date) Conversions_by_conversion_date, 52 | sum(c.metrics_conversions_value_by_conversion_date) Conversions_value_by_conversion_date, 53 | sum(c.metrics_view_through_conversions) View_through_conversions 54 | FROM `${datasetId}.base_snd_campaign_performance` c 55 | LEFT JOIN `${datasetId}.nonapp_snd_account_wow` w 56 | ON c.customer_id = w.customer_id 57 | LEFT JOIN 58 | ( 59 | SELECT DISTINCT 60 | customer_descriptive_name, 61 | customer_id, 62 | currency 63 | FROM `${datasetId}.base_snd_campaigns` 64 | WHERE segments_date = (SELECT MAX(segments_date) FROM `${datasetId}.base_snd_campaigns`) 65 | ) a 66 | ON c.customer_id = a.customer_id 67 | LEFT JOIN `${datasetId}.nonapp_snd_account_budget` b 68 | ON 69 | b.customer_id = c.customer_id 70 | AND b.segment_date = c.segments_date 71 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 -------------------------------------------------------------------------------- /sql/nonapp_trd_pmax.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | base AS ( 17 | SELECT * 18 | FROM `${datasetId}.report_nonapp_pmax_assetgroup` 19 | WHERE 20 | _PARTITIONTIME IN ( 21 | SELECT MAX(_partitionTime) FROM `${datasetId}.report_nonapp_pmax_assetgroup` 22 | ) 23 | ), 24 | asset_group_num AS ( 25 | SELECT DISTINCT 26 | customer.id AS Customer_ID, 27 | campaign.id AS Campaign_ID, 28 | COUNT(DISTINCT asset_group.id) AS asset_group_num 29 | FROM base 30 | WHERE asset_group.status != 'REMOVED' 31 | GROUP BY 1, 2 32 | ), 33 | ad_strength_num AS ( 34 | SELECT DISTINCT 35 | customer.id AS Customer_ID, 36 | campaign.id AS Campaign_ID, 37 | avg( 38 | CASE 39 | WHEN asset_group.ad_strength IN ('GOOD', 'EXCELLENT') 40 | THEN 0.68 41 | WHEN asset_group.ad_strength IN ('AVERAGE') 42 | THEN 0.35 43 | ELSE 0 44 | END) AS ad_strength_num 45 | FROM base 46 | WHERE asset_group.status != 'REMOVED' 47 | GROUP BY 1, 2 48 | ), 49 | user_video_num AS ( 50 | SELECT DISTINCT 51 | customer.id AS Customer_ID, 52 | campaign.id AS Campaign_ID, 53 | COUNT(DISTINCT asset.id) AS user_video_num 54 | FROM base 55 | WHERE 56 | asset.source = 'ADVERTISER' 57 | AND asset_group_asset.field_type LIKE '%VIDEO' 58 | AND asset_group_asset.status = 'ENABLED' 59 | AND asset_group_asset.policy_summary.approval_status LIKE 'APPROVED%' 60 | AND asset_group.status != 'REMOVED' 61 | GROUP BY 1, 2 62 | ) 63 | SELECT DISTINCT 64 | customer.id AS Customer_ID, 65 | customer.currency_code AS Currency, 66 | customer.descriptive_name AS Account, 67 | campaign.id AS Campaign_ID, 68 | campaign.name AS Campaign, 69 | campaign.status AS Campaign_status, 70 | campaign.advertising_channel_type AS Campaign_type, 71 | campaign.advertising_channel_sub_type AS Campaign_sub_type, 72 | asset_group_num, 73 | ad_strength_num, 74 | user_video_num, 75 | p.spend_7d AS Cost_7d 76 | FROM base b 77 | LEFT JOIN asset_group_num ag 78 | ON 79 | b.customer.id = ag.Customer_ID 80 | AND b.campaign.id = ag.Campaign_ID 81 | LEFT JOIN ad_strength_num ast 82 | ON 83 | b.customer.id = ast.Customer_ID 84 | AND b.campaign.id = ast.Campaign_ID 85 | LEFT JOIN user_video_num uv 86 | ON 87 | b.customer.id = uv.Customer_ID 88 | AND b.campaign.id = uv.Campaign_ID 89 | LEFT JOIN `${datasetId}.nonapp_snd_campaign_pacing` p 90 | ON b.campaign.id = p.id -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_account.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | a.customer_descriptive_name Account, 17 | c.customer_id Customer_ID, 18 | a.currency Currency, 19 | b.budget_approved Budget_approved, 20 | b.budget_served Budget_served, 21 | b.budget_start_time Budget_start_time, 22 | b.budget_end_time Budget_end_time, 23 | b.budget_remain Budget_remain, 24 | b.spending_limit Spending_limit, 25 | b.purchase_order_number Purchase_order_number, 26 | CASE 27 | WHEN Budget_start_time IS NOT NULL THEN Budget_last 28 | WHEN Budget_start_time IS NULL THEN 0 29 | ELSE 0 30 | END Budget_last_days, 31 | w.week1_cost AS Week1_cost, 32 | w.week2_cost AS Week2_cost, 33 | w.week1_clicks AS Week1_clicks, 34 | w.week2_clicks AS Week2_clicks, 35 | w.week1_conversion_value AS Week1_conversion_value, 36 | w.week2_conversion_value AS Week2_conversion_value, 37 | w.week1_all_conversion_value AS Week1_all_conversion_value, 38 | w.week2_all_conversion_value AS Week2_all_conversion_value, 39 | w.week1_conversions AS Week1_conversions, 40 | w.week2_conversions AS Week2_conversions, 41 | w.week1_impressions AS Week1_impressions, 42 | w.week2_impressions AS Week2_impressions, 43 | c.segments_date Date, 44 | sum(c.metrics_clicks) Clicks, 45 | sum(c.metrics_impressions) Impressions, 46 | sum(c.metrics_cost) Cost, 47 | sum(c.metrics_conversions) Conversions, 48 | sum(c.metrics_conversions_value) Conv_value, 49 | sum(c.metrics_all_conversions) All_conversions, 50 | sum(c.metrics_all_conversions_value) All_conv_value, 51 | sum(c.metrics_conversions_by_conversion_date) Conversions_by_conversion_date, 52 | sum(c.metrics_conversions_value_by_conversion_date) Conversions_value_by_conversion_date, 53 | sum(c.metrics_view_through_conversions) View_through_conversions 54 | FROM `${datasetId}.base_snd_campaign_performance` c 55 | LEFT JOIN `${datasetId}.nonapp_snd_account_wow` w 56 | ON c.customer_id = w.customer_id 57 | LEFT JOIN 58 | ( 59 | SELECT DISTINCT 60 | customer_descriptive_name, 61 | customer_id, 62 | currency 63 | FROM `${datasetId}.base_snd_campaigns` 64 | WHERE segments_date = (SELECT MAX(segments_date) FROM `${datasetId}.base_snd_campaigns`) 65 | ) a 66 | ON c.customer_id = a.customer_id 67 | LEFT JOIN `${datasetId}.nonapp_snd_account_budget` b 68 | ON 69 | b.customer_id = c.customer_id 70 | AND b.segment_date = c.segments_date 71 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 -------------------------------------------------------------------------------- /config/workflow_app_hourly.json: -------------------------------------------------------------------------------- 1 | { 2 | "lego_start_hourly": { 3 | "type": "query", 4 | "ancestor": "query_active_account", 5 | "next": [ 6 | { 7 | "taskId": "export_active_account", 8 | "appendedParameters": { 9 | "afterExportTask": "get_reports_hourly" 10 | } 11 | } 12 | ] 13 | }, 14 | "get_reports_hourly": { 15 | "type": "multiple", 16 | "ancestor": "get_reports", 17 | "destination": { 18 | "taskId": "download_reports_hourly" 19 | }, 20 | "next": "load_reports_hourly" 21 | }, 22 | "download_reports_hourly": { 23 | "type": "knot", 24 | "embedded": { 25 | "dueTime": 40, 26 | "tasks": [ 27 | "base_campaign_ads_approval", 28 | "app_disapprovals_ad_group_ad_asset_view" 29 | ] 30 | }, 31 | "errorOptions": { 32 | "ignoreError": true 33 | } 34 | }, 35 | "load_reports_hourly": { 36 | "type": "knot", 37 | "appendedParameters": { 38 | "customerId": "0000000000", 39 | "loginCustomerId": "0000000000" 40 | }, 41 | "embedded": { 42 | "tasks": [ 43 | { 44 | "taskId": "load_report", 45 | "appendedParameters": { 46 | "targetTable": "base_campaign_ads_approval" 47 | } 48 | }, 49 | { 50 | "taskId": "load_report", 51 | "appendedParameters": { 52 | "targetTable": "app_disapprovals_ad_group_ad_asset_view" 53 | } 54 | } 55 | ] 56 | }, 57 | "next": "trigger_snd_query_hourly" 58 | }, 59 | "trigger_snd_query_hourly": { 60 | "type": "knot", 61 | "next": "trigger_trd_query_hourly" 62 | }, 63 | "trigger_trd_query_hourly": { 64 | "type": "knot", 65 | "appendedParameters": { 66 | "markTaskId": "mark_label" 67 | }, 68 | "embedded": { 69 | "tasks": [ 70 | { 71 | "taskId": "query_general", 72 | "appendedParameters": { 73 | "queryName": "app_trd_ads_disapproval_all", 74 | "tableId": "app_trd_ads_disapproval_all" 75 | } 76 | }, 77 | { 78 | "taskId": "query_general", 79 | "appendedParameters": { 80 | "queryName": "app_trd_ads_disapproval_latest", 81 | "tableId": "app_trd_ads_disapproval_latest" 82 | } 83 | } 84 | ] 85 | }, 86 | "next": "trigger_fourth_query_hourly" 87 | }, 88 | "trigger_fourth_query_hourly": { 89 | "type": "knot", 90 | "appendedParameters": { 91 | "labelSourceTable": "base_snd_account_label" 92 | }, 93 | "embedded": { 94 | "tasks": [ 95 | { 96 | "taskId": "${markTaskId}", 97 | "appendedParameters": { 98 | "queryName": "app_trd_ads_disapproval_all" 99 | } 100 | }, 101 | { 102 | "taskId": "${markTaskId}", 103 | "appendedParameters": { 104 | "queryName": "app_trd_ads_disapproval_latest" 105 | } 106 | } 107 | ] 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/nonapp_trd_pmax.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH 16 | base AS ( 17 | SELECT * 18 | FROM `${datasetId}.report_nonapp_pmax_assetgroup` 19 | WHERE 20 | _PARTITIONTIME IN ( 21 | SELECT MAX(_partitionTime) FROM `${datasetId}.report_nonapp_pmax_assetgroup` 22 | ) 23 | ), 24 | asset_group_num AS ( 25 | SELECT DISTINCT 26 | customer.id AS Customer_ID, 27 | campaign.id AS Campaign_ID, 28 | COUNT(DISTINCT asset_group.id) AS asset_group_num 29 | FROM base 30 | WHERE asset_group.status != 'REMOVED' 31 | GROUP BY 1, 2 32 | ), 33 | ad_strength_num AS ( 34 | SELECT DISTINCT 35 | customer.id AS Customer_ID, 36 | campaign.id AS Campaign_ID, 37 | avg( 38 | CASE 39 | WHEN asset_group.ad_strength IN ('GOOD', 'EXCELLENT') 40 | THEN 0.68 41 | WHEN asset_group.ad_strength IN ('AVERAGE') 42 | THEN 0.35 43 | ELSE 0 44 | END) AS ad_strength_num 45 | FROM base 46 | WHERE asset_group.status != 'REMOVED' 47 | GROUP BY 1, 2 48 | ), 49 | user_video_num AS ( 50 | SELECT DISTINCT 51 | customer.id AS Customer_ID, 52 | campaign.id AS Campaign_ID, 53 | COUNT(DISTINCT asset.id) AS user_video_num 54 | FROM base 55 | WHERE 56 | asset.source = 'ADVERTISER' 57 | AND asset_group_asset.field_type LIKE '%VIDEO' 58 | AND asset_group_asset.status = 'ENABLED' 59 | AND asset_group_asset.policy_summary.approval_status LIKE 'APPROVED%' 60 | AND asset_group.status != 'REMOVED' 61 | GROUP BY 1, 2 62 | ) 63 | SELECT DISTINCT 64 | customer.id AS Customer_ID, 65 | customer.currency_code AS Currency, 66 | customer.descriptive_name AS Account, 67 | campaign.id AS Campaign_ID, 68 | campaign.name AS Campaign, 69 | campaign.status AS Campaign_status, 70 | campaign.advertising_channel_type AS Campaign_type, 71 | campaign.advertising_channel_sub_type AS Campaign_sub_type, 72 | asset_group_num, 73 | ad_strength_num, 74 | user_video_num, 75 | p.spend_7d AS Cost_7d 76 | FROM base b 77 | LEFT JOIN asset_group_num ag 78 | ON 79 | b.customer.id = ag.Customer_ID 80 | AND b.campaign.id = ag.Campaign_ID 81 | LEFT JOIN ad_strength_num ast 82 | ON 83 | b.customer.id = ast.Customer_ID 84 | AND b.campaign.id = ast.Campaign_ID 85 | LEFT JOIN user_video_num uv 86 | ON 87 | b.customer.id = uv.Customer_ID 88 | AND b.campaign.id = uv.Campaign_ID 89 | LEFT JOIN `${datasetId}.nonapp_snd_campaign_pacing` p 90 | ON b.campaign.id = p.id -------------------------------------------------------------------------------- /sql/base_snd_geo_perf_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | campaign_id, 17 | customer_id, 18 | customer_currency_code currency, 19 | customer_descriptive_name, 20 | campaign_name, 21 | campaign_status, 22 | campaign_advertising_channel_type, 23 | campaign_advertising_channel_sub_type, 24 | segments_week, 25 | geo_target_constant_canonical_name, 26 | geographic_view_country_criterion_id, 27 | segments_ad_network_type segments_ad_network_type, 28 | IFNULL(metrics_clicks, 0) metrics_clicks, 29 | IFNULL(metrics_conversions_value, 0) metrics_conversions_value, 30 | IFNULL(metrics_impressions, 0) metrics_impressions, 31 | IFNULL(metrics_conversions, 0) metrics_conversions, 32 | IFNULL(metrics_cost, 0) metrics_cost 33 | FROM 34 | ( 35 | SELECT 36 | campaign.id campaign_id, 37 | customer.id customer_id, 38 | customer.currency_code customer_currency_code, 39 | customer.descriptive_name customer_descriptive_name, 40 | campaign.name campaign_name, 41 | campaign.status campaign_status, 42 | campaign.advertising_channel_type campaign_advertising_channel_type, 43 | campaign.advertising_channel_sub_type campaign_advertising_channel_sub_type, 44 | segments.week segments_week, 45 | segments.ad_network_type segments_ad_network_type, 46 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 47 | SUM(metrics.clicks) metrics_clicks, 48 | SUM(metrics.conversions_value) metrics_conversions_value, 49 | SUM(metrics.impressions) metrics_impressions, 50 | ROUND(SUM(metrics.cost_micros) / 1e6, 2) metrics_cost, 51 | SUM(metrics.conversions) metrics_conversions 52 | FROM `${datasetId}.report_base_geographic_view` r 53 | INNER JOIN 54 | ( 55 | SELECT 56 | campaign.id campaign_id, 57 | segments.week segments_week, 58 | MAX(_partitionTime) partitionTime 59 | FROM 60 | `${datasetId}.report_base_geographic_view` 61 | GROUP BY 62 | 1, 63 | 2 64 | ) t 65 | ON 66 | t.partitionTime = r._partitionTime 67 | AND t.campaign_id = r.campaign.id 68 | AND t.segments_week = r.segments.week 69 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 70 | ) geo 71 | LEFT JOIN 72 | ( 73 | SELECT DISTINCT 74 | geo_target_constant.id geographic_view_country_criterion_id, 75 | geo_target_constant.canonical_name geo_target_constant_canonical_name 76 | FROM `${datasetId}.report_base_geo_target_constant` 77 | ) c 78 | USING (geographic_view_country_criterion_id) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/base_snd_geo_perf_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT DISTINCT 16 | campaign_id, 17 | customer_id, 18 | customer_currency_code currency, 19 | customer_descriptive_name, 20 | campaign_name, 21 | campaign_status, 22 | campaign_advertising_channel_type, 23 | campaign_advertising_channel_sub_type, 24 | segments_week, 25 | geo_target_constant_canonical_name, 26 | geographic_view_country_criterion_id, 27 | segments_ad_network_type segments_ad_network_type, 28 | IFNULL(metrics_clicks, 0) metrics_clicks, 29 | IFNULL(metrics_conversions_value, 0) metrics_conversions_value, 30 | IFNULL(metrics_impressions, 0) metrics_impressions, 31 | IFNULL(metrics_conversions, 0) metrics_conversions, 32 | IFNULL(metrics_cost, 0) metrics_cost 33 | FROM 34 | ( 35 | SELECT 36 | campaign.id campaign_id, 37 | customer.id customer_id, 38 | customer.currency_code customer_currency_code, 39 | customer.descriptive_name customer_descriptive_name, 40 | campaign.name campaign_name, 41 | campaign.status campaign_status, 42 | campaign.advertising_channel_type campaign_advertising_channel_type, 43 | campaign.advertising_channel_sub_type campaign_advertising_channel_sub_type, 44 | segments.week segments_week, 45 | segments.ad_network_type segments_ad_network_type, 46 | geographic_view.country_criterion_id geographic_view_country_criterion_id, 47 | SUM(metrics.clicks) metrics_clicks, 48 | SUM(metrics.conversions_value) metrics_conversions_value, 49 | SUM(metrics.impressions) metrics_impressions, 50 | ROUND(SUM(metrics.cost_micros) / 1e6, 2) metrics_cost, 51 | SUM(metrics.conversions) metrics_conversions 52 | FROM `${datasetId}.report_base_geographic_view` r 53 | INNER JOIN 54 | ( 55 | SELECT 56 | campaign.id campaign_id, 57 | segments.week segments_week, 58 | MAX(_partitionTime) partitionTime 59 | FROM 60 | `${datasetId}.report_base_geographic_view` 61 | GROUP BY 62 | 1, 63 | 2 64 | ) t 65 | ON 66 | t.partitionTime = r._partitionTime 67 | AND t.campaign_id = r.campaign.id 68 | AND t.segments_week = r.segments.week 69 | GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 70 | ) geo 71 | LEFT JOIN 72 | ( 73 | SELECT DISTINCT 74 | geo_target_constant.id geographic_view_country_criterion_id, 75 | geo_target_constant.canonical_name geo_target_constant_canonical_name 76 | FROM `${datasetId}.report_base_geo_target_constant` 77 | ) c 78 | USING (geographic_view_country_criterion_id) -------------------------------------------------------------------------------- /sql/app_snd_campaign_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | conv.*, 17 | event_name, 18 | include_in_conversion, 19 | count_type 20 | FROM 21 | ( 22 | SELECT 23 | campaign.id campaign_id, 24 | segments.date segments_date, 25 | segments.conversion_action_name segments_conversion_action_name, 26 | segments.conversion_action segments_conversion_action, 27 | segments.conversion_action_category segments_conversion_action_category, 28 | segments.external_conversion_source segments_conversion_source, 29 | segments.ad_network_type segments_ad_network_type, 30 | IFNULL(SUM(metrics.conversions_value), 0) metrics_conversions_value, 31 | IFNULL(SUM(metrics.conversions), 0) metrics_conversions, 32 | IFNULL(SUM(metrics.all_conversions_value), 0) metrics_all_conversions_value, 33 | IFNULL(SUM(metrics.all_conversions), 0) metrics_all_conversions, 34 | IFNULL( 35 | IF( 36 | segments.conversion_action_category = "DOWNLOAD", 37 | SUM(metrics.conversions), 38 | 0), 39 | 0) 40 | installs, 41 | IFNULL( 42 | IF( 43 | segments.conversion_action_category != "DOWNLOAD", 44 | SUM(metrics.conversions), 45 | 0), 46 | 0) 47 | in_app_actions 48 | FROM 49 | `${datasetId}.report_base_campaign_conversion` r 50 | INNER JOIN 51 | ( 52 | SELECT 53 | campaign.id campaign_id, 54 | segments.date segments_date, 55 | MAX(_partitionTime) partitionTime 56 | FROM 57 | `${datasetId}.report_base_campaign_conversion` 58 | GROUP BY 59 | 1, 60 | 2 61 | ) t 62 | ON 63 | t.partitionTime = r._partitionTime 64 | AND t.campaign_id = r.campaign.id 65 | AND t.segments_date = r.segments.date 66 | GROUP BY 67 | 1, 68 | 2, 69 | 3, 70 | 4, 71 | 5, 72 | 6, 73 | 7 74 | ) conv 75 | LEFT JOIN 76 | ( 77 | SELECT DISTINCT 78 | conversion_action.resource_name segments_conversion_action, 79 | IF( 80 | conversion_action.third_party_app_analytics_settings.event_name IS NULL, 81 | conversion_action.firebase_settings.event_name, 82 | conversion_action.third_party_app_analytics_settings.event_name) 83 | event_name, 84 | conversion_action.include_in_conversions_metric include_in_conversion, 85 | conversion_action.counting_type count_type 86 | FROM 87 | `${datasetId}.report_app_conversion_action` 88 | ) event 89 | USING (segments_conversion_action) 90 | WHERE 91 | metrics_conversions > 0 -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_snd_campaign_conv_report.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | conv.*, 17 | event_name, 18 | include_in_conversion, 19 | count_type 20 | FROM 21 | ( 22 | SELECT 23 | campaign.id campaign_id, 24 | segments.date segments_date, 25 | segments.conversion_action_name segments_conversion_action_name, 26 | segments.conversion_action segments_conversion_action, 27 | segments.conversion_action_category segments_conversion_action_category, 28 | segments.external_conversion_source segments_conversion_source, 29 | segments.ad_network_type segments_ad_network_type, 30 | IFNULL(SUM(metrics.conversions_value), 0) metrics_conversions_value, 31 | IFNULL(SUM(metrics.conversions), 0) metrics_conversions, 32 | IFNULL(SUM(metrics.all_conversions_value), 0) metrics_all_conversions_value, 33 | IFNULL(SUM(metrics.all_conversions), 0) metrics_all_conversions, 34 | IFNULL( 35 | IF( 36 | segments.conversion_action_category = "DOWNLOAD", 37 | SUM(metrics.conversions), 38 | 0), 39 | 0) 40 | installs, 41 | IFNULL( 42 | IF( 43 | segments.conversion_action_category != "DOWNLOAD", 44 | SUM(metrics.conversions), 45 | 0), 46 | 0) 47 | in_app_actions 48 | FROM 49 | `${datasetId}.report_base_campaign_conversion` r 50 | INNER JOIN 51 | ( 52 | SELECT 53 | campaign.id campaign_id, 54 | segments.date segments_date, 55 | MAX(_partitionTime) partitionTime 56 | FROM 57 | `${datasetId}.report_base_campaign_conversion` 58 | GROUP BY 59 | 1, 60 | 2 61 | ) t 62 | ON 63 | t.partitionTime = r._partitionTime 64 | AND t.campaign_id = r.campaign.id 65 | AND t.segments_date = r.segments.date 66 | GROUP BY 67 | 1, 68 | 2, 69 | 3, 70 | 4, 71 | 5, 72 | 6, 73 | 7 74 | ) conv 75 | LEFT JOIN 76 | ( 77 | SELECT DISTINCT 78 | conversion_action.resource_name segments_conversion_action, 79 | IF( 80 | conversion_action.third_party_app_analytics_settings.event_name IS NULL, 81 | conversion_action.firebase_settings.event_name, 82 | conversion_action.third_party_app_analytics_settings.event_name) 83 | event_name, 84 | conversion_action.include_in_conversions_metric include_in_conversion, 85 | conversion_action.counting_type count_type 86 | FROM 87 | `${datasetId}.report_app_conversion_action` 88 | ) event 89 | USING (segments_conversion_action) 90 | WHERE 91 | metrics_conversions > 0 -------------------------------------------------------------------------------- /config/workflow_app_nonapp.json: -------------------------------------------------------------------------------- 1 | { 2 | "download_mcc_reports_impl": { 3 | "type": "knot", 4 | "embedded": { 5 | "tasks": [ 6 | "base_geo_target_constant", 7 | "base_language_constant", 8 | "base_labels", 9 | "nonapp_user_interest" 10 | ] 11 | } 12 | }, 13 | "download_reports_impl": { 14 | "type": "knot", 15 | "embedded": { 16 | "dueTime": 40, 17 | "tasks": [ 18 | "base_account_budget", 19 | "base_account_change_event", 20 | "base_campaign_ads_approval", 21 | "base_campaign_conversion", 22 | "base_campaign_criterion", 23 | "base_campaign_performance", 24 | "base_campaigns", 25 | "base_customer_label", 26 | "base_detail_placement_view", 27 | "base_geographic_view", 28 | "base_videos", 29 | "app_conversion_action", 30 | "app_asset_performance", 31 | "app_geo_conversion", 32 | "app_disapprovals_ad_group_ad_asset_view", 33 | "app_ad_group", 34 | "app_ad_group_perf", 35 | "app_asset_metadata", 36 | "app_recommendations", 37 | "app_skan", 38 | "nonapp_campaign_perf_age_range", 39 | "nonapp_campaign_perf_all_ad", 40 | "nonapp_campaign_perf_all_audience", 41 | "nonapp_campaign_perf_all_feed_item", 42 | "nonapp_campaign_perf_all_time", 43 | "nonapp_campaign_perf_dsa", 44 | "nonapp_campaign_perf_gender", 45 | "nonapp_campaign_perf_search_extensions", 46 | "nonapp_campaign_perf_search_keywords", 47 | "nonapp_campaign_perf_search_search_term", 48 | "nonapp_campaign_perf_user_interest", 49 | "nonapp_user_lists", 50 | "nonapp_pmax_assetgroup", 51 | "nonapp_pmax_conversion" 52 | ] 53 | }, 54 | "errorOptions": { 55 | "ignoreError": true 56 | } 57 | }, 58 | "load_reports_impl": { 59 | "type": "knot", 60 | "embedded": { 61 | "tasks": [ 62 | "baselite_load_reports", 63 | "base_load_reports", 64 | "app_load_reports", 65 | "nonapp_load_reports" 66 | ] 67 | } 68 | }, 69 | "trigger_snd_query_impl": { 70 | "type": "knot", 71 | "embedded": { 72 | "tasks": ["base_snd_query", "app_snd_query", "nonapp_snd_query"] 73 | }, 74 | "next": "trigger_trd_query_impl" 75 | }, 76 | "trigger_trd_query_impl": { 77 | "type": "knot", 78 | "embedded": { 79 | "tasks": ["app_trd_query", "nonapplite_trd_query", "nonapp_trd_query"] 80 | }, 81 | "next": "trigger_fourth_query_impl" 82 | }, 83 | "trigger_fourth_query_impl": { 84 | "type": "knot", 85 | "appendedParameters": { 86 | "markTaskId": "mark_label" 87 | }, 88 | "embedded": { 89 | "tasks": [ 90 | "app_fourth_query", 91 | "nonapplite_fourth_query", 92 | "nonapp_fourth_query" 93 | ] 94 | }, 95 | "next": "trigger_customized_task" 96 | }, 97 | "trigger_mark_email_impl": { 98 | "type": "knot", 99 | "appendedParameters": { 100 | "markTaskId": "mark_email" 101 | }, 102 | "embedded": { 103 | "tasks": [ 104 | "app_fourth_query", 105 | "nonapplite_fourth_query", 106 | "nonapp_fourth_query" 107 | ] 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /sql/app_snd_ads_approval_all.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | asset.ad_group_id, 17 | asset_approval_status, 18 | asset_review_status, 19 | asset_id, 20 | asset.customer_id, 21 | asset.campaign_status, 22 | ad_group_ad_asset_view_field_type, 23 | campaign_app_campaign_setting_app_id, 24 | ag.ad_group_name, 25 | ag.campaign_id, 26 | ag.customer_descriptive_name, 27 | ag.campaign_name, 28 | ag.date, 29 | ag.datetime, 30 | ag.adgroup_approval_status, 31 | ag.adgroup_review_status, 32 | type, 33 | topic 34 | FROM 35 | ( 36 | SELECT 37 | ad_group.id ad_group_id, 38 | campaign.id campaign_id, 39 | campaign.name campaign_name, 40 | ad_group.name ad_group_name, 41 | customer.descriptive_name customer_descriptive_name, 42 | v.type, 43 | v.topic, 44 | DATE(_partitionTime) date, 45 | DATETIME(_partitionTime) datetime, 46 | CASE 47 | WHEN ad_group_ad.policy_summary.approval_status IS NULL THEN 'N/A' 48 | ELSE 49 | ad_group_ad.policy_summary.approval_status 50 | END 51 | adgroup_approval_status, 52 | CASE 53 | WHEN ad_group_ad.policy_summary.review_status IS NULL THEN 'N/A' 54 | ELSE 55 | ad_group_ad.policy_summary.review_status 56 | END 57 | adgroup_review_status, 58 | FROM 59 | `${datasetId}.report_base_campaign_ads_approval` 60 | LEFT JOIN 61 | UNNEST(ad_group_ad.policy_summary.policy_topic_entries) AS v 62 | WHERE 63 | campaign.advertising_channel_type = 'MULTI_CHANNEL' 64 | AND campaign.status = 'ENABLED' 65 | AND ad_group.status = 'ENABLED' 66 | ) ag 67 | LEFT JOIN 68 | ( 69 | SELECT 70 | asset.id asset_id, 71 | ad_group.id ad_group_id, 72 | campaign.app_campaign_setting.app_id campaign_app_campaign_setting_app_id, 73 | customer.id customer_id, 74 | campaign.status campaign_status, 75 | DATE(_partitionTime) date, 76 | CASE 77 | WHEN ad_group_ad_asset_view.policy_summary.approval_status IS NULL THEN 'N/A' 78 | ELSE 79 | ad_group_ad_asset_view.policy_summary.approval_status 80 | END 81 | asset_approval_status, 82 | CASE 83 | WHEN ad_group_ad_asset_view.policy_summary.review_status IS NULL THEN 'N/A' 84 | ELSE 85 | ad_group_ad_asset_view.policy_summary.review_status 86 | END 87 | asset_review_status, 88 | ad_group_ad_asset_view.field_type ad_group_ad_asset_view_field_type 89 | FROM 90 | `${datasetId}.report_app_disapprovals_ad_group_ad_asset_view` 91 | WHERE 92 | campaign.advertising_channel_type = 'MULTI_CHANNEL' 93 | AND campaign.status = 'ENABLED' 94 | ) asset 95 | USING ( 96 | ad_group_id, 97 | date) -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/app_snd_ads_approval_all.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | SELECT 16 | asset.ad_group_id, 17 | asset_approval_status, 18 | asset_review_status, 19 | asset_id, 20 | asset.customer_id, 21 | asset.campaign_status, 22 | ad_group_ad_asset_view_field_type, 23 | campaign_app_campaign_setting_app_id, 24 | ag.ad_group_name, 25 | ag.campaign_id, 26 | ag.customer_descriptive_name, 27 | ag.campaign_name, 28 | ag.date, 29 | ag.datetime, 30 | ag.adgroup_approval_status, 31 | ag.adgroup_review_status, 32 | type, 33 | topic 34 | FROM 35 | ( 36 | SELECT 37 | ad_group.id ad_group_id, 38 | campaign.id campaign_id, 39 | campaign.name campaign_name, 40 | ad_group.name ad_group_name, 41 | customer.descriptive_name customer_descriptive_name, 42 | v.type, 43 | v.topic, 44 | DATE(_partitionTime) date, 45 | DATETIME(_partitionTime) datetime, 46 | CASE 47 | WHEN ad_group_ad.policy_summary.approval_status IS NULL THEN 'N/A' 48 | ELSE 49 | ad_group_ad.policy_summary.approval_status 50 | END 51 | adgroup_approval_status, 52 | CASE 53 | WHEN ad_group_ad.policy_summary.review_status IS NULL THEN 'N/A' 54 | ELSE 55 | ad_group_ad.policy_summary.review_status 56 | END 57 | adgroup_review_status, 58 | FROM 59 | `${datasetId}.report_base_campaign_ads_approval` 60 | LEFT JOIN 61 | UNNEST(ad_group_ad.policy_summary.policy_topic_entries) AS v 62 | WHERE 63 | campaign.advertising_channel_type = 'MULTI_CHANNEL' 64 | AND campaign.status = 'ENABLED' 65 | AND ad_group.status = 'ENABLED' 66 | ) ag 67 | LEFT JOIN 68 | ( 69 | SELECT 70 | asset.id asset_id, 71 | ad_group.id ad_group_id, 72 | campaign.app_campaign_setting.app_id campaign_app_campaign_setting_app_id, 73 | customer.id customer_id, 74 | campaign.status campaign_status, 75 | DATE(_partitionTime) date, 76 | CASE 77 | WHEN ad_group_ad_asset_view.policy_summary.approval_status IS NULL THEN 'N/A' 78 | ELSE 79 | ad_group_ad_asset_view.policy_summary.approval_status 80 | END 81 | asset_approval_status, 82 | CASE 83 | WHEN ad_group_ad_asset_view.policy_summary.review_status IS NULL THEN 'N/A' 84 | ELSE 85 | ad_group_ad_asset_view.policy_summary.review_status 86 | END 87 | asset_review_status, 88 | ad_group_ad_asset_view.field_type ad_group_ad_asset_view_field_type 89 | FROM 90 | `${datasetId}.report_app_disapprovals_ad_group_ad_asset_view` 91 | WHERE 92 | campaign.advertising_channel_type = 'MULTI_CHANNEL' 93 | AND campaign.status = 'ENABLED' 94 | ) asset 95 | USING ( 96 | ad_group_id, 97 | date) -------------------------------------------------------------------------------- /sql/adh_branding_conversion_uplift_MH.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH mh_disc_users AS ( 16 | SELECT 17 | device_id_md5, 18 | 1 AS user_type 19 | FROM adh.yt_reserve_impressions_rdid 20 | WHERE CAST(media_plan_id AS STRING) IN UNNEST(SPLIT("${mediaPlanId}")) 21 | AND device_id_md5 IS NOT NULL 22 | GROUP BY 1 23 | ), 24 | ac_impressions AS ( 25 | SELECT 26 | device_id_md5, 27 | customer_id, 28 | COUNT(*) AS imps, 29 | SUM(advertiser_impression_cost_usd) as imp_cost 30 | FROM 31 | `adh.google_ads_impressions_rdid` 32 | WHERE 33 | device_id_md5 IS NOT NULL 34 | AND (CAST(campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 35 | GROUP BY 1,2 36 | ), 37 | ac_clicks AS ( 38 | SELECT 39 | device_id_md5, 40 | impression_data.customer_id, 41 | COUNT(click_id.time_usec) AS clks, 42 | SUM(advertiser_click_cost_usd) AS cost 43 | FROM 44 | adh.google_ads_clicks_rdid 45 | WHERE 46 | device_id_md5 IS NOT NULL 47 | AND (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 48 | GROUP BY 1,2 49 | ), 50 | ac_conversions AS ( 51 | SELECT 52 | device_id_md5, 53 | impression_data.customer_id, 54 | COUNT(conversion_id. time_usec) AS convs 55 | FROM 56 | adh.google_ads_conversions_rdid 57 | WHERE 58 | device_id_md5 IS NOT NULL 59 | AND CAST(conversion_type AS STRING) IN UNNEST(SPLIT("${conversionId}")) 60 | AND (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 61 | GROUP BY 1,2 62 | ) 63 | SELECT 64 | "${analysisName}" AS analysisName, 65 | ai.customer_id, 66 | customer_name, 67 | CASE 68 | WHEN yt.user_type = 1 69 | THEN "wt_yt" 70 | ELSE "ac_only" 71 | END AS user_type, 72 | SUM(ai.imps) AS impression, 73 | COUNT(DISTINCT ai.device_id_md5) AS unique_reach, 74 | SUM(ac.clks) AS clicks, 75 | SUM(ac.cost) AS cost, 76 | SUM(imp_cost) AS evc_cost, 77 | (IFNULL(SUM(ac.cost),0)+IFNULL(SUM(imp_cost),0)) AS total_cost, 78 | SUM(aconv.convs) AS conversions 79 | FROM 80 | ac_impressions ai 81 | LEFT JOIN 82 | mh_disc_users yt ON ai.device_id_md5 = yt.device_id_md5 83 | LEFT JOIN 84 | adh.google_ads_customer USING (customer_id) 85 | LEFT JOIN 86 | ac_clicks ac ON ai.device_id_md5 = ac.device_id_md5 87 | AND ai.customer_id = ac.customer_id 88 | LEFT JOIN 89 | ac_conversions aconv ON ai.device_id_md5 = aconv.device_id_md5 90 | AND ai.customer_id = aconv.customer_id 91 | GROUP BY 92 | 1,2,3,4 93 | ORDER BY 94 | 1,4 DESC -------------------------------------------------------------------------------- /tool/sheet_installer/src/oec/sql/adh_branding_conversion_uplift_MH.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2023 Google LLC 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | WITH mh_disc_users AS ( 16 | SELECT 17 | device_id_md5, 18 | 1 AS user_type 19 | FROM adh.yt_reserve_impressions_rdid 20 | WHERE CAST(media_plan_id AS STRING) IN UNNEST(SPLIT("${mediaPlanId}")) 21 | AND device_id_md5 IS NOT NULL 22 | GROUP BY 1 23 | ), 24 | ac_impressions AS ( 25 | SELECT 26 | device_id_md5, 27 | customer_id, 28 | COUNT(*) AS imps, 29 | SUM(advertiser_impression_cost_usd) as imp_cost 30 | FROM 31 | `adh.google_ads_impressions_rdid` 32 | WHERE 33 | device_id_md5 IS NOT NULL 34 | AND (CAST(campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 35 | GROUP BY 1,2 36 | ), 37 | ac_clicks AS ( 38 | SELECT 39 | device_id_md5, 40 | impression_data.customer_id, 41 | COUNT(click_id.time_usec) AS clks, 42 | SUM(advertiser_click_cost_usd) AS cost 43 | FROM 44 | adh.google_ads_clicks_rdid 45 | WHERE 46 | device_id_md5 IS NOT NULL 47 | AND (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 48 | GROUP BY 1,2 49 | ), 50 | ac_conversions AS ( 51 | SELECT 52 | device_id_md5, 53 | impression_data.customer_id, 54 | COUNT(conversion_id. time_usec) AS convs 55 | FROM 56 | adh.google_ads_conversions_rdid 57 | WHERE 58 | device_id_md5 IS NOT NULL 59 | AND CAST(conversion_type AS STRING) IN UNNEST(SPLIT("${conversionId}")) 60 | AND (CAST(impression_data.campaign_id AS STRING) IN UNNEST(SPLIT("${campaignId}")) OR CAST(impression_data.customer_id AS STRING) IN UNNEST(SPLIT("${customerId}"))) 61 | GROUP BY 1,2 62 | ) 63 | SELECT 64 | "${analysisName}" AS analysisName, 65 | ai.customer_id, 66 | customer_name, 67 | CASE 68 | WHEN yt.user_type = 1 69 | THEN "wt_yt" 70 | ELSE "ac_only" 71 | END AS user_type, 72 | SUM(ai.imps) AS impression, 73 | COUNT(DISTINCT ai.device_id_md5) AS unique_reach, 74 | SUM(ac.clks) AS clicks, 75 | SUM(ac.cost) AS cost, 76 | SUM(imp_cost) AS evc_cost, 77 | (IFNULL(SUM(ac.cost),0)+IFNULL(SUM(imp_cost),0)) AS total_cost, 78 | SUM(aconv.convs) AS conversions 79 | FROM 80 | ac_impressions ai 81 | LEFT JOIN 82 | mh_disc_users yt ON ai.device_id_md5 = yt.device_id_md5 83 | LEFT JOIN 84 | adh.google_ads_customer USING (customer_id) 85 | LEFT JOIN 86 | ac_clicks ac ON ai.device_id_md5 = ac.device_id_md5 87 | AND ai.customer_id = ac.customer_id 88 | LEFT JOIN 89 | ac_conversions aconv ON ai.device_id_md5 = aconv.device_id_md5 90 | AND ai.customer_id = aconv.customer_id 91 | GROUP BY 92 | 1,2,3,4 93 | ORDER BY 94 | 1,4 DESC --------------------------------------------------------------------------------