Skip to content

Commit

Permalink
backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-jamie committed Nov 7, 2024
1 parent 78e3f65 commit 23aaa7e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ vars:
where_sql: source_relation = 'advertiser who only cares about subscriptions' # will grab `basic_ad_actions` records where (action_type like 'subscribe%' and {{ where_sql }})
```
>**Note**: If you were previously utilizing the `facebook_ads__basic_ad_passthrough_metrics` variable to include a (likely null) field called `conversions` or `conversions_value`, the package's version of these fields will take precedence over yours. To continue including your old conversions fields, change the `alias` of the passthrough field to another name.

- Creates the new `facebook_ads__basic_ad_actions_passthrough_metrics` and `facebook_ads__basic_ad_action_values_passthrough_metrics` variables to pass through additional conversion value metrics that are calculated using different attribution windows.
- By default, the package includes only the conversion values calculated using the default attribution window set in Meta, but your report may include calculations using the other windows defined [here](https://developers.facebook.com/docs/marketing-api/reference/ads-action-stats/). See [README](https://github.com/fivetran/dbt_facebook_ads_source/tree/main?tab=readme-ov-file#passing-through-additional-metrics) for details on how to use the new variables.
- By default, the package includes only the conversion values calculated using the default attribution window set in Meta, but your report may include calculations using the other windows defined [here](https://developers.facebook.com/docs/marketing-api/reference/ads-action-stats/). See [README](https://github.com/fivetran/dbt_facebook_ads/tree/main?tab=readme-ov-file#passing-through-additional-metrics) for details on how to use the new variables.
- Adds `optimization_goal` field to `facebook_ads__ad_set_report` model. This is defined as the optimization goal this ad set is using, possible values of which are defined [here](https://developers.facebook.com/docs/marketing-api/reference/ad-campaign/#fields).
- Adds `conversion_domain` field to `facebook_ads__ad_report` model. This is defined as the domain you've configured the ad to convert to.

Expand Down
6 changes: 4 additions & 2 deletions macros/facebook_ads_persist_pass_through_columns.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{# Adapted from fivetran_utils.persist_pass_through_columns() macro to include coalesces #}

{% macro facebook_ads_persist_pass_through_columns(pass_through_variable, identifier=none, transform='', coalesce_with=none) %}
{% macro facebook_ads_persist_pass_through_columns(pass_through_variable, identifier=none, transform='', coalesce_with=none, exclude_fields=[]) %}

{% if var(pass_through_variable, none) %}
{% for field in var(pass_through_variable) %}
{% set field_name = field.alias|default(field.name)|lower if field is mapping else field %}
, {{ transform ~ '(' ~ ('coalesce(' if coalesce_with is not none else '') ~ (identifier ~ '.' if identifier else '') ~ field_name ~ ((', ' ~ coalesce_with ~ ')') if coalesce_with is not none else '') ~ ')' }} as {{ field_name }}
{% if field_name not in exclude_fields %}
, {{ transform ~ '(' ~ ('coalesce(' if coalesce_with is not none else '') ~ (identifier ~ '.' if identifier else '') ~ field_name ~ ((', ' ~ coalesce_with ~ ')') if coalesce_with is not none else '') ~ ')' }} as {{ field_name }}
{% endif %}
{% endfor %}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion models/facebook_ads__account_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ joined as (
sum(coalesce(conversion_report.conversions, 0)) as conversions,
sum(coalesce(conversion_report.conversions_value, 0)) as conversions_value

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum') }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum', exclude_fields=['conversions', 'conversions_value']) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_actions_passthrough_metrics', transform = 'sum', coalesce_with=0) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_action_values_passthrough_metrics', transform = 'sum', coalesce_with=0) }}

Expand Down
2 changes: 1 addition & 1 deletion models/facebook_ads__ad_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ joined as (
sum(coalesce(conversion_report.conversions, 0)) as conversions,
sum(coalesce(conversion_report.conversions_value, 0)) as conversions_value

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum') }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum', exclude_fields=['conversions', 'conversions_value']) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_actions_passthrough_metrics', transform = 'sum', coalesce_with=0) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_action_values_passthrough_metrics', transform = 'sum', coalesce_with=0) }}

Expand Down
2 changes: 1 addition & 1 deletion models/facebook_ads__ad_set_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ joined as (
sum(coalesce(conversion_report.conversions, 0)) as conversions,
sum(coalesce(conversion_report.conversions_value, 0)) as conversions_value

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum') }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum', exclude_fields=['conversions', 'conversions_value']) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_actions_passthrough_metrics', transform = 'sum', coalesce_with=0) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_action_values_passthrough_metrics', transform = 'sum', coalesce_with=0) }}

Expand Down
2 changes: 1 addition & 1 deletion models/facebook_ads__campaign_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ joined as (
sum(coalesce(conversion_report.conversions, 0)) as conversions,
sum(coalesce(conversion_report.conversions_value, 0)) as conversions_value

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum') }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum', exclude_fields=['conversions', 'conversions_value']) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_actions_passthrough_metrics', transform = 'sum', coalesce_with=0) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_action_values_passthrough_metrics', transform = 'sum', coalesce_with=0) }}

Expand Down
2 changes: 1 addition & 1 deletion models/facebook_ads__url_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ joined as (
sum(coalesce(conversion_report.conversions, 0)) as conversions,
sum(coalesce(conversion_report.conversions_value, 0)) as conversions_value

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum') }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_passthrough_metrics', transform = 'sum', exclude_fields=['conversions', 'conversions_value']) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_actions_passthrough_metrics', transform = 'sum', coalesce_with=0) }}
{{ facebook_ads_persist_pass_through_columns(pass_through_variable='facebook_ads__basic_ad_action_values_passthrough_metrics', transform = 'sum', coalesce_with=0) }}

Expand Down

0 comments on commit 23aaa7e

Please sign in to comment.