Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion metrics #26

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dbt_modules/
logs/
.DS_Store
integration_tests/.DS_Store
dbt_packages/
dbt_packages/
integration_tests/package-lock.yml
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# dbt_twitter v0.8.0

[PR #26](https://github.com/fivetran/dbt_twitter/pull/26) includes the following **BREAKING CHANGE** updates:

## Feature Updates: Native Conversion Support
We have added more robust support for conversions in our data models by doing the following:
- Created the `twitter_ads__conversion_fields` and `twitter_ads__conversion_sale_amount_fields` variables to pass through conversion metrics (total number and monetary value, respectively).
- By default, `twitter_ads__conversion_fields` will include `conversion_purchases_metric` and `conversion_custom_metric`.
- By default, `twitter_ads__conversion_sale_amount_fields` will include `conversion_purchases_sale_amount` and `conversion_custom_sale_amount`.
- These conversion fields will be included in each end model report. Additionally, they will be summed up into new `total_conversions` and `total_conversions_sale_amount` columns.
- See [README](https://github.com/fivetran/dbt_twitter?tab=readme-ov-file#customizing-types-of-conversions) for more details on how to configure these variables.

## Under the Hood
- Ensured the above changes maintain backwards compatibility with [existing passthrough column variables](https://github.com/fivetran/dbt_twitter?tab=readme-ov-file#passing-through-additional-metrics).
- Added a new [version](https://github.com/fivetran/dbt_twitter_ads/blob/main/macros/twitter_ads_persist_pass_through_columns.sql) of the `persist_pass_through_columns()` [macro](https://github.com/fivetran/dbt_fivetran_utils/blob/v0.4.10/macros/persist_pass_through_columns.sql) in which we can include coalesces and properly check between conversion field values and the existing passthrough columns.
- Added integrity and consistency validation tests within `integration_tests` for the Twitter Ads transformation models.

## Documentation
- Highlighted all metrics included in the package by default. Previously, `url_clicks` and `spend_micro` were missing from this README [section](https://github.com/fivetran/dbt_twitter?tab=readme-ov-file#passing-through-additional-metrics).
- Documented how to configure the new `twitter_ads__conversion_fields` and `twitter_ads__conversion_sale_amount_fields` variables [here](https://github.com/fivetran/dbt_twitter?tab=readme-ov-file#customizing-types-of-conversions).
- Added Contributors [subsection](https://github.com/fivetran/dbt_twitter?tab=readme-ov-file#contributors) to README.

## Contributors
- [Seer Interactive](https://www.seerinteractive.com/?utm_campaign=Fivetran%20%7C%20Models&utm_source=Fivetran&utm_medium=Fivetran%20Documentation)

# dbt_twitter v0.7.0
[PR #21](https://github.com/fivetran/dbt_twitter/pull/21) includes the following updates:
## Feature update 🎉
Expand Down
54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ dispatch:
search_order: ['spark_utils', 'dbt_utils']
```

### Step 2: Install the package
Include the following Twitter package version in your `packages.yml` file:
### Step 2: Install the package (skip if using `ad_reporting` combination package)
If you are not using the downstream [Ad Reporting](https://github.com/fivetran/dbt_ad_reporting) combination package, include the following Twitter package version in your `packages.yml` file:
> TIP: Check [dbt Hub](https://hub.getdbt.com/) for the latest installation instructions or [read the dbt docs](https://docs.getdbt.com/docs/package-management) for more information on installing packages

```yml
# packages.yml
packages:
- package: fivetran/twitter_ads
version: [">=0.7.0", "<0.8.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.8.0", "<0.9.0"] # we recommend using ranges to capture non-breaking changes automatically
```
Do NOT include the `twitter_ads_source` package in this file. The transformation package itself has a dependency on it and will install the source package as well.

Expand All @@ -79,6 +79,8 @@ vars:
```

### (Optional) Step 5: Additional configurations
<details open><summary>Expand/Collapse details</summary>

#### Union multiple connectors
If you have multiple twitter ads connectors in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. The package will union all of the data together and pass the unioned table into the transformations. You will be able to see which source it came from in the `source_relation` column of each model. To use this functionality, you will need to set either the `twitter_ads_union_schemas` OR `twitter_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

Expand All @@ -91,8 +93,39 @@ vars:

To connect your multiple schema/database sources to the package models, follow the steps outlined in the [Union Data Defined Sources Configuration](https://github.com/fivetran/dbt_fivetran_utils/tree/releases/v0.4.latest#union_data-source) section of the Fivetran Utils documentation for the union_data macro. This will ensure a proper configuration and correct visualization of connections in the DAG.

#### Customizing Types of Conversions
The package will include conversion metrics provided to the following variables in each model.

| Variable | Definition | Default Values |
| -------- | -------- | -------- |
| `twitter_ads__conversion_fields` | Which fields should be included in calculating total number of conversions. | `conversion_purchases_metric`, `conversion_custom_metric` |
| `twitter_ads__conversion_sale_amount_fields` | Which `*_sale_amount` fields should be included in calculating the total value of conversions. | `conversion_purchases_sale_amount`, `conversion_custom_sale_amount` |

In addition, the fields included in `var('twitter_ads__conversion_fields')` will be summed up into a `total_conversions` field, and the fields included in `var('twitter_ads__conversion_sale_amount_fields')` will be summed up into a `total_conversions_sale_amount` field.

By default, the data models include purchases and custom conversion events in both variables. However, you can configure each to include any types of conversions available in the Twitter Ads source `*_report` tables:

```yml
# dbt_project.yml
vars:
twitter_ads__conversion_fields:
- conversion_purchases_metric
- conversion_sign_ups_metric
- mobile_conversion_payment_info_additions_post_engagement
- mobile_conversion_add_to_wishlists_post_engagement
- mobile_conversion_add_to_carts_post_engagement
- mobile_conversion_checkouts_initiated_post_engagement
- <any conversion field you want to include>
twitter_ads__conversion_sale_amount_fields:
- conversion_purchases_sale_amount
- conversion_sign_ups_sale_amount
- <any conversion value/sale amount field you want to include>
```

> We recommend using the same *types* of conversion events for `twitter_ads__conversion_fields` and `twitter_ads__conversion_sale_amount_fields` so that `total_conversions` and `total_conversions_sale_amount` properly map onto each other, but this is not required.

#### Passing Through Additional Metrics
By default, this package will select `clicks`, `impressions`, and `cost` from the source reporting tables to store into the staging models. If you would like to pass through additional metrics to the staging models, add the below configurations to your `dbt_project.yml` file. These variables allow for the pass-through fields to be aliased (`alias`) if desired, but not required. Use the below format for declaring the respective pass-through variables:
Besides the above conversion fields, this package by default will select `clicks`, `url_clicks`, `impressions`, `spend` (calculated from `billed_charge_local_micro`), and `spend_micro` (aliased from `billed_charge_local_micro`) from the source reporting tables to store into the staging models. If you would like to pass through additional metrics to the staging models, add the below configurations to your `dbt_project.yml` file. These variables allow for the pass-through fields to be aliased (`alias`) if desired, but not required. Use the below format for declaring the respective pass-through variables:

> IMPORTANT: Make sure to exercise due diligence when adding metrics to these models. The metrics added by default (taps, impressions, and spend) have been vetted by the Fivetran team, maintaining this package for accuracy. There are metrics included within the source reports, such as metric averages, which may be inaccurately represented at the grain for reports created in this package. You must ensure that whichever metrics you pass through are appropriate to aggregate at the respective reporting levels in this package.

Expand Down Expand Up @@ -132,6 +165,8 @@ vars:
twitter_ads_<default_source_table_name>_identifier: your_table_name
```

</details>

### (Optional) Step 6: Orchestrate your models with Fivetran Transformations for dbt Core™
<details><summary>Expand for more details</summary>
<br>
Expand All @@ -146,8 +181,8 @@ This dbt package is dependent on the following dbt packages. These dependencies

```yml
packages:
- package: fivetran/twitter_source
version: [">=0.7.0", "<0.8.0"]
- package: fivetran/twitter_ads_source
version: [">=0.8.0", "<0.9.0"]
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
- package: dbt-labs/dbt_utils
Expand All @@ -166,6 +201,13 @@ In creating this package, which is meant for a wide range of use cases, we had t
### Contributions
A small team of analytics engineers at Fivetran develops these dbt packages. However, the packages are made better by community contributions.

We highly encourage and welcome contributions to this package. Check out [this dbt Discourse article](https://discourse.getdbt.com/t/contributing-to-a-dbt-package/657) on the best workflow for contributing to a package.

#### Contributors
We thank [everyone](https://github.com/fivetran/dbt_twitter/graphs/contributors) who has taken the time to contribute. Each PR, bug report, and feature request has made this package better and is truly appreciated.

A special thank you to [Seer Interactive](https://www.seerinteractive.com/?utm_campaign=Fivetran%20%7C%20Models&utm_source=Fivetran&utm_medium=Fivetran%20Documentation), who we closely collaborated with to introduce native conversion support to our Ad packages.

## Are there any resources available?
- If you have questions or want to reach out for help, see the [GitHub Issue](https://github.com/fivetran/dbt_twitter/issues/new/choose) section to find the right avenue of support for you.
- If you would like to provide feedback to the dbt package team at Fivetran or would like to request a new dbt package, fill out our [Feedback Form](https://www.surveymonkey.com/r/DQ7K7WW).
9 changes: 8 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'twitter_ads'
version: '0.7.0'
version: '0.8.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
Expand All @@ -22,3 +22,10 @@ vars:
twitter_ads__line_item_report_passthrough_metrics: []
twitter_ads__line_item_keywords_report_passthrough_metrics: []
twitter_ads__promoted_tweet_report_passthrough_metrics: []

twitter_ads__conversion_fields:
- conversion_purchases_metric
- conversion_custom_metric
twitter_ads__conversion_sale_amount_fields:
- conversion_purchases_sale_amount
- conversion_custom_sale_amount
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/run_results.json

This file was deleted.

15 changes: 14 additions & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
name: 'twitter_integration_tests'
version: '0.7.0'
version: '0.8.0'
profile: 'integration_tests'
config-version: 2
snapshot-paths: ["snapshots"]

models:
+schema: "twitter_ads_{{ var('directed_schema','dev') }}"

fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
vars:
twitter_ads__line_item_report_passthrough_metrics:
- name: "conversion_purchases_metric"
- name: "conversion_custom_sale_amount"
alias: "custom_conversion_value"

twitter_ads__conversion_sale_amount_fields:
- conversion_purchases_sale_amount
- conversion_custom_sale_amount
- conversion_sign_ups_sale_amount

twitter_ads_source:
twitter_ads_schema: twitter_ads_integration_tests_4

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/packages.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
packages:
- local: ../
- local: ../
65 changes: 65 additions & 0 deletions integration_tests/tests/consistency/consistency_account_report.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{ config(
tags="fivetran_validations",
enabled=var('fivetran_validation_tests_enabled', false)
) }}

with prod as (
select
account_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_prod.twitter_ads__account_report
group by 1
),

dev as (
select
account_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_dev.twitter_ads__account_report
group by 1
),

final as (
select
prod.account_id,
prod.clicks as prod_clicks,
dev.clicks as dev_clicks,
prod.url_clicks as prod_url_clicks,
dev.url_clicks as dev_url_clicks,
prod.impressions as prod_impressions,
dev.impressions as dev_impressions,
prod.spend as prod_spend,
dev.spend as dev_spend,
prod.spend_micro as prod_spend_micro,
dev.spend_micro as dev_spend_micro
{# prod.total_conversions as prod_total_conversions,
dev.total_conversions as dev_total_conversions,
prod.total_conversions_sale_amount as prod_total_conversions_sale_amount,
dev.total_conversions_sale_amount as dev_total_conversions_sale_amount #}
from prod
full outer join dev
on dev.account_id = prod.account_id
)

select *
from final
where
abs(prod_clicks - dev_clicks) >= .01
or abs(prod_url_clicks - dev_url_clicks) >= .01
or abs(prod_impressions - dev_impressions) >= .01
or abs(prod_spend - dev_spend) >= .01
or abs(prod_spend_micro - dev_spend_micro) >= .01
{# or abs(prod_total_conversions - dev_total_conversions) >= .01
or abs(total_conversions_sale_amount - dev_total_conversions_sale_amount) >= .01 #}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{ config(
tags="fivetran_validations",
enabled=var('fivetran_validation_tests_enabled', false)
) }}

with prod as (
select
campaign_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_prod.twitter_ads__campaign_report
group by 1
),

dev as (
select
campaign_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_dev.twitter_ads__campaign_report
group by 1
),

final as (
select
prod.campaign_id,
prod.clicks as prod_clicks,
dev.clicks as dev_clicks,
prod.url_clicks as prod_url_clicks,
dev.url_clicks as dev_url_clicks,
prod.impressions as prod_impressions,
dev.impressions as dev_impressions,
prod.spend as prod_spend,
dev.spend as dev_spend,
prod.spend_micro as prod_spend_micro,
dev.spend_micro as dev_spend_micro
{# prod.total_conversions as prod_total_conversions,
dev.total_conversions as dev_total_conversions,
prod.total_conversions_sale_amount as prod_total_conversions_sale_amount,
dev.total_conversions_sale_amount as dev_total_conversions_sale_amount #}
from prod
full outer join dev
on dev.campaign_id = prod.campaign_id
)

select *
from final
where
abs(prod_clicks - dev_clicks) >= .01
or abs(prod_url_clicks - dev_url_clicks) >= .01
or abs(prod_impressions - dev_impressions) >= .01
or abs(prod_spend - dev_spend) >= .01
or abs(prod_spend_micro - dev_spend_micro) >= .01
{# or abs(prod_total_conversions - dev_total_conversions) >= .01
or abs(total_conversions_sale_amount - dev_total_conversions_sale_amount) >= .01 #}
65 changes: 65 additions & 0 deletions integration_tests/tests/consistency/consistency_keyword_report.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{ config(
tags="fivetran_validations",
enabled=var('fivetran_validation_tests_enabled', false)
) }}

with prod as (
select
keyword_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_prod.twitter_ads__keyword_report
group by 1
),

dev as (
select
keyword_id,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend,
sum(spend_micro) as spend_micro,
sum(url_clicks) as url_clicks
{# sum(total_conversions) as total_conversions,
sum(total_conversions_sale_amount) as total_conversions_sale_amount #}
from {{ target.schema }}_twitter_ads_dev.twitter_ads__keyword_report
group by 1
),

final as (
select
prod.keyword_id,
prod.clicks as prod_clicks,
dev.clicks as dev_clicks,
prod.url_clicks as prod_url_clicks,
dev.url_clicks as dev_url_clicks,
prod.impressions as prod_impressions,
dev.impressions as dev_impressions,
prod.spend as prod_spend,
dev.spend as dev_spend,
prod.spend_micro as prod_spend_micro,
dev.spend_micro as dev_spend_micro
{# prod.total_conversions as prod_total_conversions,
dev.total_conversions as dev_total_conversions,
prod.total_conversions_sale_amount as prod_total_conversions_sale_amount,
dev.total_conversions_sale_amount as dev_total_conversions_sale_amount #}
from prod
full outer join dev
on dev.keyword_id = prod.keyword_id
)

select *
from final
where
abs(prod_clicks - dev_clicks) >= .01
or abs(prod_url_clicks - dev_url_clicks) >= .01
or abs(prod_impressions - dev_impressions) >= .01
or abs(prod_spend - dev_spend) >= .01
or abs(prod_spend_micro - dev_spend_micro) >= .01
{# or abs(prod_total_conversions - dev_total_conversions) >= .01
or abs(total_conversions_sale_amount - dev_total_conversions_sale_amount) >= .01 #}
Loading