Skip to content

feature/country-report #24

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 12 commits into from
Apr 30, 2025
Merged

feature/country-report #24

merged 12 commits into from
Apr 30, 2025

Conversation

fivetran-joemarkiewicz
Copy link
Collaborator

@fivetran-joemarkiewicz fivetran-joemarkiewicz commented Apr 22, 2025

PR Overview

Package version introduced in this PR: v0.8.0

This PR addresses the following Issue/Feature(s): Internal ticket

Summary of changes:

Introduces the new tiktok_ads__campaign_country_report.

Submission Checklist

  • Alignment meeting with the reviewer (if needed)
    • Timeline and validation requirements discussed
  • Provide validation details:
    • Validation Steps: Check for unintentional effects (e.g., add/run consistency & integrity tests)
      • Provided in internal ticket
    • Testing Instructions: Confirm the change addresses the issue(s)
      • Provided in internal ticket
    • Focus Areas: Complex logic or queries that need extra attention
      • Discussed live and provide comments in this PR to call out notable sections.

Changelog

  • Draft changelog for PR
  • Final changelog for release review

@fivetran-joemarkiewicz fivetran-joemarkiewicz marked this pull request as ready for review April 23, 2025 21:47
CHANGELOG.md Outdated
**4 total changes • 0 possible breaking changes
| Table/Column | Change Type | Old Name | New Name | Notes |
|---------------------------------------------------|-------------|----------|-------------------------------------------|-------------------------------------------------------------------|
| tiktok_ads__campaign_country_report | New Model | | | New table that represents the daily performance of a campaign at the country/geographic region level. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should we add links to these models in the DAG?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - added

CHANGELOG.md Outdated
| Table/Column | Change Type | Old Name | New Name | Notes |
|---------------------------------------------------|-------------|----------|-------------------------------------------|-------------------------------------------------------------------|
| tiktok_ads__campaign_country_report | New Model | | | New table that represents the daily performance of a campaign at the country/geographic region level. |
| stg_tiktok_ads__campaign_country_report_tmp | New Model | | | Temp model added for `campaign_country_report`. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we differentiate between Staging and Transform Models here? "New Staging Model" vs. "New Transformation Model" for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - added

CHANGELOG.md Outdated

## Feature Updates
- Added the `tiktok_ads__campaign_country_report` end model and upstream staging models. See above for schema change details and new models added.
- For dbt Core users: If you do not sync this table or would like disable these new models you can disable the models by setting the `tiktok_ads__using_campaign_country_report` variable to `false` in your `dbt_project.yml` file (`true` by default).
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a link to the README?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - added

CHANGELOG.md Outdated
- Added the `tiktok_ads__campaign_country_report` end model and upstream staging models. See above for schema change details and new models added.
- For dbt Core users: If you do not sync this table or would like disable these new models you can disable the models by setting the `tiktok_ads__using_campaign_country_report` variable to `false` in your `dbt_project.yml` file (`true` by default).
- Included the `tiktok_ads__campaign_country_report_passthrough_metrics` passthrough variable in the above mentioned new staging models. Refer to the [README](https://github.com/fivetran/dbt_tiktok_ads/tree/main?tab=readme-ov-file#passing-through-additional-metrics) for more details.
- Introduced the above mentioned new columns to the `stg_tiktok_ads__campaign_history` model.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this repetitive with line 11 of the Schema Changes table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - added

README.md Outdated
@@ -89,6 +90,13 @@ 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.

#### Disable Country Reports
This package leverages the `campaign_country_report` table to help report on ad and campaign performance by country. However, if you are not actively syncing this report from your TikTok Ads connection, you may disable the transformations for the `campaign_country_report` by adding the following variable configuration to your root `dbt_project.yml` file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This package leverages the `campaign_country_report` table to help report on ad and campaign performance by country. However, if you are not actively syncing this report from your TikTok Ads connection, you may disable the transformations for the `campaign_country_report` by adding the following variable configuration to your root `dbt_project.yml` file:
This package leverages the `campaign_country_report` table to help report on ad and campaign performance by country and region. However, if you are not actively syncing this report from your TikTok Ads connection, you may disable the transformations for the `campaign_country_report` by adding the following variable configuration to your root `dbt_project.yml` file:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See same comment from the source. It's not entirely accurate to claim and region here. Instead we'll clarify country/geographic region level.

dbt_project.yml Outdated
@@ -15,6 +15,10 @@ vars:
ad_report_hourly: "{{ ref('stg_tiktok_ads__ad_report_hourly') }}"
ad_history: "{{ ref('stg_tiktok_ads__ad_history') }}"
advertiser: "{{ ref('stg_tiktok_ads__advertiser') }}"
ad_country_report: "{{ ref('stg_tiktok_ads__ad_country_report') }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to no longer being built, so it can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, this was initially included and then removed. Removing the artifact.

dbt_project.yml Outdated
tiktok_ads__ad_group_hourly_passthrough_metrics: []
tiktok_ads__ad_hourly_passthrough_metrics: []
tiktok_ads__campaign_hourly_passthrough_metrics: []
tiktok_ads__campaign_country_report_passthrough_metrics: []
tiktok_ads__ad_country_report_passthrough_metrics: []
Copy link
Contributor

Choose a reason for hiding this comment

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

This macro seems to no longer being built, so it can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, this was initially included and then removed. Removing the artifact.


select
country_report.source_relation,
cast(country_report.stat_time_day as date) as date_day,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we cast to date_day in the transformation model rather than the staging model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No reason, but we should cast at staging model. Made the update in the source package and removing this cast here.

Comment on lines 500 to 519
description: Total number of clicks.
- name: impressions
description: Total number of impressions.
- name: spend
description: Total spend in the advertiser’s currency.
- name: conversion
description: Total number of tracked conversions.
- name: conversion_rate
description: Conversion rate as a percentage.
- name: cost_per_conversion
description: Average cost per conversion.
- name: daily_cpc
description: Cost per click.
- name: daily_cpm
description: Cost per mille (1,000 impressions).
- name: daily_ctr
description: Click-through rate.
- name: real_time_conversion
description: Total number of real-time conversions reported.
Copy link
Contributor

@fivetran-avinash fivetran-avinash Apr 28, 2025

Choose a reason for hiding this comment

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

I think you could replicate the yml descriptions for the metrics for what is shown on the other reports to add more details.

A few examples from the tiktok_ads__campaign report:

 - name: impressions
    description: The number of impressions that occurred on the day of the record.
  - name: clicks
    description: The number of clicks that occurred on the day of the record.
  - name: spend
    description: The amount of spend that occurred on the day of the record.
  - name: reach
    description: The number of unique users who saw your ads at least once. This metric is estimated.
  - name: conversion
    description: >
      The number of times your ad achieved an outcome, based on the secondary goal you selected.  
      As one campaign may have a number of different secondary goals, this statistic is not supported for campaigns. 
      Please go to ad groups or ads to view. (The total count is calculated based on the time each ad impression occurred.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Updated to match other metric defs from existing models


- name: tiktok_ads__campaign_country_report
description: Each record in this table represents the daily performance of a campaign at the country/geographic region level.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this model is representing country and geographic regions, should we rename the model to be more generic, like tiktok_ads__campaign_geographic_report? Or is the plurality of data for country_code usually countries?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah the plurality of data for country_code is typically countries with a few outliers based on TikTok Ads API docs. We opted to call out the geographic regions in the description to highlight that there are some outliers, but they are not the majority. Additionally, since there are only a few outliers and not complete support for regions, I didn't want to name the model as such.

Lastly, I would prefer the name of the model match the source name as closely as possible.

end_count_unique_days != staging_count_unique_days or
end_total_impressions != staging_total_impressions or
end_total_clicks != staging_total_clicks or
end_total_spend != staging_total_spend or
Copy link
Contributor

Choose a reason for hiding this comment

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

With monetary floats, I've always noticed that the numbers can deviate by an insigifcant amount to throw errors that would not be logged in the financial reports. Perhaps this would be better:

Suggested change
end_total_spend != staging_total_spend or
abs(end_total_spend - staging_total_spend) > 0.01 or

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good approach and helps to future proof any false positives. Added.

(sum(country_report.clicks)/nullif(sum(country_report.impressions),0))*100 as daily_ctr,
sum(country_report.real_time_conversion) as real_time_conversion

{{ tiktok_ads_persist_pass_through_columns(pass_through_variable='tiktok_ads__campaign_country_report_passthrough_metrics', identifier='country_report', transform='sum', coalesce_with=0, exclude_fields=['real_time_conversion','total_purchase_value','total_sales_lead_value']) }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need the exclude_fields here since this is a net new model and backwards compatibility isn't required. What are your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I also don't think total_purchase_value' and 'total_sales_lead_value are even present in the campaign_country_report)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, removed the exclude fields. This was an artifact of initial model build and emulating other models in this package.

Copy link
Contributor

@fivetran-avinash fivetran-avinash left a comment

Choose a reason for hiding this comment

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

@fivetran-joemarkiewicz Great work so far! A few comments, questions and suggestions before approval.

CHANGELOG.md Outdated

[PR #24](https://github.com/fivetran/dbt_tiktok_ads/pull/24) includes the following updates:
## Schema Changes
**4 total changes • 0 possible breaking changes
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume we want this bolded, so:

Suggested change
**4 total changes • 0 possible breaking changes
**4 total changes • 0 possible breaking changes**

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update applied.

Copy link
Contributor

@fivetran-avinash fivetran-avinash left a comment

Choose a reason for hiding this comment

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

@fivetran-joemarkiewicz Approved with one suggestion!

sum(country_report.impressions) as impressions,
sum(country_report.spend) as spend,
sum(country_report.conversion) as conversion,
sum(country_report.conversion_rate) as conversion_rate,
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't make sense to sum rates so I don't think conversion_rate and cost_per_conversion should be included. I'm not sure there's a way to derive it either given that they come as is in the staging model

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed - made the relevant updates.

Copy link
Contributor

@fivetran-reneeli fivetran-reneeli left a comment

Choose a reason for hiding this comment

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

Looks mostly good but I had one major callout.

Copy link
Contributor

@fivetran-reneeli fivetran-reneeli left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@fivetran-reneeli fivetran-reneeli left a comment

Choose a reason for hiding this comment

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

LGTM

@fivetran-joemarkiewicz fivetran-joemarkiewicz merged commit 233485f into main Apr 30, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants