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 conversions #24

Merged
merged 4 commits into from
Oct 29, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ target/
dbt_modules/
logs/
.DS_Store
dbt_packages/
dbt_packages/
env/
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_snapchat_ads_source v0.7.0
[PR #24](https://github.com/fivetran/dbt_snapchat_ads_source/pull/24) includes the following **BREAKING CHANGE** updates:

## Feature Updates: Conversion Support
We have added more robust support for conversions in our data models by doing the following:

- Created a `snapchat_ads__conversion_fields` variable to pass through additional conversion fields in the `stg_snapchat_ads__ad_hourly_report`,`stg_snapchat_ads__ad_squad_hourly_report` and `stg_snapchat_ads__campaign_hourly_report` models.
- By default, `snapchat_ads__conversion_fields` will bring in the most used conversion field, `conversion_purchases`. See the [README](https://github.com/fivetran/dbt_snapchat_ads_source/tree/main?tab=readme-ov-file#configuring-conversion-fields) for details on how to adjust this.
- Brought in the `conversion_purchases_value` field to the above mentioned `stg_snapchat_ads__*_hourly_report` models.
> **IMPORTANT**: The above new field additions are **breaking changes** for users who were not already bringing in conversion fields via passthrough columns.

## Documentation Update
- Documented how to use the new `snapchat_ads__conversion_fields` variable [here](https://github.com/fivetran/dbt_snapchat_ads_source/tree/main?tab=readme-ov-file#configuring-conversion-fields).
- Added new metrics to `src` and `stg` yml files.

## Under the Hood
- Updated `snapchat_*_hourly_report_data` seed files with relevant conversion fields for more robust testing.
- Ensured backwards compatibility with existing passthrough column frameworks by creating `snapchat_ads_add_pass_through_columns` and `snapchat_ads_fill_pass_through_columns` macro checks for whether these conversion fields are already brought in by the existing [passthrough variables](https://github.com/fivetran/dbt_reddit_ads_source/tree/main?tab=readme-ov-file#passing-through-additional-metrics). This ensures there are no duplicate column errors if both the new conversion variable and the old passthrough variable are leveraged in any `stg_snapchat_ads__*_hourly_report*` data model.

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

# dbt_snapchat_ads_source v0.6.0
[PR #20](https://github.com/fivetran/dbt_snapchat_ads_source/pull/20) includes the following updates:
## Feature update 🎉
Expand Down
50 changes: 40 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ dispatch:
search_order: ['spark_utils', 'dbt_utils']
```

### Step 2: Install the package (skip if also using the `snapchat_ads` transformation package)
If you are **not** using the [Snapchat Ads transformation package](https://github.com/fivetran/dbt_snapchat_ads), include the following package version in your `packages.yml` file. If you are installing the transform package, the source package is automatically installed as a dependency.
### Step 2: Install the package (skip if also using the `snapchat_ads` transformation package or `ad_reporting` combination package)
If you are **not** using the [Snapchat Ads transformation package](https://github.com/fivetran/dbt_snapchat_ads) and/or [Ad Reporting combination package](https://github.com/fivetran/dbt_ad_reporting), include the following package version in your `packages.yml` file. If you are installing the transform package, the source package is automatically installed as a dependency.
> 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/snapchat_ads_source
version: [">=0.6.0", "<0.7.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.7.0", "<0.8.0"] # we recommend using ranges to capture non-breaking changes automatically
```
### Step 3: Configure your variables

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

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

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

Expand All @@ -67,24 +69,45 @@ 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:

> 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.
By default, this package will select `swipes`, `impressions`, `spend`, `conversion_purchases_value`, and `conversion_purchases` (or whichever fields are specified by the `snapchat_ads__conversion_fields` variable in the next section) 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:

```yml
vars:
snapchat_ads__ad_hourly_passthrough_metrics:
- name: "new_custom_field"
alias: "custom_field"
alias: "custom_field_alias"
transform_sql: "coalesce(custom_field_alias, 0)" # reference the `alias` here if you are using one
- name: "unique_int_field"
alias: "field_id"
- name: "another_one"
transform_sql: "coalesce(another_one, 0)" # reference the `name` here if you're not using an alias
snapchat_ads__ad_squad_hourly_passthrough_metrics:
- name: "this_field"
snapchat_ads__campaign_hourly_report_passthrough_metrics:
- name: "unique_string_field"
alias: "field_id"
```

> **Note**: Make sure to exercise due diligence when adding metrics to these models. The metrics added by default (swipes, impressions, spend, and conversions) 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**: You do NOT need to add conversions in this way. See the following section for an alternative implementation.

#### Configuring Conversion Fields
Separate from the above passthrough metrics, the package will also include conversion metrics based on the `snapchat_ads__conversion_fields` variable, in addition to the `conversion_purchases_value` field.

By default, the data models consider `conversion_purchases` to be conversions. These should cover most use cases, but, say, if you would like to consider adding payment info, adding to wishlist, adding to the cart, etc. to also be conversions, you would apply the following configuration with the **original** source names of the conversion fields (not aliases you provided in the section above):

```yml
# dbt_project.yml
vars:
snapchat_ads__conversion_fields: ['conversion_purchases', 'conversion_add_billing', 'conversion_save', 'conversion_add_cart']
```

> We introduced support for conversion fields in our `*_hourly_report` data models in the [v0.7.0 release](https://github.com/fivetran/dbt_snapchat_ads_source/releases/tag/v0.7.0) of the package, but customers might have been bringing in these conversion fields earlier using the passthrough fields variables. The data models will avoid "duplicate column" errors automatically if this is the case.

#### 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_snapchat_ads_source/blob/main/dbt_project.yml) variable declarations to see the expected names.

```yml
Expand All @@ -93,14 +116,16 @@ vars:
```

#### Change the build schema
By default, this package builds the Snapchat Ads staging models within a schema titled (`<target_schema>` + `_stg_snapchat_ads`) in your destination. If this is not where you would like your Snapchat Ads staging data to be written to, add the following configuration to your root `dbt_project.yml` file:
By default, this package builds the Snapchat Ads staging models (9 views, 9 tables) within a schema titled (`<target_schema>` + `_stg_snapchat_ads`) in your destination. If this is not where you would like your Snapchat Ads staging data to be written to, add the following configuration to your root `dbt_project.yml` file:

```yml
models:
snapchat_ads_source:
+schema: my_new_schema_name # leave blank for just the target_schema
```

</details>

### (Optional) Step 5: Orchestrate your models with Fivetran Transformations for dbt Core™

<details><summary>Expand for more details</summary>
Expand Down Expand Up @@ -135,7 +160,12 @@ 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) to learn how to contribute to a dbt package.
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_snapchat_ads_source/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_snapchat_ads_source/issues/new/choose) section to find the right avenue of support for you.
Expand Down
3 changes: 2 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'snapchat_ads_source'
version: '0.6.0'
version: '0.7.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
vars:
Expand All @@ -16,6 +16,7 @@ vars:
snapchat_ads__ad_hourly_passthrough_metrics: []
snapchat_ads__ad_squad_hourly_passthrough_metrics: []
snapchat_ads__campaign_hourly_report_passthrough_metrics: []
snapchat_ads__conversion_fields: ['conversion_purchases']
models:
snapchat_ads_source:
+schema: snapchat_ads_source
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: snapchat_ads_source_integration_tests
schema: snapchat_ads_source_integration_tests_1
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: snapchat_ads_source_integration_tests
schema: snapchat_ads_source_integration_tests_1
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: snapchat_ads_source_integration_tests
schema: snapchat_ads_source_integration_tests_1
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: snapchat_ads_source_integration_tests
schema: snapchat_ads_source_integration_tests_1
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: snapchat_ads_source_integration_tests
schema: snapchat_ads_source_integration_tests_1
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
11 changes: 9 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: 'snapchat_ads_source_integration_tests'

version: '0.6.0'
version: '0.7.0'
profile: 'integration_tests'
config-version: 2

vars:
snapchat_ads_schema: snapchat_ads_source_integration_tests
snapchat_ads_schema: snapchat_ads_source_integration_tests_1
snapchat_ads_ad_account_history_identifier: "snapchat_ad_account_history_data"
snapchat_ads_ad_history_identifier: "snapchat_ad_history_data"
snapchat_ads_ad_hourly_report_identifier: "snapchat_ad_hourly_report_data"
Expand All @@ -16,6 +16,13 @@ vars:
snapchat_ads_creative_history_identifier: "snapchat_creative_history_data"
snapchat_ads_creative_url_tag_history_identifier: "snapchat_creative_url_tag_history_data"

snapchat_ads__conversion_fields: ['conversion_purchases']
snapchat_ads__ad_hourly_passthrough_metrics:
- name: conversion_add_billing
- name: conversion_purchases
alias: conversion_purchases_alias
- name: conversion_page_views

dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ dbt-redshift>=1.3.0,<2.0.0
dbt-postgres>=1.3.0,<2.0.0
dbt-spark>=1.3.0,<2.0.0
dbt-spark[PyHive]>=1.3.0,<2.0.0
dbt-databricks>=1.3.0,<2.0.0
dbt-databricks>=1.6.0,<2.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for this change? Is there something in a previous dbt-databricks version that isn't supported in these changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real reason, just saw that this was inconsistent with the requirement.txt files of some other packages. Happy to revert if preferable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. This is fine to keep, I just wanted to make sure there wasn't a particular reason and if we had to change the required dbt version range. But this looks fine to keep thanks!

Loading