GithubHelp home page GithubHelp logo

fivetran / dbt_snapchat_ads_source Goto Github PK

View Code? Open in Web Editor NEW
1.0 37.0 4.0 1.65 MB

Fivetran's Snapchat Ads source dbt package

Home Page: https://fivetran.github.io/dbt_snapchat_ads_source/

License: Apache License 2.0

Shell 100.00%
dbt fivetran dbt-packages snapchat-ads

dbt_snapchat_ads_source's Introduction

Snapchat Ads Source dbt Package (Docs)

📣 What does this dbt package do?

  • Materializes Snapchat Ads staging tables which leverage data in the format described by this ERD. These staging tables clean, test, and prepare your Snapchat Ads data from Fivetran's connector for analysis by doing the following:
    • Name columns for consistency across all packages and for easier analysis
    • Adds freshness tests to source data
    • Adds column-level testing where applicable. For example, all primary keys are tested for uniqueness and non-null values.
  • Generates a comprehensive data dictionary of your Snapchat Ads data through the dbt docs site.
  • These tables are designed to work simultaneously with our Snapchat Ads transformation package.
    • Refer to our Docs site for more details about these materialized models.

🎯 How do I use the dbt package?

Step 1: Prerequisites

To use this dbt package, you must have the following:

  • At least one Fivetran Snapchat Ads connector syncing data into your destination.
  • A BigQuery, Snowflake, Redshift, Databricks, or PostgreSQL destination.

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.

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

Step 2: Install the package (skip if also using the snapchat_ads transformation package)

If you are not using the Snapchat Ads transformation package, 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 for the latest installation instructions or read the dbt docs for more information on installing packages.

packages:
  - package: fivetran/snapchat_ads_source
    version: [">=0.6.0", "<0.7.0"] # we recommend using ranges to capture non-breaking changes automatically

Step 3: Configure your variables

Define database and schema variables

By default, this package runs using your destination and the snapchat_ads_source schema. If this is not where your Snapchat Ads data is (for example, if your Snapchat Ads schema is named snapchat_ads_fivetran), you would add the following configuration to your root dbt_project.yml file with your custom database and schema names:

vars:
    snapchat_ads_database: your_destination_name
    snapchat_ads_schema: your_schema_name 

(Optional) Step 4: Additional configurations

Union multiple connectors

If you have multiple snapchat_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 snapchat_ads_union_schemas OR snapchat_ads_union_databases variables (cannot do both) in your root dbt_project.yml file:

vars:
    snapchat_ads_union_schemas: ['snapchat_ads_usa','snapchat_ads_canada'] # use this if the data is in different schemas/datasets of the same database/project
    snapchat_ads_union_databases: ['snapchat_ads_usa','snapchat_ads_canada'] # use this if the data is in different databases/projects but uses the same schema name

Please be aware that 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 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:

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.

vars:
    snapchat_ads__ad_hourly_passthrough_metrics: 
      - name: "new_custom_field"
        alias: "custom_field"
    snapchat_ads__ad_squad_hourly_passthrough_metrics:
      - name: "this_field"
    snapchat_ads__campaign_hourly_report_passthrough_metrics:
      - name: "unique_string_field"
        alias: "field_id"

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:

IMPORTANT: See this project's dbt_project.yml variable declarations to see the expected names.

vars:
    snapchat_ads_<default_source_table_name>_identifier: your_table_name 

Change the build schema

By default, this package builds the Snapchat Ads staging models within a schema titled (<target_schema> + _stg_snapchat_ads) in your destination. If this is not where you would like your Snapchat Ads staging data to be written to, add the following configuration to your root dbt_project.yml file:

models:
    snapchat_ads_source:
      +schema: my_new_schema_name # leave blank for just the target_schema

(Optional) Step 5: Orchestrate your models with Fivetran Transformations for dbt Core™

Expand for more details

Fivetran offers the ability for you to orchestrate your dbt project through Fivetran Transformations for dbt Core™. Learn how to set up your project for orchestration through Fivetran in our Transformations for dbt Core™ setup guides.

🔍 Does this package have dependencies?

This dbt package is dependent on the following dbt packages. Please be aware that these dependencies are installed by default within this package. For more information on the following packages, refer to the dbt hub 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.

packages:
    - package: fivetran/fivetran_utils
      version: [">=0.4.0", "<0.5.0"]

    - package: dbt-labs/dbt_utils
      version: [">=1.0.0", "<2.0.0"]

    - 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 of the package and refer to the CHANGELOG and release notes for more information on changes across versions.

Opinionated Decisions

In creating this package, which is meant for a wide range of use cases, we had to take opinionated stances on a few different questions we came across during development. We've consolidated significant choices we made in the DECISIONLOG.md, and will continue to update as the package evolves. We are always open to and encourage feedback on these choices, and the package in general.

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 to learn how to contribute to a dbt package!

🏪 Are there any resources available?

  • If you have questions or want to reach out for help, please refer to the GitHub Issue 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.
  • Have questions or want to just say hi? Book a time during our office hours on Calendly or email us at [email protected].

dbt_snapchat_ads_source's People

Contributors

fivetran-reneeli avatar fivetran-joemarkiewicz avatar fivetran-sheringuyen avatar dylanbaker avatar fivetran-catfritz avatar fivetran-jamie avatar jlmendgom5tran avatar kristin-bagnall avatar alex-ilyichov avatar

Stargazers

 avatar

Watchers

Jason Nochlin avatar Fraser Harris avatar James Cloos avatar Miklos Juhasz avatar Jay avatar  avatar Taylor Brown avatar Alison Kline avatar Roman Vlasenko avatar Ian Woods avatar  avatar Vuk Djoric avatar Pavel Akimov avatar Artem Lavrov avatar  avatar Mike Gordon avatar Martin K avatar Hannah Bowers avatar Bo Huang avatar Kelly Kohlleffel avatar Rakmandzhan Rakhmatov avatar  avatar Roman Ageev avatar Stepan Babayan avatar Hossain Elahi avatar Dhara Patel avatar Imen Graja avatar William Larsen avatar Kirill Zharskiy avatar ParagPatil avatar Mrinalini Sharma avatar  avatar Ivan Ryazanov avatar Sunil Kuruba avatar  avatar Shashank Tripathi avatar Artem Romanov avatar

dbt_snapchat_ads_source's Issues

BUG - Micro conversion

Are you a current Fivetran customer?

Fivetran created PR

Describe the bug

Snapchat records all monetary values in micros. We will want to update the package to convert micros to dollar values.

Expected behavior

The source package should apply the conversion for easier analysis and proper integration into the ad reporting package.

[Error] <issue with passthrough metrics>

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Adding passthrough metrics is not working as expected.

dbt_snapchat_ads_source models have metrics that are missing from the dbt_snapchat_ads models.

This is causing the following error:

Column name XXXX is ambiguous at [229:9]

Relevant error log or model output

11:10:41  Began running node model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report
11:10:41  8 of 12 START sql table model dbt_dev_snapchat_ads_source.stg_snapchat_ads__ad_hourly_report  [RUN]
11:10:41  Acquiring new bigquery connection 'model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report'
11:10:41  Began compiling node model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report
11:10:41  Opening a new connection, currently in state closed
11:10:42  Writing injected SQL for node "model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report"
11:10:42  Timing info for model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report (compile): 2023-03-15 11:10:41.790652 => 2023-03-15 11:10:42.058106
11:10:42  Began executing node model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report
11:10:42  Writing runtime sql for node "model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report"
11:10:42  On model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report: /* {"app": "dbt", "dbt_version": "1.4.5", "profile_name": "user", "target_name": "default", "node_id": "model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report"} */

  
    

    create or replace table `dp-world-reporting`.`dbt_dev_snapchat_ads_source`.`stg_snapchat_ads__ad_hourly_report`
    
    
    OPTIONS()
    as (
      

with base as (

    select * 
    from `dp-world-reporting`.`dbt_dev_snapchat_ads_source`.`stg_snapchat_ads__ad_hourly_report_tmp`
),

fields as (

    select
        
    
    
    ad_id
    
 as 
    
    ad_id
    
, 
    
    
    attachment_quartile_1
    
 as 
    
    attachment_quartile_1
    
, 
    
    
    attachment_quartile_2
    
 as 
    
    attachment_quartile_2
    
, 
    
    
    attachment_quartile_3
    
 as 
    
    attachment_quartile_3
    
, 
    
    
    attachment_total_view_time_millis
    
 as 
    
    attachment_total_view_time_millis
    
, 
    
    
    attachment_view_completion
    
 as 
    
    attachment_view_completion
    
, 
    
    
    date
    
 as 
    
    date
    
, 
    
    
    impressions
    
 as 
    
    impressions
    
, 
    
    
    quartile_1
    
 as 
    
    quartile_1
    
, 
    
    
    quartile_2
    
 as 
    
    quartile_2
    
, 
    
    
    quartile_3
    
 as 
    
    quartile_3
    
, 
    
    
    saves
    
 as 
    
    saves
    
, 
    
    
    screen_time_millis
    
 as 
    
    screen_time_millis
    
, 
    
    
    shares
    
 as 
    
    shares
    
, 
    
    
    spend
    
 as 
    
    spend
    
, 
    
    
    swipes
    
 as 
    
    swipes
    
, 
    
    
    video_views
    
 as 
    
    video_views
    
, 
    
    
    view_completion
    
 as 
    
    view_completion
    
, 
    
    
    view_time_millis
    
 as 
    
    view_time_millis
    
, 
    
    
    video_views
    
 as 
    
    video_views
    
, 
    cast(null as STRING) as 
    
    video_completion
    
 

        
    from base
),

final as (
    
    select 
        ad_id,
        cast (date as TIMESTAMP) as date_hour,
        attachment_quartile_1,
        attachment_quartile_2,
        attachment_quartile_3,
        (attachment_total_view_time_millis / 1000000.0) as attachment_total_view_time,
        attachment_view_completion,
        quartile_1,
        quartile_2,
        quartile_3,
        saves,
        shares,
        (screen_time_millis / 1000000.0) as screen_time,
        video_views,
        view_completion,
        (view_time_millis / 1000000.0) as view_time,
        impressions,
        (spend / 1000000.0) as spend,
        swipes

        


    
        
            
                , video_views
            
        
    
        
            
                , video_completion
            
        
    




    from fields
)

select * 
from final
    );
  
11:10:42  BigQuery adapter: Retry attempt 1 of 1 after error: BadRequest('Column name video_views is ambiguous at [229:9]')
11:10:44  BigQuery adapter: https://console.cloud.google.com/bigquery?project=dp-world-reporting&j=bq:europe-west2:22bf9a03-de4b-439e-b028-4d70bdec354b&page=queryresults
11:10:44  Timing info for model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report (execute): 2023-03-15 11:10:42.058564 => 2023-03-15 11:10:44.210166
11:10:44  Database Error in model stg_snapchat_ads__ad_hourly_report (models/stg_snapchat_ads__ad_hourly_report.sql)
  Column name video_views is ambiguous at [229:9]
  compiled Code at target/run/snapchat_ads_source/models/stg_snapchat_ads__ad_hourly_report.sql
11:10:44  Sending event: {'category': 'dbt', 'action': 'run_model', 'label': '71126931-651d-4824-81b0-3ea7e7a2c8ee', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x7f9d4c33cc70>]}
11:10:44  8 of 12 ERROR creating sql table model dbt_dev_snapchat_ads_source.stg_snapchat_ads__ad_hourly_report  [�[31mERROR�[0m in 2.42s]
11:10:44  Finished running node model.snapchat_ads_source.stg_snapchat_ads__ad_hourly_report

Expected behavior

Adding passthrough metrics other than (swipes, impressions, spend) should work for both snapchat packages:

dbt_snapchat_ads_source
dbt_snapchat_ads

dbt Project configurations

snapchat_ads__ad_hourly_passthrough_metrics: 
      - name: "video_views"
      - name: "video_completion"
    snapchat_ads__ad_squad_hourly_passthrough_metrics:
      - name: "video_views"
      - name: "video_completion"
    snapchat_ads__campaign_hourly_report_passthrough_metrics:
      - name: "video_views"
      - name: "video_completion"

Package versions

  • package: fivetran/snapchat_ads
    version: 0.5.1

What database are you using dbt with?

bigquery

dbt Version

1.4

Additional Context

No response

Are you willing to open a PR to help address this issue?

  • Yes.
  • Yes, but I will need assistance and will schedule time during our office hours for guidance
  • No.

[Feature] Add documentation on differences among aggregations across different grains

Copied from fivetran/dbt_ad_reporting #92.

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

Some customers have brought up concerns on why sums are different across different grains, for example why spend is not the same summed up across the ad level versus the campaign level.

Example from Joe regarding a recent customer inquiry:

"The reason for this discrepancy is due to not all ads being served at the ad level. There are some ads that are only served at the ad group/campaign/etc. levels. This means that you can have ads sent at the campaign level and that counts towards your total spend. However, since the ad was never sent at an individual ad 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 level, we were missing data as some ads were not served at an ad level, but were served at a campaign level."

We should add more context like above to our ad packages READMEs as a proactive measure.

Describe alternatives you've considered

No response

Are you interested in contributing this feature?

  • Yes.
  • Yes, but I will need assistance and will schedule time during your office hours for guidance.
  • No.

Anything else?

No response

[Feature] Add union schema capability

Copied from fivetran/dbt_facebook_ads_source #29.

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

Issue for adding the union schema capability.

Describe alternatives you've considered

No response

Are you interested in contributing this feature?

  • Yes.
  • Yes, but I will need assistance and will schedule time during your office hours for guidance.
  • No.

Anything else?

No response

[Feature] Add disabling models for non-existent sources

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

We (Dave.com) launch campaigns on Snapchat, but do no use creative url tags. This causes this package to fail (see below) since the creative_url_tag_history table does not exist in the schema managed by the Snapchat connector.

Please add a config to disable models for non-existent sources (specifically creative_url_tag_history). For example, the Fivetran Stripe package has this currently:

Screen Shot 2022-08-25 at 10 24 56 AM


14:33:03  Database Error in model stg_snapchat__creative_url_tag_history_tmp (models/tmp/stg_snapchat__creative_url_tag_history_tmp.sql)
14:33:03    002003 (42S02): SQL compilation error:
14:33:03    Object 'MARKETING_DB.SNAPCHAT_ADS_V2.CREATIVE_URL_TAG_HISTORY' does not exist or not authorized.
14:33:03    compiled SQL at target/run/snapchat_ads_source/models/tmp/stg_snapchat__creative_url_tag_history_tmp.sql
14:33:03  Encountered an error:
FailFast Error in model stg_snapchat__creative_url_tag_history_tmp (models/tmp/stg_snapchat__creative_url_tag_history_tmp.sql)
Failing early due to test failure or runtime error
Error: Process completed with exit code 2.

Describe alternatives you've considered

Have worked w. our Fivetran AE & support to find alternatives. They recommended requesting this feature.

Are you interested in contributing this feature?

  • Yes.
  • Yes, but I will need assistance and will schedule time during your office hours for guidance.
  • No.

Anything else?

No response

BUG - creative_url_tag_history test failure

Are you a current Fivetran customer?

Tyler Schmidt, Data Scientist, Toggle/Farmers Insurance

Describe the bug

The unique_combination_of_columns test for stg_snapchat__creative_url_tag_history is giving a failure because of updated_at field not being included as part of the unique check despite being the ORDER BY for the is_most_recent_record

Steps to reproduce

  1. Excute dbt test --select dbt_utils_unique_combination_of_columns_stg_snapchat__creative_url_tag_history_creative_id__param_key
  2. See error

Expected behavior

I would exepct it to pass as the only reason for duplicate is updates to the information via the normal data flow (updated_at)

Project variables configuration

name: 'toggle_data_wh'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'toggle_data_wh'

# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
seed-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  # directory which will store compiled SQL files
clean-targets:         # directories to be removed by `dbt clean`
  - "target"
  - "dbt_packages"



# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/ directory
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.
models:
  toggle_data_wh:
    +materialized: table
    staging:
      +materialized: view
  snapchat_ads_source:
    +schema: stg_ads

vars:
  snapchat_ads_source:
    snapchat_database: fnv_raw_db
    snapchat_schema: snapchat_ads 

Package Version

packages:

  - package: Datavault-UK/dbtvault
    version: 0.7.9
    
#  - package: fivetran/ad_reporting
#    version: 0.2.3

  - package: fivetran/snapchat_ads_source
    version: 0.3.0

Warehouse

  • BigQuery
  • Redshift
  • Snowflake
  • Postgres
  • Databricks
  • Other (provide details below)

Additional context

Screenshots

Please indicate the level of urgency

This is not urgent as we turned off the test in production via --exclude .... and will not be updating our production run to DBT 1.0 for a bit so we will not be able to utlize any changes till after then anyway.

Are you interested in contributing to this package?

  • Yes, I can do this and open a PR for your review.
  • Possibly, but I'm not quite sure how to do this. I'd be happy to do a live coding session with someone to get this fixed.
  • No, I'd prefer if someone else fixed this. I don't have the time and/or don't know what the root cause of the problem is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.