GithubHelp home page GithubHelp logo

fivetran / dbt_facebook_ads Goto Github PK

View Code? Open in Web Editor NEW
24.0 38.0 27.0 1.46 MB

Fivetran data models for Facebook Ads built using dbt.

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

License: Apache License 2.0

Shell 100.00%
dbt dbt-packages fivetran facebook-ads

dbt_facebook_ads's Introduction

Facebook Ads Transformation dbt Package (Docs)

πŸ“£ What does this dbt package do?

  • Produces modeled tables that leverage Facebook Ads data from Fivetran's connector in the format described by this ERD and builds off the output of our Facebook Ads source package.
  • Enables you to better understand the performance of your ads across varying grains:
    • Providing an account, campaign, ad group, keyword, ad, and utm level reports.
  • Materializes output models designed to work simultaneously with our multi-platform Ad Reporting package.
  • Generates a comprehensive data dictionary of your source and modeled Facebook Ads data through the dbt docs site.

The following table provides a detailed list of all models materialized within this package by default.

TIP: See more details about these models in the package's dbt docs site.

Model Description
facebook_ads__account_report Each record in this table represents the daily performance at the account level.
facebook_ads__campaign_report Each record in this table represents the daily performance of a campaign at the campaign/advertising_channel/advertising_channel_subtype level.
facebook_ads__ad_set_report Each record in this table represents the daily performance at the ad set level.
facebook_ads__ad_report Each record in this table represents the daily performance at the ad level.
facebook_ads__utm_report Each record in this table represents the daily performance of URLs at the ad level.

🎯 How do I use the dbt package?

Step 1: Prerequisites

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

  • At least one Fivetran Facebook Ads connector syncing data into your destination.
  • A BigQuery, Snowflake, Redshift, PostgreSQL, or Databricks destination.
  • You will need to configure your Facebook Ads connector to pull the basic_ad pre-built report. This pre-built report should be enabled in your connector by default. However, to confirm this pre-built report is actively syncing you may perform the following steps:
    1. Navigate to the connector schema tab.
    2. Search for basic_ad and confirm it is selected.
    3. If not selected, do so and sync. If already selected you are ready to run the models!

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

Include the following facebook_ads package version in your packages.yml file:

TIP: Check dbt Hub for the latest installation instructions or read the dbt docs for more information on installing packages.

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

Do NOT include the facebook_ads_source package in this file. The transformation package itself has a dependency on it and will install the source package as well.

Step 3: Define database and schema variables

By default, this package runs using your destination and the facebook_ads schema. If this is not where your Facebook Ads data is (for example, if your Facebook Ads schema is named facebook_ads_fivetran), add the following configuration to your root dbt_project.yml file:

vars:
    facebook_ads_database: your_destination_name
    facebook_ads_schema: your_schema_name 

(Optional) Step 4: Additional configurations

Union multiple connectors

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

vars:
    facebook_ads_union_schemas: ['facebook_ads_usa','facebook_ads_canada'] # use this if the data is in different schemas/datasets of the same database/project
    facebook_ads_union_databases: ['facebook_ads_usa','facebook_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:
    facebook_ads__basic_ad_passthrough_metrics: 
      - name: "new_custom_field"
        alias: "custom_field"
      - name: "another_one"

Change the build schema

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

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

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:
    facebook_ads_<default_source_table_name>_identifier: your_table_name 

(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/facebook_ads_source
      version: [">=0.7.0", "<0.8.0"]

    - 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 you stay consistent with the latest version of the package and refer to the CHANGELOG, DECISIONLOG and release notes for more information on changes across versions.

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 on the best workflow for contributing to a 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 be part of the community discourse? Create a post in the Fivetran community and our team along with the community can join in on the discussion!

dbt_facebook_ads's People

Contributors

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbt_facebook_ads's Issues

[Feature] Update README to reflect new pre built report flow

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

Recently the Facebook Ads connector was updated to have the creation of the pre built reports take place in the schema tab as opposed to the connector settings. Since our README in this package as well as the source package references the old setup flow, we will want to update this to be consistent with the latest workflow available in the connector.

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

DOCUMENTATION UPDATE - Update README to Reflect Source Requirements

Are you a Fivetran customer?

Fivetran created request

Is your feature request related to a problem? Please describe.

This repo does not contain the required reports needed to run the final models. We should update the repo to include these requirements.

Describe alternatives you've considered

Point users to the source package. This is not ideal and should all be included in this repo as well to allow users to look in just one location.

Additional context

The similar update we made to the dbt_google_ads repo has proven helpful. The same can be helpful here.

[Feature] Update to use `fivetran_utils.extract_url_parameter` instead of `dbt_utils.get_url_parameter`

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

An issue with dbt_utils.get_url_parameter was discovered in fivetran/dbt_linkedin_source#55 for Databricks SQL. Macro fivetran_utils.extract_url_parameter was added to solve this issue for Databricks targets (see fivetran/dbt_fivetran_utils#130 more info).

For this package, references to dbt_utils.get_url_parameter need to be updated to fivetran_utils.extract_url_parameter.

[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

[Bug] docs - add `facebook_url_tags` model description to README

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

This model exists: https://github.com/fivetran/dbt_facebook_ads/blob/main/models/facebook_ads__url_tags.sql

But is not found in the README

Relevant error log or model output

No response

Expected behavior

na

dbt Project configurations

na

Package versions

na

What database are you using dbt with?

bigquery

dbt Version

na

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 more metrics to the reports

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

When comparing the facebook ad report model to the dbt_tiktok_ads one it is clear that this package includes a lot less metrics:

See

https://github.com/fivetran/dbt_tiktok_ads/blob/e462a3274679dfb724a01a62bde80e5e38cc6f19/models/tiktok_ads__ad_report.sql#L57-L74

vs

sum(report.clicks) as clicks,
sum(report.impressions) as impressions,
sum(report.spend) as spend

There's a lot of data that's not aggregated, fields like reach and frequency are missing for example.

Is it possible to add those?

Describe alternatives you've considered

Since these sources are configurable, and can contain less or more metrics depending on how you configure them, it would also be a nice addition to have configuration options to add the needed fields.

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

QUESTION - How to Sync all required tables from Ad Reporting Connector

Your Question

There seems to be confusion with customers in regards to how to exactly obtain the tables needed for this dbt package to work. The Facebook Ads connector does not generate a few of these tables by default and therefore some additional configuration is needed by customers to sync these tables.

We should add some additional context within the README (or a different location) about how a customer will be able to sync the required tables necessary to run this package. We should also possibly consider adding similar context to the dbt_ad_reporting package to save users a step if they start at the dbt_ad_reporting package.

Additional context

dbt Slack thread within #tools-fivetran created by Arni Westh detailing the confusion and roadblocks encountered to get the package working.

Highlights from this thread include the below conclusion message:

"In case other wonders about this, I added a Custom Report with the fields I
knew I needed. This generated all the tables above, except basic_ad which I
added as a Pre-build Report. This could have been documented a bit more clearly πŸ™‚"

Please indicate the level of urgency and business impact of this request

Low level urgency and low impact as this would most likely just update the README.

[Feature] Migrate dbt_facebook_ads_creative_history into dbt_facebook_ads

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

Instead of separating facebook_ads into three different packages (source, creative_history and modeling), it would be great to consolidate Facebook Ads into the typical 'source' and 'modeling' breakdown traditionally found in our other packages. This feature request aims to consolidate the dbt_facebook_ads_creative_history package into the dbt_facebook_ads package.

Deprecation of the dbt_facebook_ads_creative_history package should not happen until all logic has been migrated over to dbt_facebook_ads and therefore can still be referenced by users in the meantime.

Describe alternatives you've considered

Keeping the package separate

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 - orders and revenue added to tables

Are you a Fivetran customer?
Connor Beem, Sr. Growth Data Analyst, Cameo

Is your feature request related to a problem? Please describe.
No problem, just would like orders and revenue in these tables as well!

Describe the solution you'd like
adding in orders and revenue from facebook basic_ad_actions

Describe alternatives you've considered
adding these in manually from this table

Additional context

Please indicate the level of urgency and business impact of this request
definitely needed for reporting!

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 work implemented.
  • No, I'd prefer if someone else did this. I don't have the time and/or don't know how to incorporate the changes necessary.

Unioning Multiple ads Connectors

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

If you have multiple facebook ads connectors in Fivetran, you can use this package on all of them simultaneously

Describe alternatives you've considered

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?

[Feature] explore optimizing `get_url_tag_query` macro for redshift

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

In this macro, we have warehouse-specific logic for parsing out jsons. For redshift, we cross join with a generated number-series, but there are now more performant methods that we've used in Hubspot and Iterable

let's update facebook ads as well!

Describe alternatives you've considered

leave it as is

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

facebook_ads__url_tag support BigQuery JSON datatype

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Materialization of facebook_ads__url_tag fails, when using bigquery adapter

Relevant error log or model output

09:51:16  17 of 24 ERROR creating sql table model dbt_skomissarov_facebook_ads.facebook_ads__url_tags  [ERROR in 2.56s]

09:51:27
09:51:27  Completed with 1 error and 0 warnings:
09:51:27
09:51:27  Database Error in model facebook_ads__url_tags (models/facebook_ads__url_tags.sql)
09:51:27    No matching signature for function TRIM for argument types: JSON, STRING. Supported signatures: TRIM(STRING, [STRING]); TRIM(BYTES, BYTES) at [37:38]
09:51:27    compiled Code at target/run/facebook_ads/models/facebook_ads__url_tags.sql

Expected behavior

Should materialize without error

dbt Project configurations

facebook_ads_schema: fivetran_facebook_ads

Package versions

  • package: fivetran/facebook_ads
    version: [">=0.6.0", "<0.7.0"]

What database are you using dbt with?

bigquery

dbt Version

dbt --version
Core:

  • installed: 1.3.0
  • latest: 1.5.0 - Update available!

Your version of dbt-core is out of date!
You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation

Plugins:

  • bigquery: 1.3.0 - Update available!
  • duckdb: 1.3.0 - Update available!

At least one plugin is out of date or incompatible with dbt-core.
You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation

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.

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.