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

[Feature] Add conversion metrics #20

Merged
merged 9 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/
dbt_packages/
env/
.DS_Store
.DS_Store
package-lock.yml
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# dbt_tiktok_ads v0.6.0
[PR #20](https://github.com/fivetran/dbt_tiktok_ads/pull/20) includes the following **BREAKING CHANGE** updates:

# Feature Updates: Conversion Support
- We have added the following source fields to each `tiktok_ads` end model (note that the `conversion` field was already present):
- `real_time_conversion`: Number of times your ad resulted in the optimization event and timeframe you selected.
- `total_purchase_value`: The total value of purchase events that occurred in your app that were recorded by your measurement partner.
- `total_sales_lead_value`: The monetary worth or potential value assigned to a lead generated through ads.
- `total_conversion_value`: The accumulated value of `total_purchase_value` and `total_sales_lead_value`.

- In the event that you were already passing the above fields in via our [passthrough columns](https://github.com/fivetran/dbt_tiktok_ads?tab=readme-ov-file#passing-through-additional-metrics), the package will dynamically avoid "duplicate column" errors.
> The above new field additions are **breaking changes** for users who were not already bringing in conversion fields via passthrough columns.

## Under the Hood
- Created `tiktok_ads_persist_pass_through_columns` macro to ensure that the new conversion fields are backwards compatible with users who have already included them via passthrough fields.
- Updated `conversion` field to be an integer rather than a numeric data type in the `tiktok_ads_source` package, as is the expected behavior of the field. **This is a breaking change.**
- Added integrity and consistency validation tests within `integration_tests` folder for the transformation models (to be used by maintainers only).
- Updated seed data to adequately test new field additions in integration tests.

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

# dbt_tiktok_ads v0.5.0
[PR #13](https://github.com/fivetran/dbt_tiktok_ads/pull/13) includes the following updates:

Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ dispatch:
search_order: ['spark_utils', 'dbt_utils']
```

### Step 2: Install the package
Include the following tiktok_ads package version in your `packages.yml` file:
### Step 2: Install the package (skip if also using the `ad_reporting` combo package)
Include the following tiktok_ads package version in your `packages.yml` file _if_ you are not also using the upstream [Ad Reporting combination package](https://github.com/fivetran/dbt_ad_reporting):
> 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.

```yaml
packages:
- package: fivetran/tiktok_ads
version: [">=0.5.0", "<0.6.0"]
version: [">=0.6.0", "<0.7.0"]

```
Do **NOT** include the `tiktok_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 @@ -70,6 +71,9 @@ vars:
For additional configurations for the source models, visit the [Tiktok Ads source package](https://github.com/fivetran/dbt_tiktok_ads_source).

### (Optional) Step 4: Additional configurations

<details open><summary>Expand/Collapse details</summary>

#### Union multiple connectors
If you have multiple tiktok_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 `tiktok_ads_union_schemas` OR `tiktok_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

Expand All @@ -83,9 +87,9 @@ 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.

#### 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:
By default, this package will select `clicks`, `impressions`, `spend` , `conversion`, `real_time_conversion`, `total_purchase_value`, and `total_sales_lead_value` 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.
> IMPORTANT: Make sure to exercise due diligence when adding metrics to these models. The metrics added by default (clicks, impressions, spend, and various conversion metrics) 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.

```yml
vars:
Expand All @@ -101,22 +105,19 @@ vars:
```

#### Change the build schema
By default, this package will build the TikTok Ads staging models within a schema titled (`<target_schema>` + `_stg_tiktok_ads`) and the final TikTok Ads models within a schema titled (`<target_schema>` + `_tiktok_ads`) in your target database. If this is not where you would like your modeled TikTok data to be written to, add the following configuration to your `dbt_project.yml` file:
By default, this package will build the TikTok Ads staging models (7 views, 7 tables) within a schema titled (`<target_schema>` + `_stg_tiktok_ads`) and the final TikTok Ads models (5 tables) within a schema titled (`<target_schema>` + `_tiktok_ads`) in your target database. If this is not where you would like your modeled TikTok data to be written to, add the following configuration to your `dbt_project.yml` file:

```yml
# dbt_project.yml

...
models:
tiktok_ads:
+schema: my_new_schema_name # leave blank for just the target_schema
tiktok_ads_source:
+schema: my_new_schema_name # leave blank for just the target_schema
```


#### Change the source table references
If an individual source table has a different name than the package expects, add the table name as it appears in your destination to the respective variable:
If an individual source table has a different name than the package expects, add the table name as it appears in your destination to the respective variable. This is not available when running the package on multiple unioned connectors.

> IMPORTANT: See this project's [`dbt_project.yml`](https://github.com/fivetran/dbt_tiktok_ads/blob/main/dbt_project.yml) variable declarations to see the expected names.

Expand All @@ -125,6 +126,8 @@ vars:
tiktok_ads_<default_source_table_name>_identifier: your_table_name
```

</details>

### (Optional) Step 5: Orchestrate your models with Fivetran Transformations for dbt Core™
<details><summary>Expand for more details</summary>
<br>
Expand All @@ -140,7 +143,7 @@ This dbt package is dependent on the following dbt packages. These dependencies
```yml
packages:
- package: fivetran/tiktok_ads_source
version: [">=0.5.0", "<0.6.0"]
version: [">=0.6.0", "<0.7.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
Expand All @@ -160,6 +163,11 @@ A small team of analytics engineers at Fivetran develops these dbt packages. How

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_tiktok_ads/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_tiktok_ads/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).
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'tiktok_ads'
version: '0.5.0'
version: '0.6.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
Expand Down
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.

10 changes: 5 additions & 5 deletions integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ integration_tests:
pass: "{{ env_var('CI_REDSHIFT_DBT_PASS') }}"
dbname: "{{ env_var('CI_REDSHIFT_DBT_DBNAME') }}"
port: 5439
schema: tiktok_ads_integration_tests_4
schema: tiktok_ads_integration_tests_5
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: tiktok_ads_integration_tests_4
schema: tiktok_ads_integration_tests_5
threads: 8
keyfile_json: "{{ env_var('GCLOUD_SERVICE_KEY') | as_native }}"
snowflake:
Expand All @@ -33,7 +33,7 @@ integration_tests:
role: "{{ env_var('CI_SNOWFLAKE_DBT_ROLE') }}"
database: "{{ env_var('CI_SNOWFLAKE_DBT_DATABASE') }}"
warehouse: "{{ env_var('CI_SNOWFLAKE_DBT_WAREHOUSE') }}"
schema: tiktok_ads_integration_tests_4
schema: tiktok_ads_integration_tests_5
threads: 8
postgres:
type: postgres
Expand All @@ -42,13 +42,13 @@ integration_tests:
pass: "{{ env_var('CI_POSTGRES_DBT_PASS') }}"
dbname: "{{ env_var('CI_POSTGRES_DBT_DBNAME') }}"
port: 5432
schema: tiktok_ads_integration_tests_4
schema: tiktok_ads_integration_tests_5
threads: 8
databricks:
catalog: "{{ env_var('CI_DATABRICKS_DBT_CATALOG') }}"
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
schema: tiktok_ads_integration_tests_4
schema: tiktok_ads_integration_tests_5
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
12 changes: 10 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: 'tiktok_ads_integration_tests'
version: '0.5.0'
version: '0.6.0'
profile: 'integration_tests'
config-version: 2

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

vars:
tiktok_ads_source:
tiktok_ads_schema: tiktok_ads_integration_tests_4
tiktok_ads_schema: tiktok_ads_integration_tests_5
tiktok_ads_adgroup_history_identifier: "tiktok_adgroup_history_data"
tiktok_ads_ad_history_identifier: "tiktok_ad_history_data"
tiktok_ads_advertiser_identifier: "tiktok_advertiser_data"
Expand All @@ -14,6 +17,11 @@ vars:
tiktok_ads_adgroup_report_hourly_identifier: "tiktok_adgroup_report_hourly_data"
tiktok_ads_campaign_report_hourly_identifier: "tiktok_campaign_report_hourly_data"

tiktok_ads__ad_group_hourly_passthrough_metrics:
- name: total_purchase_value
- name: total_sales_lead_value
alias: total_sales_lead_value_aliased

seeds:
+quote_columns: "{{ true if target.type == 'redshift' else false }}"

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: ../
10 changes: 5 additions & 5 deletions integration_tests/seeds/tiktok_ad_report_hourly_data.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AD_ID,STAT_TIME_HOUR,COST_PER_CONVERSION,REAL_TIME_CONVERSION,CPC,VIDEO_PLAY_ACTIONS,CONVERSION_RATE,VIDEO_VIEWS_P_75,RESULT,VIDEO_VIEWS_P_50,IMPRESSIONS,COMMENTS,REAL_TIME_COST_PER_RESULT,CONVERSION,REAL_TIME_RESULT,VIDEO_VIEWS_P_100,SHARES,REAL_TIME_CONVERSION_RATE,COST_PER_SECONDARY_GOAL_RESULT,SECONDARY_GOAL_RESULT_RATE,CLICKS,COST_PER_1000_REACHED,VIDEO_VIEWS_P_25,REACH,REAL_TIME_COST_PER_CONVERSION,PROFILE_VISITS_RATE,AVERAGE_VIDEO_PLAY,PROFILE_VISITS,CPM,CTR,VIDEO_WATCHED_2_S,FOLLOWS,RESULT_RATE,VIDEO_WATCHED_6_S,SECONDARY_GOAL_RESULT,COST_PER_RESULT,AVERAGE_VIDEO_PLAY_PER_USER,REAL_TIME_RESULT_RATE,SPEND,LIKES,_FIVETRAN_SYNCED
1,2021-09-15 10:00:00,0,0,0,22,0,2,0,2,23,0,0,0,0,0,0,0,-,-,0,0,22,0,0,0,2.22,0,32.22,0,2,0,0,22,-,0,0,0,2.22,0,2021-09-15 15:56:34.862
2,2021-09-15 10:00:00,0,0,0,33,0,0,0,0,22,0,0,0,0,0,0,0,-,-,0,0,3,0,0,0,2.22,0,2.22,0,2,0,0,2,-,0,0,0,0.22,0,2021-09-15 15:56:34.953
3,2021-09-15 10:00:00,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,-,-,0,0,0,0,0,0,2.22,0,0,0,0,0,0,0,-,0,0,0,0,0,2021-09-15 15:56:34.923
4,2021-09-15 10:00:00,0.22,2,0.22,22,222,2,2,2,22,0,0.22,2,2,2,0,200,-,-,2,0,2,0,0.22,0,2.22,0,22.22,2.22,2,0,100,2,-,0.22,0,222,0.22,2,2021-09-15 15:56:34.950
AD_ID,STAT_TIME_HOUR,COST_PER_CONVERSION,CPC,VIDEO_PLAY_ACTIONS,CONVERSION_RATE,VIDEO_VIEWS_P_75,RESULT,VIDEO_VIEWS_P_50,IMPRESSIONS,COMMENTS,REAL_TIME_COST_PER_RESULT,CONVERSION,REAL_TIME_RESULT,VIDEO_VIEWS_P_100,SHARES,REAL_TIME_CONVERSION_RATE,COST_PER_SECONDARY_GOAL_RESULT,SECONDARY_GOAL_RESULT_RATE,CLICKS,COST_PER_1000_REACHED,VIDEO_VIEWS_P_25,REACH,REAL_TIME_COST_PER_CONVERSION,PROFILE_VISITS_RATE,AVERAGE_VIDEO_PLAY,PROFILE_VISITS,CPM,CTR,VIDEO_WATCHED_2_S,FOLLOWS,RESULT_RATE,VIDEO_WATCHED_6_S,SECONDARY_GOAL_RESULT,COST_PER_RESULT,AVERAGE_VIDEO_PLAY_PER_USER,REAL_TIME_RESULT_RATE,SPEND,LIKES,REAL_TIME_CONVERSION,TOTAL_PURCHASE_VALUE,TOTAL_SALES_LEAD_VALUE,_FIVETRAN_SYNCED
1,2021-09-15 10:00:00,0,0,22,0,2,0,2,23,0,0,0,0,0,0,0,-,-,0,0,22,0,0,0,2.22,0,32.22,0,2,0,0,22,-,0,0,0,2.22,0,0,0.00,0.00,2021-09-15 15:56:34.862
2,2021-09-15 10:00:00,0,0,33,0,0,0,0,22,0,0,0,0,0,0,0,-,-,0,0,3,0,0,0,2.22,0,2.22,0,2,0,0,2,-,0,0,0,0.22,0,0,0.01,0.01,2021-09-15 15:56:34.953
3,2021-09-15 10:00:00,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,-,-,0,0,0,0,0,0,2.22,0,0,0,0,0,0,0,-,0,0,0,0,0,0,0.00,0.00,2021-09-15 15:56:34.923
4,2021-09-15 10:00:00,0.22,0.22,22,222,2,2,2,22,0,0.22,2,2,2,0,200,-,-,2,0,2,0,0.22,0,2.22,0,22.22,2.22,2,0,100,2,-,0.22,0,222,0.22,2,2,0.00,0.00,2021-09-15 15:56:34.950
10 changes: 5 additions & 5 deletions integration_tests/seeds/tiktok_adgroup_report_hourly_data.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADGROUP_ID,STAT_TIME_HOUR,COST_PER_CONVERSION,REAL_TIME_CONVERSION,CPC,VIDEO_PLAY_ACTIONS,CONVERSION_RATE,VIDEO_VIEWS_P_75,RESULT,VIDEO_VIEWS_P_50,IMPRESSIONS,COMMENTS,REAL_TIME_COST_PER_RESULT,CONVERSION,REAL_TIME_RESULT,VIDEO_VIEWS_P_100,SHARES,REAL_TIME_CONVERSION_RATE,COST_PER_SECONDARY_GOAL_RESULT,SECONDARY_GOAL_RESULT_RATE,CLICKS,COST_PER_1000_REACHED,VIDEO_VIEWS_P_25,REACH,REAL_TIME_COST_PER_CONVERSION,PROFILE_VISITS_RATE,AVERAGE_VIDEO_PLAY,PROFILE_VISITS,CPM,CTR,VIDEO_WATCHED_2_S,FOLLOWS,RESULT_RATE,VIDEO_WATCHED_6_S,SECONDARY_GOAL_RESULT,COST_PER_RESULT,AVERAGE_VIDEO_PLAY_PER_USER,REAL_TIME_RESULT_RATE,SPEND,LIKES,_FIVETRAN_SYNCED
1,2021-09-15 5:00:00,0,0,1.77,555,0,33,0,38,32,0,0,0,0,3,0,0,-,-,2,18.44,150,333,0,0,5,0,17.99,1.22,333,0,0,133,-,0,4.66,0,7.6,3,2021-09-15 15:57:22.614
2,2021-09-15 7:00:00,1.33,7,0.76,1111,39,33,5,33,3235,0,4.123,5,3,44,0,43.22,-,-,34,0,150,0,1.75,0,3.33,0,13.66,1.44,333,0,36.77,233,-,2.3342,0,38.88,17.22,3,2021-09-15 15:57:22.606
3,2021-09-15 7:00:00,3.23,7,1,2222,33,33,7,443,3235,0,2.353,5,7,55,0,22,-,-,33,0,333,0,4.44,0,4.22,0,11.88,1.55,334,0,34,233,-,3.6212,0,22,25.33,4,2021-09-15 15:57:22.616
4,2021-09-15 4:00:00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-,-,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-,0,0,0,0,0,2021-09-15 15:57:22.616
ADGROUP_ID,STAT_TIME_HOUR,COST_PER_CONVERSION,CPC,VIDEO_PLAY_ACTIONS,CONVERSION_RATE,VIDEO_VIEWS_P_75,RESULT,VIDEO_VIEWS_P_50,IMPRESSIONS,COMMENTS,REAL_TIME_COST_PER_RESULT,CONVERSION,REAL_TIME_RESULT,VIDEO_VIEWS_P_100,SHARES,REAL_TIME_CONVERSION_RATE,COST_PER_SECONDARY_GOAL_RESULT,SECONDARY_GOAL_RESULT_RATE,CLICKS,COST_PER_1000_REACHED,VIDEO_VIEWS_P_25,REACH,REAL_TIME_COST_PER_CONVERSION,PROFILE_VISITS_RATE,AVERAGE_VIDEO_PLAY,PROFILE_VISITS,CPM,CTR,VIDEO_WATCHED_2_S,FOLLOWS,RESULT_RATE,VIDEO_WATCHED_6_S,SECONDARY_GOAL_RESULT,COST_PER_RESULT,AVERAGE_VIDEO_PLAY_PER_USER,REAL_TIME_RESULT_RATE,SPEND,LIKES,REAL_TIME_CONVERSION,TOTAL_PURCHASE_VALUE,TOTAL_SALES_LEAD_VALUE,_FIVETRAN_SYNCED
1,2021-09-15 5:00:00,0,1.77,555,0,33,0,38,32,0,0,0,0,3,0,0,-,-,2,18.44,150,333,0,0,5,0,17.99,1.22,333,0,0,133,-,0,4.66,0,7.6,3,0,0.00,0.00,2021-09-15 15:57:22.614
2,2021-09-15 7:00:00,1.33,0.76,1111,39,33,5,33,3235,0,4.123,2,3,44,0,43.22,-,-,34,0,150,0,1.75,0,3.33,0,13.66,1.44,333,0,36.77,233,-,2.3342,0,38.88,17.22,3,2,0.01,0.01,2021-09-15 15:57:22.606
3,2021-09-15 7:00:00,3.23,1,2222,33,33,7,443,3235,0,2.353,0,7,55,0,22,-,-,33,0,333,0,4.44,0,4.22,0,11.88,1.55,334,0,34,233,-,3.6212,0,22,25.33,4,0,0.00,0.00,2021-09-15 15:57:22.616
4,2021-09-15 4:00:00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-,-,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-,0,0,0,0,0,0,0.00,0.00,2021-09-15 15:57:22.616
Loading