Skip to content

add conversions #33

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

Merged
merged 34 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2c155be
add conversion dummy fields and pass through backward compat macro
fivetran-reneeli Aug 23, 2024
b5a2adc
add conversion fields to get columns macro
fivetran-reneeli Aug 23, 2024
d9dc3c0
add conversion fields to staging models
fivetran-reneeli Aug 27, 2024
a62cabd
ymls
fivetran-reneeli Aug 28, 2024
b3ba552
add pass through macro backward compat to get columns macro
fivetran-reneeli Aug 29, 2024
447ea76
up versions
fivetran-reneeli Aug 29, 2024
055491c
fix macro ref
fivetran-reneeli Aug 30, 2024
d5b4b80
new seed data with additional test column in ad group table
fivetran-reneeli Aug 30, 2024
0908526
changelog, breaking change version
fivetran-reneeli Aug 30, 2024
41a6944
update seed data
fivetran-reneeli Aug 30, 2024
e79bcd0
string cast advertiser id
fivetran-reneeli Aug 30, 2024
c507c68
string config in integration test yml since thats whats in the get co…
fivetran-reneeli Aug 30, 2024
ec758a1
cast micro dollar fields as bigint, try new schema
fivetran-reneeli Aug 30, 2024
5528f13
update seeds
fivetran-reneeli Sep 3, 2024
4d60143
cast all ids as strings for safe measure
fivetran-reneeli Sep 3, 2024
ca645a7
readme
fivetran-reneeli Sep 3, 2024
5f1d5b9
Merge branch 'main' into add_converions
fivetran-reneeli Sep 3, 2024
958b1a7
oops the merge deleted the macros
fivetran-reneeli Sep 3, 2024
ab8f761
new schema
fivetran-reneeli Sep 4, 2024
99765af
docs
fivetran-reneeli Sep 4, 2024
2b1fc7b
update changelog
fivetran-reneeli Sep 4, 2024
e5ed54d
Merge branch 'main' into add_converions
fivetran-jamie Sep 20, 2024
96a4e39
tweaks
fivetran-jamie Sep 20, 2024
d766f07
coalesce
fivetran-jamie Sep 20, 2024
9a0930c
docs
fivetran-jamie Sep 20, 2024
e6eff80
changelog
fivetran-jamie Sep 20, 2024
9ab30c1
rm advertiser id cast as string note since its now covered in next bu…
fivetran-reneeli Sep 24, 2024
d7c789d
Merge branch 'add_converions' of https://github.com/fivetran/dbt_pint…
fivetran-jamie Oct 17, 2024
0dbcc54
updates
fivetran-jamie Oct 17, 2024
55e46ae
docs
fivetran-jamie Oct 17, 2024
3a5fcbf
headers
fivetran-jamie Oct 17, 2024
0e36d44
changelog
fivetran-jamie Oct 17, 2024
d8ebc27
add note to changelog
fivetran-jamie Oct 18, 2024
d1ec281
rm decision log
fivetran-reneeli Oct 21, 2024
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
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# dbt_pinterest_source v0.11.0

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

## Feature Updates: Native Conversion Support
- We have added the following source fields to each `stg_pinterest_ads__<entity>_report` model:
- `total_conversions`: The sum of all website conversion events.
- `total_conversions_quantity`: The total count of items or units involved in conversions.
- `total_conversions_value` (converted from `total_conversions_value_in_micro_dollar`) Total order value associated with conversions.
- In the event that you were already passing the above fields in via our [passthrough columns](https://github.com/fivetran/dbt_pinterest/blob/main/README.md#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 `pinterest_ads_fill_pass_through_columns` and `pinterest_ads_add_pass_through_columns` macros to ensure that the new conversion fields are backwards compatible with users who have already included them via passthrough fields.
- Explicitly casts `<entity>_id` fields as strings in:
- `stg_pinterest_ads__ad_group_history`
- `stg_pinterest_ads__ad_group_report`
- `stg_pinterest_ads__advertiser_history`
- `stg_pinterest_ads__advertiser_report`
- `stg_pinterest_ads__campaign_history`
- `stg_pinterest_ads__campaign_report`
- `stg_pinterest_ads__keyword_history`
- `stg_pinterest_ads__keyword_report`
- `stg_pinterest_ads__pin_promotion_history`
- `stg_pinterest_ads__pin_promotion_report`
- Updated seed data to represent an e-commerce customer scenario.
- Coalesces `spend` with 0 to ensure proper downstream aggregations.

## Documentation
- Updates the [DECISIONLOG](DECISIONLOG.md) to clarify why there exist differences among aggregations across different grains.

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

# dbt_pinterest_source v0.10.1

[PR #31](https://github.com/fivetran/dbt_pinterest_source/pull/31) includes the following updates:
Expand Down
5 changes: 5 additions & 0 deletions DECISIONLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Why may aggregations across different grains (keywords, ad group, campaign, etc) differ?

Different grains may not always have entire coverage and map out to each other. For example, there may be some ad groups that only feature in campaigns, and not at the ad group level itself. Therefore This means that you can have ad groups sent at the campaign level and that counts towards your total spend. However, since the ad group was never sent at an individual ad group level, it will not be included.

This was a large reason for us breaking the ad reporting package into separate hierarchical end models. Because we found when we only used the ad group level, for example, we were missing data as some ad groups were not served at an ad group level, but were served at a campaign level.
46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ To use this dbt package, you must have the following:

#### Databricks Dispatch Configuration
If you are using a Databricks destination with this package you will need to add the below (or a variation of the below) dispatch configuration within your `dbt_project.yml`. This is required in order for the package to accurately search for macros within the `dbt-labs/spark_utils` then the `dbt-labs/dbt_utils` packages respectively.

```yml
dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']
```

### Step 2: Install the package (skip if also using the `pinterest` transformation package)
If you are **not** using the [Pinterest transformation package](https://github.com/fivetran/dbt_pinterest), include the following pinterest_source package version in your `packages.yml` file.
### Step 2: Install the package (skip if also using the `pinterest` transformation package or `ad_reporting` combo package)
If you are **not** using the [Pinterest transformation package](https://github.com/fivetran/dbt_pinterest) or the [Ad Reporting combination package](https://github.com/fivetran/dbt_ad_reporting), include the following pinterest_source 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.
```yaml

```yml
packages:
- package: fivetran/pinterest_source
version: [">=0.10.0", "<0.11.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.11.0", "<0.12.0"] # we recommend using ranges to capture non-breaking changes automatically
```

### Step 3: Define database and schema variables
By default, this package runs using your destination and the `pinterest` schema. If this is not where your Pinterest Ads data is (for example, if your pinterest schema is named `pinterest_fivetran`), add the following configuration to your root `dbt_project.yml` file:

Expand All @@ -49,15 +52,19 @@ vars:
pinterest_database: your_destination_name
pinterest_schema: your_schema_name
```
#### Step 4: Disabling Keyword Models

### Step 4: Disabling Keyword Models
This package takes into consideration that not every Pinterest account tracks `keyword` performance, and allows you to disable the corresponding functionality by adding the following variable configuration:

```yml
# dbt_project.yml
vars:
pinterest__using_keywords: False # Default = true
```

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

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

Expand All @@ -66,14 +73,15 @@ vars:
pinterest_ads_union_schemas: ['pinterest_usa','pinterest_canada'] # use this if the data is in different schemas/datasets of the same database/project
pinterest_ads_union_databases: ['pinterest_usa','pinterest_canada'] # use this if the data is in different databases/projects but uses the same schema name
```

> NOTE: The native `source.yml` connection set up in the package will not function when the union schema/database feature is utilized. Although the data will be correctly combined, you will not observe the sources linked to the package models in the Directed Acyclic Graph (DAG). This happens because the package includes only one defined `source.yml`.

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` (converted from `spend_in_micro_dollar`), `total_conversions`, `total_conversions_quantity`, and `total_conversions_value` (converted from `total_conversions_value_in_micro_dollar`) 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, total conversions, total conversions quantity, and total conversions value) have been vetted by the Fivetran team maintaining this package for accuracy. There are metrics included within the source reports, for example metric averages, which may be inaccurately represented at the grain for reports created in this package. You will want to ensure whichever metrics you pass through are indeed appropriate to aggregate at the respective reporting levels provided in this package.

```yml
vars:
Expand All @@ -91,34 +99,39 @@ vars:
- name: "other_id"
alias: "another_id"
```

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

```yml
models:
pinterest_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_pinterest_source/blob/main/dbt_project.yml) variable declarations to see the expected names.

```yml
vars:
pinterest_<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>

Fivetran offers the ability for you to orchestrate your dbt project through [Fivetran Transformations for dbt Core™](https://fivetran.com/docs/transformations/dbt). Learn how to set up your project for orchestration through Fivetran in our [Transformations for dbt Core™ setup guides](https://fivetran.com/docs/transformations/dbt#setupguide).

</details>

## Does this package have dependencies?
This dbt package is dependent on the following dbt packages. These dependencies are installed by default within this package. For more information on the following packages, refer to the [dbt hub](https://hub.getdbt.com/) site.
> IMPORTANT: If you have any of these dependent packages in your own `packages.yml` file, we highly recommend that you remove them from your root `packages.yml` to avoid package version conflicts.

```yml
packages:
- package: fivetran/fivetran_utils
Expand All @@ -130,15 +143,20 @@ packages:
- package: dbt-labs/spark_utils
version: [">=0.3.0", "<0.4.0"]
```

## How is this package maintained and can I contribute?
### Package Maintenance
The Fivetran team maintaining this package _only_ maintains the latest version of the package. We highly recommend that you stay consistent with the [latest version](https://hub.getdbt.com/fivetran/pinterest_source/latest/) of the package and refer to the [CHANGELOG](https://github.com/fivetran/dbt_pinterest_source/blob/main/CHANGELOG.md) and release notes for more information on changes across versions.

### 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_pinterest_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_pinterest_source/issues/new/choose) section to find the right avenue of support for you.
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'pinterest_source'
version: '0.10.1'
version: '0.11.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
vars:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

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: pinterest_source_integration_tests_3
schema: pinterest_source_integration_tests_5
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: pinterest_source_integration_tests_3
schema: pinterest_source_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: pinterest_source_integration_tests_3
schema: pinterest_source_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: pinterest_source_integration_tests_3
schema: pinterest_source_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: pinterest_source_integration_tests_3
schema: pinterest_source_integration_tests_5
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
28 changes: 17 additions & 11 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: 'pinterest_source_integration_tests'
version: '0.10.1'
version: '0.11.0'
profile: 'integration_tests'
config-version: 2

vars:
pinterest_schema: pinterest_source_integration_tests_3
pinterest_schema: pinterest_source_integration_tests_5
pinterest_ads_ad_group_history_identifier: "pinterest_ad_group_history_data"
pinterest_ads_campaign_history_identifier: "pinterest_campaign_history_data"
pinterest_ads_pin_promotion_history_identifier: "pinterest_pin_promotion_history_data"
Expand All @@ -15,20 +15,26 @@ vars:
pinterest_ads_campaign_report_identifier: "pinterest_campaign_report_data"
pinterest_ads_advertiser_history_identifier: "pinterest_advertiser_history_data"
pinterest_ads_advertiser_report_identifier: "pinterest_advertiser_report_data"
pinterest__ad_group_report_passthrough_metrics:
- name: "total_conversions"
- name: "total_view_checkout"
alias: "t_view_checkout"

seeds:
+quote_columns: "{{ true if target.type in ('redshift','postgres') else false }}"
pinterest_source_integration_tests:
+column_types:
id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
campaign_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
ad_group_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
pin_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
advertiser_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
ad_account_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
pin_promotion_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"
keyword_id: "{{ 'int64' if target.name == 'bigquery' else 'bigint' }}"

id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
campaign_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
ad_group_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
pin_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
advertiser_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
ad_account_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
pin_promotion_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
keyword_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
spend_in_micro_dollar: "{%- if target.type == 'bigquery' -%} INT64 {%- else -%} bigint {%- endif -%}"
total_conversions_value_in_micro_dollar: "{%- if target.type == 'bigquery' -%} INT64 {%- else -%} bigint {%- endif -%}"

dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']
Loading