Skip to content

Commit

Permalink
Add conversions to Linkedin Ads Source package (#67)
Browse files Browse the repository at this point in the history
* add macros for conversions, attempt passthrough logic

* macro fiddling

* workin

* Update seed file to fix buildkite errors

* syntax

* more model updates, documentation yml, regen docs

* make code DRYer

* more macros

* documentation

* DECISIONLOG & README

* PR fixes

* regen docs

* README

* changelog

* changelog

* cast as bigint before coalesing with 0

* update docs with code update

* joe suggestion

---------

Co-authored-by: Jamie Rodriguez <[email protected]>
  • Loading branch information
fivetran-avinash and fivetran-jamie authored Jul 30, 2024
1 parent d6f11d2 commit f953ac9
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 161 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# dbt_linkedin_source v0.9.0
[PR #67](https://github.com/fivetran/dbt_linkedin_source/pull/67) includes the following updates:

## 🚨 Breaking Changes 🚨
## Feature Updates: Conversion Support!
We have added more robust support for conversions in our data models by doing the following:
- Created a `linkedin_ads__conversion_fields` variable to pass through additional conversion metrics in the `stg_linkedin_ads__ad_analytics_by_campaign` and `stg_linkedin_ads__ad_analytics_by_creative` models.
- Set variable defaults in the `dbt_project.yml` to bring in the most used conversion fields `external_website_conversions` and `one_click_leads`.
- Ensured backwards compatibility with existing passthrough column variables in these models by creating macro checks for whether these fields already are brought in by the existing passthrough variables. This ensures there are no duplicate column errors if both the new conversion variable and the old passthrough variable are leveraged in either `stg_linkedin_ads__ad_analytics_by_*` data model.
- Brought in the `conversion_value_in_local_currency` field to the above mentioned `stg_linkedin_ads__ad_analytics_by_*` models.
> The above new field additions are 🚨 **breaking changes** 🚨 for users who were not already bringing in conversion fields via passthrough columns.
## Documentation Update
- Documents the ability to transform metrics provided to the `linkedin_ads__campaign_passthrough_metrics` and `linkedin_ads__creative_passthrough_metrics` variables [in the README](https://github.com/fivetran/dbt_linkedin_source/blob/main/README.md#adding-in-conversion-fields-variable).
- Added new metrics to `src` and `stg` yml files.

## Under the Hood
- Updated `linkedin_ad_analytics_by_creative_data` seed file with relevant conversion fields for more robust testing.

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

# dbt_linkedin_source v0.8.2
[PR #66](https://github.com/fivetran/dbt_linkedin_source/pull/66) includes the following updates:
## Bug Fixes
Expand Down
24 changes: 24 additions & 0 deletions DECISIONLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Best Practices with Configuring LinkedIn Ads Conversion Fields Variable
The `linkedin_ads__conversion_fields` variable is designed for end users to properly measure the conversions at the proper level of granularity. By default, we use `external_website_conversions` and `one_click_leads` as they are arguably the most used conversion measures, and fulfill entirely separate objectives as conversions (Website Conversion and Lead Generation respectively).

However, if you decide to configure your own conversion field variable fields, we highly recommend that you bring in conversions at the proper level of segmentation, so there aren't conversions that belong to multiple fields you bring in.

### Bad Practice Example

```yml
# dbt_project.yml
vars:
linkedin_ads__conversion_fields: ['external_website_conversions', 'external_website_pre_click_conversions', 'external_website_post_click_conversions']
```
`external_website_conversions` is comprised of both `external_website_pre_click_conversions` and `external_website_post_click_conversions`.

### Good Practice Example

```yml
# dbt_project.yml
vars:
linkedin_ads__conversion_fields: ['external_website_pre_click_conversions', 'external_website_post_click_conversions']
```

`external_website_pre_click_conversions` and `external_website_post_click_conversions` are two different type of external website conversions, so there should be no overlap.
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ dispatch:
search_order: ['spark_utils', 'dbt_utils']
```
## Step 2: Install the package (skip if also using the `linkedin` transformation package)
If you are **not** using the [Linkedin transformation package](https://github.com/fivetran/dbt_linkedin), 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 `linkedin` transformation package, or `ad_reporting` combination package)
If you are **not** using the [Linkedin transformation package](https://github.com/fivetran/dbt_linkedin) and/or [Ad Reporting transformation 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.
```yml
# packages.yml
packages:
- package: fivetran/linkedin_source
version: [">=0.8.0", "<0.9.0"]
version: [">=0.9.0", "<0.10.0"]
```

## Step 3: Define database and schema variables
Expand All @@ -73,7 +73,7 @@ Please be aware that the native `source.yml` connection set up in the package wi

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.

### Switching to Local Currency
### Switching to Local Currency for Costs
Additionally, the package allows you to select whether you want to add in costs in USD or the local currency of the ad. By default, the package uses USD. If you would like to have costs in the local currency, add the following variable to your `dbt_project.yml` file:

```yml
Expand All @@ -82,26 +82,46 @@ vars:
linkedin_ads__use_local_currency: True # false by default -- uses USD
```

### 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:
**Note**: Unlike cost, conversion values are only available in the local currency. The package will only use the `conversion_value_in_local_currency` field for conversion values, while it may draw from the `cost_in_local_currency` and `cost_in_usd` source fields for cost.

>**Note** Please ensure you exercised 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, 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.
### Passing Through Additional Metrics
By default, this package will select `clicks`, `impressions`, `cost` and `conversion_value_in_local_currency` (as well as fields set via `linkedin_ads__conversion_fields` in the next section) from the source reporting tables `ad_analytics_by_campaign` and `ad_analytics_by_creative` to store into the corresponding 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`) and transformed (`transform_sql`) if desired, but not required. Only the `name` of each metric field is required. Use the below format for declaring the respective pass-through variables:

```yml
# dbt_project.yml
vars:
linkedin_ads__campaign_passthrough_metrics: # pulls from ad_analytics_by_campaign
- 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
- name: "that_field"
linkedin_ads__creative_passthrough_metrics: # pulls from ad_analytics_by_creative
- name: "new_custom_field"
alias: "custom_field"
- name: "unique_int_field"
```
>**Note** Please ensure you exercised due diligence when adding metrics to these models. The metrics added by default (clicks, impressions, and spend) 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. (**Important**: You do not need to add conversions in this way. See the following section for an alternative implementation.)
### Adding in Conversion Fields Variable
Separate from the above passthrough metrics, the package will also include conversion metrics based on the `linkedin_ads__conversion_fields` variable, in addition to the `conversion_value_in_local_currency` field.

By default, the data models consider `external_website_conversions` and `one_click_leads` to be conversions. These should cover most use cases, but, say, if you would like to consider landing page clicks and external post click conversions 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:
linkedin_ads__conversion_fields: ['external_website_conversions', 'one_click_leads', 'external_website_post_click_conversions', 'landing_page_clicks']
```

Make sure to follow best practices in configuring fields in the conversion field variables! [See the DECISIONLOG for more details](https://github.com/fivetran/dbt_linkedin_source/blob/main/DECISIONLOG.md#best-practices-with-configuring-linkedin-ads-conversion-fields-variable).

> We introduced support for conversion fields in our `ad_analytics_by_campaign` and `ad_analytics_by_creative` data models in the [v0.9.0 release](https://github.com/fivetran/dbt_linkedin_source/releases/tag/v0.9.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 build schema
By default, this package builds the Linkedin Ads staging models within a schema titled (`<target_schema>` + `_linkedin_ads_source`) in your destination. If this is not where you would like your Linkedin staging data to be written to, add the following configuration to your root `dbt_project.yml` file:

Expand All @@ -113,7 +133,8 @@ 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_linkedin_source/blob/main/dbt_project.yml) variable declarations to see the expected names.

```yml
Expand Down Expand Up @@ -152,4 +173,3 @@ A small team of analytics engineers at Fivetran develops these dbt packages. How
# 🏪 Are there any resources available?
- If you have questions or want to reach out for help, please refer to the [GitHub Issue](https://github.com/fivetran/dbt_linkedin_source/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).
- Have questions or want to be part of the community discourse? Create a post in the [Fivetran community](https://community.fivetran.com/t5/user-group-for-dbt/gh-p/dbt-user-group) and our team along with the community can join in on the discussion!
3 changes: 2 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'linkedin_source'
version: '0.8.2'
version: '0.9.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
Expand All @@ -18,3 +18,4 @@ vars:
ad_analytics_by_campaign: "{{ source('linkedin_ads', 'ad_analytics_by_campaign') }}"
linkedin_ads__campaign_passthrough_metrics: []
linkedin_ads__creative_passthrough_metrics: []
linkedin_ads__conversion_fields: ['external_website_conversions', 'one_click_leads']
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

Loading

0 comments on commit f953ac9

Please sign in to comment.