Skip to content

Commit

Permalink
Add support for custom conversion mapping
Browse files Browse the repository at this point in the history
* Custom conversions and conversions_value can be added to
  `asset_performance` and `ad_group_network_split`.
* Document usage in `docs/advanced-customizations`

Change-Id: I0939b2f2f8134cddbdef0bed4748d2deecd54183
  • Loading branch information
AVMarkin committed Nov 29, 2023
1 parent 7c61f44 commit 1dda874
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 15 deletions.
56 changes: 43 additions & 13 deletions app/assets/bq_queries/asset_performance.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-- Copyright 2022 Google LLC
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Contains performance (clicks, impressions, installs, inapps, etc) on asset_id level
-- segmented by network (Search, Display, YouTube).
Expand Down Expand Up @@ -124,6 +124,24 @@ WITH CampaignCostTable AS (
ANY_VALUE(video_orientation) AS video_orientation
FROM `{bq_dataset}.video_orientation`
GROUP BY 1
),
CustomConvSplit AS (
SELECT
C.date,
C.ad_group_id,
C.asset_id,
C.field_type,
C.network,
{% for custom_conversion in custom_conversions %}
{% for conversion_alias, conversion_name in custom_conversion.items() %}
SUM(IF(ConversionMapping.conversion_name IN ('{{conversion_name}}'), C.all_conversions, 0)) AS conversions_{{conversion_alias}},
SUM(IF(ConversionMapping.conversion_name IN ('{{conversion_name}}'), C.all_conversions_value, 0)) AS conversions_value_{{conversion_alias}},
{% endfor %}
{% endfor %}
FROM `{bq_dataset}.asset_conversion_split` AS C
LEFT JOIN `{bq_dataset}.app_conversions_mapping` AS ConversionMapping
ON C.conversion_id = ConversionMapping.conversion_id
GROUP BY 1, 2, 3, 4, 5
)
SELECT
PARSE_DATE("%Y-%m-%d", AP.date) AS day,
Expand Down Expand Up @@ -198,6 +216,12 @@ SELECT
SUM(ConvSplit.inapps_adjusted) AS inapps_adjusted,
SUM(AP.view_through_conversions) AS view_through_conversions,
SUM(AP.conversions_value) AS conversions_value,
{% for custom_conversion in custom_conversions %}
{% for conversion_alias, conversion_name in custom_conversion.items() %}
SUM(COALESCE(CCS.conversions_{{conversion_alias}}, 0)) AS conversions_{{conversion_alias}},
SUM(COALESCE(CCS.conversions_value_{{conversion_alias}}, 0)) AS conversions_value_{{conversion_alias}},
{% endfor %}
{% endfor %}
{% for day in cohort_days %}
SUM(GetCohort(AssetCohorts.lag_data.installs, {{day}})) AS installs_{{day}}_day,
SUM(GetCohort(AssetCohorts.lag_data.inapps, {{day}})) AS inapps_{{day}}_day,
Expand Down Expand Up @@ -235,4 +259,10 @@ LEFT JOIN `{bq_dataset}.AssetCohorts` AS AssetCohorts
AND AP.network = AssetCohorts.network
AND AP.asset_id = AssetCohorts.asset_id
AND AP.field_type = AssetCohorts.field_type
LEFT JOIN CustomConvSplit AS CCS
ON AP.date = CCS.date
AND AP.ad_group_id = CCS.ad_group_id
AND AP.network = CCS.network
AND AP.asset_id = CCS.asset_id
AND AP.field_type = CCS.field_type
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, 25, 26, 27, 28, 29, 30, 31, 32);
26 changes: 25 additions & 1 deletion app/core/bq_queries/ad_group_network_split.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ AS (
FROM `{bq_dataset}.account_campaign_ad_group_mapping`
LEFT JOIN `{bq_dataset}.ocid_mapping` USING(account_id)
GROUP BY 1
),
CustomConvSplit AS (
SELECT
date,
ad_group_id,
network,
{% for custom_conversion in custom_conversions %}
{% for conversion_alias, conversion_name in custom_conversion.items() %}
SUM(IF(conversion_name IN ('{{conversion_name}}'), all_conversions, 0)) AS conversions_{{conversion_alias}},
SUM(IF(conversion_name IN ('{{conversion_name}}'), all_conversions_value, 0)) AS conversions_value_{{conversion_alias}},
{% endfor %}
{% endfor %}
FROM `{bq_dataset}.ad_group_conversion_split`
GROUP BY 1, 2, 3
)
SELECT
PARSE_DATE("%Y-%m-%d", AP.date) AS day,
Expand Down Expand Up @@ -91,7 +105,13 @@ SELECT
SUM(inapps_adjusted) AS inapps_adjusted,
SUM(AP.view_through_conversions) AS view_through_conversions,
SUM(AP.video_views) AS video_views,
SUM(AP.conversions_value) AS conversions_value
SUM(AP.conversions_value) AS conversions_value,
{% for custom_conversion in custom_conversions %}
{% for conversion_alias, conversion_name in custom_conversion.items() %}
SUM(COALESCE(CCS.conversions_{{conversion_alias}}, 0)) AS conversions_{{conversion_alias}},
SUM(COALESCE(CCS.conversions_value_{{conversion_alias}}, 0)) AS conversions_value_{{conversion_alias}},
{% endfor %}
{% endfor %}
FROM {bq_dataset}.ad_group_performance AS AP
LEFT JOIN ConversionsTable AS ConvSplit
USING(date, ad_group_id, network)
Expand All @@ -101,4 +121,8 @@ LEFT JOIN `{bq_dataset}.AppCampaignSettingsView` AS ACS
ON M.campaign_id = ACS.campaign_id
LEFT JOIN `{bq_dataset}.GeoLanguageView` AS G
ON M.campaign_id = G.campaign_id
LEFT JOIN CustomConvSplit AS CCS
ON AP.date = CCS.date
AND AP.ad_group_id = CCS.ad_group_id
AND AP.network = CCS.network
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
3 changes: 2 additions & 1 deletion app/core/google_ads_queries/ad_group_conversion_split.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SELECT
segments.conversion_action~0 AS conversion_id,
metrics.conversions AS conversions,
metrics.all_conversions AS all_conversions,
metrics.conversions_value AS conversions_value
metrics.conversions_value AS conversions_value,
metrics.all_conversions_value AS all_conversions_value
FROM ad_group
WHERE
campaign.advertising_channel_type = "MULTI_CHANNEL"
Expand Down
25 changes: 25 additions & 0 deletions docs/advanced-customizations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# How to customize App Reporting Pack data fetching

## Providing custom conversion mapping

If you want your tables (`asset_performance` and `ad_group_network_split`)
to contain custom conversion mapping (i.e. column that contains conversion(s)
only with a particular conversion name) you can add the following lines to
your `app_reporting_pack.yaml` in "conversion_alias: Conversion Name" format:

```
template:
custom_conversions:
- conversion_name_1: "Your Conv','Second Conv"
conversion_name_2: "My Conv"
```

This will the following columns to your tables in BigQuery:

* `conversions_conversion_name_1`
* `conversions_value_conversion_name_1`
* `conversions_conversion_name_2`
* `conversions_value_conversion_name_2`

You can add one or more conversion names to a given conversion alias; in case
of several conversion they should be separated with `','`.

0 comments on commit 1dda874

Please sign in to comment.