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

feat(source-tiktok-marketing): add fivetran converter #57

Merged
merged 3 commits into from
Sep 3, 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
94 changes: 89 additions & 5 deletions connectors/source_tiktok_marketing/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,93 @@
# Airbyte source_tiktok_marketing dbt Package
# Tiktok Marketing Airbyte dbt Package

This package contains dbt models for Airbyte source_tiktok_marketing source.
---

> [!WARNING]
> This model was tested and only work with Bigquery.

What it includes:

* A complete source description
* ERD model for the source
* Diagram documentation for the source
- This package contains dbt models to work with Airbyte Tiktok Marketing connector.
- The package is compatible with latest version of Airbyte Tiktok Marketing connector.
- Currently, it is limited to creating transformations compatible with [Fivetran's modeling dbt package](https://github.com/fivetran/dbt_tiktok_ads/tree/main).
- In the future, specific models will be applied directly to Airbyte connector output. If you have an idea or want to propose an analytical model for this source, please refer to the contributing guide, which explains how to propose a new transformation model.
- This package was tested with BigQuery, Snowflake, and Postgres data warehouses.

---

## 🎯 Intructions how to use

### Airbyte dbt Package

For now Airbyte dbt packages aren't versioned. You must configure using git and subdirectory. For now there isn't any transformation model directly applied to this package. But you can generate docs and tests with dbt.

Create the following files:

**`dbt_project.yml`**

```yaml
vars:
using_fivetran_model: False
airbyte_database: "airbyte_db_default"
airbyte_schema: "airbyte_dbt_tiktok_marketing"
```

**`packages.yml`**

```yaml
packages:
- git: "https://github.com/airbytehq/airbyte-dbt-models.git"
subdirectory: "connectors/source_tiktok_marketing"
```

After you can run `dbt tests` or `dbt docs generate` to have a preview of Airbyte output data.

### Fivetran Tiktok Marketing Modeling dbt package

This package transforms Airbyte connector output data, making it compatible with Fivetran's Tiktok Marketing dbt package. You can check the analytical models Fivetran creates [here](https://github.com/fivetran/dbt_tiktok_ads/tree/main?tab=readme-ov-file#-what-does-this-dbt-package-do). The link also provides information about how the package works and what is configurable.

Create the require files to use Airbyte and Fivetran dbt packages:

**`packages.yml`**

```yaml
packages:
- git: "https://github.com/airbytehq/airbyte-dbt-models.git"
subdirectory: "connectors/source_tiktok_marketing"

- package: fivetran/tiktok_ads
version: [">=0.5.0", "<0.6.0"]
```

This is a default variable definition you must configure to have the models created.

**`dbt_project.yml`**

```yaml
vars:
# Required by Airbyte dbt model
using_fivetran_model: True
airbyte_database: "airbyte_db_default"
airbyte_schema: "airbyte_dbt_tiktok_marketing"

# Required by Fivetran dbt model
tiktok_ads_database: "airbyte_db_default"
tiktok_ads_schema: "airbyte_dbt_tiktok_marketing"

tiktok_ads_adgroup_history_identifier: "ad_group_history"
tiktok_ads_adgroup_report_hourly_identifier: "ad_group_report_hourly"
tiktok_ads_ad_history_identifier: "ad_history"
tiktok_ads_ad_report_hourly_identifier: "ad_report_hourly"
tiktok_ads_advertiser_identifier: "advertiser"
tiktok_ads_campaign_history_identifier: "campaign_history"
tiktok_ads_campaign_report_hourly_identifier: "campaign_report_hourly"
```

After run `dbt run`, you can see the models being created.

---

## :package: Package Maintenance

- This package is maintained by the Airbyte Community.
- You can contribute any time please read the Contributing Guidelines or enter the Airbyte Slack Channel `#airbyte-dbt-packages`
4 changes: 2 additions & 2 deletions connectors/source_tiktok_marketing/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ config-version: 2

version: 0.1.0

profile: airbyte
profile: integration_tests

model-paths:
- models
Expand All @@ -20,7 +20,7 @@ clean-targets:
- logs

require-dbt-version:
- '>=1.0.0'
- ">=1.0.0"
- <2.0.0

models:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: integration_test_tiktok_marketing

config-version: 2

version: 0.1.0

profile: integration_tests

model-paths:
- models

macro-paths:
- macros

target-path: target

clean-targets:
- target
- dbt_modules
- logs

require-dbt-version:
- ">=1.0.0"
- <2.0.0

models:
airbyte_dbt_source_tiktok_marketing:
materialized: view
+schema: dbt_source_tiktok_marketing
staging:
materialized: view
tmp:
materialized: view

vars:
# Required by Airbyte dbt model
using_fivetran_model: True
airbyte_database: "airbyte_db_default"
airbyte_schema: "airbyte_dbt_source_tiktok_marketing"

# Required by Fivetran dbt model
tiktok_ads_database: "airbyte_db_default"
tiktok_ads_schema: "airbyte_dbt_source_tiktok_marketing"

tiktok_ads_adgroup_history_identifier: "ad_group_history"
tiktok_ads_adgroup_report_hourly_identifier: "ad_group_report_hourly"
tiktok_ads_ad_history_identifier: "ad_history"
tiktok_ads_ad_report_hourly_identifier: "ad_report_hourly"
tiktok_ads_advertiser_identifier: "advertiser"
tiktok_ads_campaign_history_identifier: "campaign_history"
tiktok_ads_campaign_report_hourly_identifier: "campaign_report_hourly"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
packages:
- local: ../
- package: fivetran/tiktok_ads
version: 0.5.0
- package: fivetran/tiktok_ads_source
version: 0.5.2
- package: fivetran/fivetran_utils
version: 0.4.10
- package: dbt-labs/spark_utils
version: 0.3.0
- package: dbt-labs/dbt_utils
version: 1.2.0
sha1_hash: 42ec6d0b088b381a14f44945a2410c46d5049e4f
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
- local: ../

- package: fivetran/tiktok_ads
version: [">=0.5.0", "<0.6.0"]
1 change: 1 addition & 0 deletions connectors/source_tiktok_marketing/integration_tests/vars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{airbyte_database: $AB_DB, tiktok_marketing_database: $AB_DB}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

{% if target.type == "postgres" %}

WITH TMP AS (
SELECT
action_category_ids AS action_categories,
action_days,
adgroup_id,
adgroup_name,
advertiser_id,
age_groups AS age, --FIX
age_groups,
audience_type,
budget,
campaign_id,
category_id AS category,
campaign_name AS display_name,
frequency,
frequency_schedule,
gender,
interest_category_ids AS interest_category_v_2,
app_download_url AS landing_page_url,
languages,
modify_time AS updated_at
FROM
{{ source('source_tiktok_marketing', 'ad_groups') }}
)

SELECT * FROM TMP

{% elif target.type == "bigquery" %}

WITH TMP AS (
SELECT
action_category_ids AS action_categories,
action_days,
adgroup_id,
adgroup_name,
advertiser_id,
age_groups AS age, --FIX
age_groups,
audience_type,
budget,
campaign_id,
category_id AS category,
campaign_name AS display_name,
frequency,
frequency_schedule,
gender,
interest_category_ids AS interest_category_v_2,
app_download_url AS landing_page_url,
languages,
modify_time AS updated_at
FROM
{{ source('source_tiktok_marketing', 'ad_groups') }}
)

SELECT * FROM TMP

{% elif target.type == "snowflake" %}

WITH TMP AS (
SELECT
action_category_ids AS action_categories,
action_days,
adgroup_id,
adgroup_name,
advertiser_id,
age_groups AS age, --FIX
age_groups,
audience_type,
budget,
campaign_id,
category_id AS category,
campaign_name AS display_name,
frequency,
frequency_schedule,
gender,
interest_category_ids AS interest_category_v_2,
app_download_url AS landing_page_url,
languages,
modify_time AS updated_at
FROM
{{ source('source_tiktok_marketing', 'ad_groups') }}
)

SELECT * FROM TMP

{%endif%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: 2

models:
- name: ad_group_history
schema: "{{ var('airbyte_schema', target.schema) }}"
database: "{{ var('airbyte_database', target.database) }}"
identifier: "{{ var('tiktok_ads_adgroup_history_identifier', 'ad_group_history') }}"
description: All fields and field values associated with ad_group_history.
config:
+enabled: "{{ var('using_fivetran_model', False) }}"
columns:
- name: action_categories
description: The IDs of the action categories associated with the ad group
- name: action_days
description: The number of days the action has been performed
- name: adgroup_id
description: The unique identifier of the ad group
- name: adgroup_name
description: The name of the ad group
- name: advertiser_id
description: The unique identifier of the advertiser
- name: age
description: The targeted age groups for the ad group
- name: age_groups
description: The targeted age groups for the ad group
- name: audience_type
description: The type of audience being targeted
- name: budget
description: The allocated budget for the ad group
- name: campaign_id
description: The unique identifier of the campaign
- name: category
description: The ID of the category for the ad group
- name: display_name
description: The name of the campaign
- name: frequency
description: The frequency of ad display
- name: frequency_schedule
description: The schedule for frequency capping
- name: gender
description: The targeted gender for the ad group
- name: interest_category_v_2
description: The IDs of interest categories for targeting
- name: landing_page_url
description: The URL for downloading the associated app
- name: languages
description: The targeted languages for the ad group
- name: updated_at
description: The timestamp for when the ad group was last modified
Loading
Loading