Skip to content

Commit

Permalink
Feature/conversions (#7)
Browse files Browse the repository at this point in the history
* add new conversion report tables

* fix naming and docs

* seed

* version

* bring in passthrough variable and mod documentation and readme

* docs

* more updates

* alias

* add to integration test yml

* docs

* add reddit ads enable config

* updates

* readme and docs

* add decisionlog about discrepancies across different grains

* changelog

* casting date as date in macro

* add coalesce

* cull down columns

* polish up

* tweak

* changelog

* reword

* change base to tmp and add changelog note

---------

Co-authored-by: Jamie Rodriguez <[email protected]>
  • Loading branch information
fivetran-reneeli and fivetran-jamie authored Oct 24, 2024
1 parent db8bd8f commit 6c7f5e8
Show file tree
Hide file tree
Showing 33 changed files with 809 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target/
dbt_modules/
logs/
env/
dbt_packages/
dbt_packages/
integration_tests/package-lock.yml
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# dbt_reddit_ads_source v0.3.0
[PR #7](https://github.com/fivetran/dbt_reddit_ads_source/pull/7) includes the following **BREAKING CHANGE** updates:

## Feature: Conversion Metrics
- Introduces 4 new staging models to bring in conversion metrics (click-through conversions, view-through conversions, total value, and total items) across different dimensions:
- `stg_reddit_ads__account_conversions_report`
- `stg_reddit_ads__ad_group_conversions_report`
- `stg_reddit_ads__ad_conversions_report`
- `stg_reddit_ads__campaign_conversions_report`
> Note: If you would like to include conversion metrics, please ensure you have the `account_conversions_report`, `ad_group_conversions_report`, `ad_conversions_report`, and `campaign_conversions_report` source tables syncing in your Reddit Ads connector(s). Otherwise, the package will run successfully but produce `null` conversion metric values.
- Introduces the `<entity>_conversions_passthrough_metrics` variables to allow additional fields from the source `*_conversion_report` tables. We use the maximum attribution window when considering conversions and therefore retrieve conversions metrics from the `click_through_conversion_attribution_window_month` (conversions) and `view_through_conversion_attribution_window_month` (view_through_conversions) fields from the respective source tables. For information on how to configure these variables to bring in additional windows and fields into the `stg_<entity>_conversions_report` models, refer to the [README](https://github.com/fivetran/dbt_reddit_ads_source/tree/main?tab=readme-ov-file#passing-through-additional-metrics).

## Under the hood
- Coalesces each pre-existing metrics (ie `clicks`, `impressions`, and `spend`) with `0` to avoid the complications of `null` in downstream aggregations.
- Adds the respective seed data for the new models in addition to updating relevant documentation.
- Adds documentation explaining potential discrepancies across reporting grains.

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

# dbt_reddit_ads_source v0.2.0
[PR #5](https://github.com/fivetran/dbt_reddit_ads_source/pull/5) includes the following updates:
## Feature update 🎉
Expand Down
4 changes: 4 additions & 0 deletions DECISIONLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Why don't metrics add up across different grains (Ex. ad level vs campaign level)?
When aggregating metrics like clicks and spend across different grains, discrepancies can arise due to differences in how data is captured, grouped, or attributed at each grain. For example, certain actions or costs might be attributed differently at the ad, campaign, or ad group level, leading to inconsistencies when rolled up. Additionally, for example, at the keyword grain, where a keyword can belong to multiple ad groups, aggregations can lead to over counting. Conversely, some ads may only be represented at the ad group level, rather than individual ad levels, leading to under counting at the ad grain.

This is a reason why we have broken out the ad reporting packages into separate hierarchical end models (Ad, Ad Group, Campaign, and more). Because if we only used ad-level reports, we could be missing data.
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ dispatch:
search_order: ['spark_utils', 'dbt_utils']
```
### Step 2: Install the package
Include the following reddit_ads_source package version in your `packages.yml` file.
### Step 2: Install the package (skip if also using the `reddit_ads` transformation or `ad_reporting` combo package)
If you are _not_ using the [Reddit Ads](https://github.com/fivetran/dbt_reddit_ads) transformation package or the [Ad Reporting](https://github.com/fivetran/dbt_ad_reporting) combination package, include the following reddit_ads_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
packages:
- package: fivetran/reddit_ads_source
version: [">=0.2.0", "<0.3.0"]
version: [">=0.3.0", "<0.4.0"]
```
### Step 3: Define database and schema variables
By default, this package runs using your destination and the `reddit_ads` schema. If this is not where your Reddit Ads data is (for example, if your `reddit_ads` schema is named `reddit_ads_fivetran`), add the following configuration to your root `dbt_project.yml` file:
Expand All @@ -51,6 +51,8 @@ vars:
```

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

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

Expand All @@ -64,9 +66,11 @@ 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 `spend` 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 following configurations to your `dbt_project.yml` file. These variables allow the pass-through fields to be aliased (`alias`) if desired, but not required. Use the following format for declaring the respective pass-through variables:
By default, this package will select `clicks`, `impressions`, `spend`, `conversions` (aliased from `click_through_conversion_attribution_window_month` source field), `view_through_conversions` (aliased from `view_through_conversion_attribution_window_month` source field), `total_items`, and `total_value` from the source reporting tables to store into the staging models. Note that we choose the maximum attribution window for counting conversions.

If you would like to pass through additional metrics to the staging models, for example, different attribution windows for conversions such as `view_through_conversion_attribution_window_week`, add the following configurations to your `dbt_project.yml` file. These variables allow the pass-through fields to be aliased (`alias`) if desired, but not required. Use the following format for declaring the respective pass-through variables:

> **NOTE** Ensure you exercised due diligence when adding metrics to these models. The metrics added by default (clicks, impressions, and cost) 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 want to ensure whichever metrics you pass through are indeed appropriate to aggregate at the respective reporting levels provided in this package.
> **NOTE** Make sure to exercise due diligence when adding metrics to these models. The metrics added by default (clicks, impressions, cost, conversions, view-through conversions, total items, and total 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 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 @@ -81,10 +85,18 @@ vars:
- name: "new_custom_field"
alias: "custom_field"
- name: "a_second_field"
reddit_ads__account_conversions_passthrough_metrics:
- name: "view_through_conversion_attribution_window_week"
reddit_ads__ad_group_conversions_passthrough_metrics:
- name: "view_through_conversion_attribution_window_week"
reddit_ads__ad_conversions_passthrough_metrics:
- name: "view_through_conversion_attribution_window_week"
reddit_ads__campaign_conversions_passthrough_metrics:
- name: "view_through_conversion_attribution_window_week"
```

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

```yml
models:
Expand All @@ -93,14 +105,16 @@ models:
```

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

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

Expand Down Expand Up @@ -130,7 +144,12 @@ The Fivetran team maintaining this package _only_ maintains the latest version o
### 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_reddit_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_reddit_ads_source/issues/new/choose) section to find the right avenue of support for you.
Expand Down
12 changes: 10 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'reddit_ads_source'
version: '0.2.0'
version: '0.3.0'

config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
Expand All @@ -21,7 +21,15 @@ vars:
ad_report: "{{ source('reddit_ads','ad_report') }}"
campaign: "{{ source('reddit_ads','campaign') }}"
campaign_report: "{{ source('reddit_ads', 'campaign_report') }}"
account_conversions_report: "{{ source('reddit_ads','account_conversions_report') }}"
ad_group_conversions_report: "{{ source('reddit_ads','ad_group_conversions_report') }}"
ad_conversions_report: "{{ source('reddit_ads','ad_conversions_report') }}"
campaign_conversions_report: "{{ source('reddit_ads','campaign_conversions_report') }}"
reddit_ads__account_passthrough_metrics: []
reddit_ads__ad_group_passthrough_metrics: []
reddit_ads__ad_passthrough_metrics: []
reddit_ads__campaign_passthrough_metrics: []
reddit_ads__campaign_passthrough_metrics: []
reddit_ads__account_conversions_passthrough_metrics: []
reddit_ads__ad_group_conversions_passthrough_metrics: []
reddit_ads__ad_conversions_passthrough_metrics: []
reddit_ads__campaign_conversions_passthrough_metrics: []
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.

18 changes: 16 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
name: 'reddit_ads_source_integration_tests'
version: '0.2.0'
version: '0.3.0'

profile: 'integration_tests'
config-version: 2

vars:
vars:
reddit_ads_schema: reddit_ads_source_integration_tests
reddit_ads_account_identifier: "reddit_ads_account_data"
reddit_ads_account_report_identifier: "reddit_ads_account_report_data"
reddit_ads_account_conversions_report_identifier: "reddit_ads_account_conversions"
reddit_ads_ad_identifier: "reddit_ads_ad_data"
reddit_ads_ad_report_identifier: "reddit_ads_ad_report_data"
reddit_ads_ad_conversions_report_identifier: "reddit_ads_ad_conversions"
reddit_ads_ad_group_identifier: "reddit_ads_ad_group_data"
reddit_ads_ad_group_report_identifier: "reddit_ads_ad_group_report_data"
reddit_ads_ad_group_conversions_report_identifier: "reddit_ads_ad_group_conversions"
reddit_ads_campaign_identifier: "reddit_ads_campaign_data"
reddit_ads_campaign_report_identifier: "reddit_ads_campaign_report_data"
reddit_ads_campaign_conversions_report_identifier: "reddit_ads_campaign_conversions"

reddit_ads__campaign_conversions_passthrough_metrics:
- name: avg_value
reddit_ads__account_conversions_passthrough_metrics:
- name: view_through_conversion_attribution_window_week
reddit_ads__ad_conversions_passthrough_metrics:
- name: click_through_conversion_attribution_window_week
reddit_ads__ad_group_conversions_passthrough_metrics:
- name: view_through_conversion_attribution_window_day

dispatch:
- macro_namespace: dbt_utils
search_order: ['spark_utils', 'dbt_utils']
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/seeds/reddit_ads_account_conversions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_fivetran_synced,account_id,avg_value,click_through_conversion_attribution_window_day,click_through_conversion_attribution_window_month,click_through_conversion_attribution_window_week,date,event_name,total_items,total_value,view_through_conversion_attribution_window_day,view_through_conversion_attribution_window_month,view_through_conversion_attribution_window_week
2023-01-10 12:00:00,1234,25.50,10,15,7,2022-10-09,purchase,5,127.50,1,3,2
2023-01-10 12:00:00,1234,30.75,10,15,7,2022-10-10,purchase,8,246.00,1,3,2
2023-01-10 12:00:00,1234,22.80,10,15,7,2022-10-11,purchase,6,136.80,1,3,2
2023-01-10 12:00:00,1234,28.60,10,15,7,2022-10-12,purchase,7,200.20,1,3,2
2023-01-10 12:00:00,1234,35.20,10,15,7,2022-10-13,purchase,9,316.80,1,3,2
2023-01-10 12:00:00,1234,27.90,10,15,7,2022-10-14,purchase,6,167.40,1,3,2
2023-01-10 12:00:00,1234,31.50,10,15,7,2022-10-15,purchase,4,126.00,1,3,2
2023-01-10 12:00:00,1234,29.75,10,15,7,2022-10-16,purchase,8,238.00,1,3,2
9 changes: 9 additions & 0 deletions integration_tests/seeds/reddit_ads_ad_conversions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_fivetran_synced,account_id,ad_id,avg_value,click_through_conversion_attribution_window_day,click_through_conversion_attribution_window_month,click_through_conversion_attribution_window_week,date,event_name,total_items,total_value,view_through_conversion_attribution_window_day,view_through_conversion_attribution_window_month,view_through_conversion_attribution_window_week
2023-01-10 12:00:00,1234,1510393835426777445,27.50,10,15,7,2022-10-09,purchase,2,55.00,1,3,2
2023-01-10 12:00:00,1234,1510393835426777445,32.75,10,15,7,2022-10-10,purchase,3,98.25,1,3,2
2023-01-10 12:00:00,1234,1522247232378637129,24.80,10,15,7,2022-10-11,purchase,2,49.60,1,3,2
2023-01-10 12:00:00,1234,1522247232378637129,30.60,10,15,7,2022-10-12,purchase,3,91.80,1,3,2
2023-01-10 12:00:00,1234,1535743348805779455,37.20,10,15,7,2022-10-13,purchase,4,148.80,1,3,2
2023-01-10 12:00:00,1234,1535743348805779455,29.90,10,15,7,2022-10-14,purchase,2,59.80,1,3,2
2023-01-10 12:00:00,1234,1542438385001795138,33.50,10,15,7,2022-10-15,purchase,1,33.50,1,3,2
2023-01-10 12:00:00,1234,1542438385001795138,31.75,10,15,7,2022-10-16,purchase,3,95.25,1,3,2
9 changes: 9 additions & 0 deletions integration_tests/seeds/reddit_ads_ad_group_conversions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_fivetran_synced,account_id,ad_group_id,avg_value,click_through_conversion_attribution_window_day,click_through_conversion_attribution_window_month,click_through_conversion_attribution_window_week,date,event_name,total_items,total_value,view_through_conversion_attribution_window_day,view_through_conversion_attribution_window_month,view_through_conversion_attribution_window_week
2023-01-10 12:00:00,1234,1510393829097718070,28.50,10,15,7,2022-10-09,purchase,1,28.50,1,3,2
2023-01-10 12:00:00,1234,1510393829097718070,33.75,10,15,7,2022-10-10,purchase,2,67.50,1,3,2
2023-01-10 12:00:00,1234,1522247226241194321,25.80,10,15,7,2022-10-11,purchase,1,25.80,1,3,2
2023-01-10 12:00:00,1234,1522247226241194321,31.60,10,15,7,2022-10-12,purchase,2,63.20,1,3,2
2023-01-10 12:00:00,1234,1535743345604192832,38.20,10,15,7,2022-10-13,purchase,3,114.60,1,3,2
2023-01-10 12:00:00,1234,1535743345604192832,30.90,10,15,7,2022-10-14,purchase,1,30.90,1,3,2
2023-01-10 12:00:00,1234,1542438363648999385,34.50,10,15,7,2022-10-15,purchase,1,34.50,1,3,2
2023-01-10 12:00:00,1234,1542438363648999385,32.75,10,15,7,2022-10-16,purchase,2,65.50,1,3,2
9 changes: 9 additions & 0 deletions integration_tests/seeds/reddit_ads_campaign_conversions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_fivetran_synced,account_id,avg_value,campaign_id,click_through_conversion_attribution_window_day,click_through_conversion_attribution_window_month,click_through_conversion_attribution_window_week,date,event_name,total_items,total_value,view_through_conversion_attribution_window_day,view_through_conversion_attribution_window_month,view_through_conversion_attribution_window_week
2023-01-10 12:00:00,1234,26.50,1510393823694638543,10,15,7,2022-10-09,purchase,3,79.50,1,3,2
2023-01-10 12:00:00,1234,31.75,1510393823694638543,10,15,7,2022-10-10,purchase,4,127.00,1,3,2
2023-01-10 12:00:00,1234,23.80,1542438351052756282,10,15,7,2022-10-11,purchase,3,71.40,1,3,2
2023-01-10 12:00:00,1234,29.60,1542438351052756282,10,15,7,2022-10-12,purchase,4,118.40,1,3,2
2023-01-10 12:00:00,1234,36.20,1576385495765735715,10,15,7,2022-10-13,purchase,5,181.00,1,3,2
2023-01-10 12:00:00,1234,28.90,1576385495765735715,10,15,7,2022-10-14,purchase,3,86.70,1,3,2
2023-01-10 12:00:00,1234,32.50,1593209133449106285,10,15,7,2022-10-15,purchase,2,65.00,1,3,2
2023-01-10 12:00:00,1234,30.75,1593209133449106285,10,15,7,2022-10-16,purchase,4,123.00,1,3,2
18 changes: 18 additions & 0 deletions macros/get_account_conversions_report_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% macro get_account_conversions_report_columns() %}

{% set columns = [
{"name": "_fivetran_synced", "datatype": dbt.type_timestamp()},
{"name": "account_id", "datatype": dbt.type_string()},
{"name": "click_through_conversion_attribution_window_month", "datatype": dbt.type_int()},
{"name": "date", "datatype": "date"},
{"name": "event_name", "datatype": dbt.type_string()},
{"name": "total_items", "datatype": dbt.type_int()},
{"name": "total_value", "datatype": dbt.type_int()},
{"name": "view_through_conversion_attribution_window_month", "datatype": dbt.type_int()}
] %}

{{ fivetran_utils.add_pass_through_columns(columns, var('reddit_ads__account_conversions_passthrough_metrics')) }}

{{ return(columns) }}

{% endmacro %}
Loading

0 comments on commit 6c7f5e8

Please sign in to comment.