1. Home
  2. Blog
  3. Cross-Channel Ad Performance Model in dbt

Data Engineering

Cross-Channel Ad Performance Model in dbt: Spend, ROAS and Cross-Channel Attribution

Build a cross-channel ad performance model in dbt: platform staging, conformed dimensions, cross-channel attribution rules, incremental reloads and tests.

Every agency and brand with more than two ad platforms eventually needs one table that answers "what did we spend and what did we get, by channel, by day". The short version: one staging model per platform that maps to a shared column contract, a union at date and campaign grain, and an incremental fact table that reloads a rolling window and labels each platform's attribution rule. This is a hands-on build of that cross-channel ad performance model in dbt, using Google Ads, Meta, TikTok and Amazon Ads as the four sources. It goes further than our overview of building a marketing warehouse with dbt and Snowflake: actual model structure, column contracts, incremental logic and tests.

The examples use Snowflake SQL and current dbt syntax. They are examples to adapt, not a package to install.

Cross-channel ad performance: the target fact table

Start by writing down the output, then work backwards. The target is fct_ad_performance_daily with this grain and columns:

  • Grain: one row per date, platform, account and campaign
  • Keys: report_date, platform, account_id, campaign_id
  • Descriptors: campaign_name, channel, account_currency, account_time_zone
  • Delivery: spend, impressions, clicks (in account currency)
  • Platform-reported results: platform_conversions, platform_conversion_value, attribution_rule
  • Reporting currency: spend_usd, platform_conversion_value_usd

Campaign level is the right default grain for a cross-channel table. Ad-level and keyword-level tables are useful, but the dimensions do not line up across platforms (Amazon targets, Google keywords, Meta ads) and forcing them into one table creates a sparse mess. Keep those as platform-specific marts.

The project layout:

models/
  staging/
    google_ads/stg_google_ads__campaign_daily.sql
    meta_ads/stg_meta_ads__campaign_daily.sql
    tiktok_ads/stg_tiktok_ads__campaign_daily.sql
    amazon_ads/stg_amazon_ads__campaign_daily.sql
  intermediate/
    int_ad_performance_unioned.sql
  marts/
    fct_ad_performance_daily.sql
    dim_campaign.sql
seeds/
  channel_map.csv
  account_settings.csv

Staging: rename, cast and standardize per platform

Each staging model does four things and nothing else: rename fields to the shared contract, cast types, convert units, and add the platform and attribution_rule labels. No joins and no business logic.

The platform quirks staging absorbs:

  • Google Ads reports cost_micros. Divide by 1,000,000.
  • Meta returns metrics as strings and conversions inside an actions array. Flatten and cast, and pick the client's primary action type from a mapping seed.
  • TikTok often returns metric values as strings too, with dates as timestamps at midnight. Cast both.
  • Amazon Ads reports return fixed attribution windows as separate columns (Sponsored Products reports offer windows such as 7 and 14 days). Choose one per ad product and say so in attribution_rule.

A Google Ads staging model (example):

-- models/staging/google_ads/stg_google_ads__campaign_daily.sql
select
    segments_date::date                     as report_date,
    'google_ads'                            as platform,
    customer_id::varchar                    as account_id,
    campaign_id::varchar                    as campaign_id,
    campaign_name,
    metrics_cost_micros / 1000000.0         as spend,
    metrics_impressions                     as impressions,
    metrics_clicks                          as clicks,
    metrics_conversions                     as platform_conversions,
    metrics_conversions_value               as platform_conversion_value,
    'google_ads_account_default_by_click'   as attribution_rule,
    _loaded_at
from {{ source('google_ads', 'campaign_daily') }}

Every staging model must output exactly the same columns, in the same order, with the same types. A short YAML contract on each staging model (contract: {enforced: true} with typed columns) makes dbt fail the build if one drifts.

Where staging models usually go wrong

Three mistakes show up in almost every ad warehouse we audit. First, deduplication is skipped because "the API never returns duplicates". It does not, but your loads can, when a retry appends a second copy of a day. Deduplicate in staging on the natural key and the latest _loaded_at. Second, deleted and archived campaigns are filtered out. Their historical spend is real, so keep them and carry the status as a column. Third, currency conversion happens in staging. Keep staging in the account's own currency and convert once, in the mart, so there is exactly one place where FX logic lives.

Conformed dimensions: channel, campaign, date and currency

Four dimensions make the union usable.

Channel. Platforms are not channels. Google Ads covers search, shopping, video and Performance Max. Meta and TikTok are paid social. Amazon Ads is retail media. A seed maps platform plus the platform's own campaign type to a reporting channel:

platform,campaign_type,channel
google_ads,SEARCH,Paid search
google_ads,PERFORMANCE_MAX,Performance Max
meta_ads,ALL,Paid social
tiktok_ads,ALL,Paid social
amazon_ads,SPONSORED_PRODUCTS,Retail media

Campaign. dim_campaign takes the latest name, status and objective per campaign from each platform's campaign entity table, keyed on platform plus campaign ID. Campaign IDs are only unique within a platform, so the key is always the pair. Parse naming conventions (client, brand, market) here, once.

Date. Use a date spine so days with zero spend still exist. Each platform reports in its account's time zone, and you should keep that local date as report_date rather than shifting daily rows to UTC.

Currency. An account_settings seed (or a table loaded from each platform's account endpoint) gives each account's currency and IANA time zone. Join a daily FX rate table on date and currency to produce the USD columns. Keep the original currency columns too.

Cross-channel attribution: different grains and attribution windows

The union is simple once staging is right:

-- models/intermediate/int_ad_performance_unioned.sql
{% set platforms = ['google_ads', 'meta_ads', 'tiktok_ads', 'amazon_ads'] %}
{% for p in platforms %}
select * from {{ ref('stg_' ~ p ~ '__campaign_daily') }}
{% if not loop.last %}union all{% endif %}
{% endfor %}

The hard part is honesty about what the result columns mean. Spend, impressions and clicks are reasonably comparable across platforms. Platform conversions are not: each platform credits itself under its own windows and rules, so Meta's 7-day click plus 1-day view number and Amazon's 14-day number cannot be added into "total conversions". Three rules we apply:

  • Keep attribution_rule on every row and show it in the BI layer.
  • Never sum platform_conversions across platforms without a label that says it double counts.
  • Compute blended metrics (total spend against total store revenue from Shopify or your order system) in a separate mart, using one ROAS definition for everything.

Crediting conversions across channels at the order or user level is a separate model built on top of this table. Our attribution and marketing mix modeling work starts from a fact table like this one rather than replacing it.

If one platform only reports weekly or by campaign lifetime, do not spread it across days to fit the grain. Load it into its own table at its native grain.

Incremental models and lookback reloads

Ad data restates. Meta's numbers settle after 28 days, Google's conversions move for the length of the conversion window, and Amazon's attributed sales update after the click. An incremental model that only processes new dates will be wrong forever. Reprocess a rolling window and merge on the full key:

-- models/marts/fct_ad_performance_daily.sql
{{ config(
    materialized = 'incremental',
    incremental_strategy = 'merge',
    unique_key = ['report_date', 'platform', 'account_id', 'campaign_id'],
    on_schema_change = 'append_new_columns'
) }}

select
    u.*,
    a.currency                                   as account_currency,
    a.time_zone                                  as account_time_zone,
    u.spend * fx.rate_to_usd                     as spend_usd,
    u.platform_conversion_value * fx.rate_to_usd as platform_conversion_value_usd
from {{ ref('int_ad_performance_unioned') }} u
join {{ ref('account_settings') }} a
  on a.platform = u.platform and a.account_id = u.account_id
left join {{ ref('fx_rates_daily') }} fx
  on fx.rate_date = u.report_date and fx.currency = a.currency

{% if is_incremental() %}
where u.report_date >= dateadd(day, -{{ var('ad_lookback_days', 35) }}, current_date)
{% endif %}

Set ad_lookback_days to cover the longest restatement window among your platforms, and match it to the reload window in your extractors: there is no point merging 35 days in dbt if the pipeline only re-pulls 7. Schedule an occasional --full-refresh (monthly is common) to catch anything the window missed, such as a campaign renamed long ago. On BigQuery, insert_overwrite on date partitions is often cheaper than merge for this pattern.

Two situations the rolling window does not cover. When a new client account is connected, its history arrives all at once, often years of dates outside the window. Run a targeted backfill for that account (a full refresh of the model, or a run with a wider ad_lookback_days var) rather than waiting for the monthly refresh. When a platform changes a metric definition or you change a client's primary conversion action, history needs rebuilding too. Both are reasons to keep raw data in your warehouse indefinitely: you can always rebuild the marts from it.

Tests and documentation

The tests that catch real problems in this model:

  • Grain: dbt_utils.unique_combination_of_columns on the four key columns.
  • Not null: keys, spend and account_currency.
  • Accepted values: platform limited to the four sources.
  • Relationships: every account in the fact exists in account_settings, and every campaign in dim_campaign.
  • FX coverage: a singular test that returns rows where spend > 0 and spend_usd is null.
  • Reconciliation: a singular test comparing each platform's spend for a recent day with an account-level total pulled separately, within a tolerance.

Unit tests (dbt 1.8 and later) are worth adding for the Meta action-type mapping and the FX conversion, since those are logic, not data. Document every column in YAML, and above all attribution_rule, because that is the first question a client asks.

Exposing the model to BI and AI

Dashboards should read from fct_ad_performance_daily, dim_campaign and a blended mart, never from staging or raw tables. Defining the core metrics (spend, ROAS, CPA) once in the dbt Semantic Layer or in your BI tool's semantic model keeps every report on the same formulas.

For agencies sharing data with clients on Snowflake, Secure Data Sharing with a secure view filtered to that client's accounts lets the client query its own rows from its own Snowflake account with no data copied (a consumer in another region or cloud needs replication first). That is cleaner than exporting files. For AI assistants and agents, give them the documented marts and the column descriptions, not raw tables, and limit any automated action to rules you have approved.

We have built this pattern at scale. For BTR Media, one set of ETL pipelines feeds one data model and one dashboard across Amazon, Walmart and Instacart, and platforms can be added without a rebuild (case study). For Tinuiti, multi-source pipelines for five marketplaces feed one unified BI warehouse (case study). If your sources include Google Ads, our Google Ads API reporting guide covers the extraction side.

See our dbt and Airflow and marketing data warehouse pages for how we run this in production, or book a free 30-minute ad data review to scope it for your platforms.

Frequently asked questions

How do I combine Google, Meta and Amazon ads in dbt?

Give each platform its own staging model that renames, casts and converts units into one shared column contract (date, platform, account, campaign, spend, impressions, clicks, platform conversions, platform conversion value, currency, attribution window). Then union the staging models in one fact model at a single grain, usually date by campaign. Keep platform-reported conversions labeled by platform and window rather than summing them into one total.

Should ad models be incremental?

Usually yes once tables reach millions of rows, but with a lookback. Ad platforms restate recent days, so an incremental model must reprocess a rolling window (for example the last 30 days) and merge on a unique key, not just append new dates. Small accounts with a few thousand rows a day can stay as plain tables, which are simpler and always correct.

Are there dbt packages for ad platforms?

Yes. Fivetran publishes open-source dbt packages that model its connectors' ad platform schemas, including a combined ad reporting package. They are a good reference even if you do not use Fivetran, but they assume that connector's raw schema. If your data arrives from custom pipelines or several tools, you will write your own staging models and can borrow the conventions.

What is cross-channel attribution?

Cross-channel attribution assigns credit for a conversion across the ad channels a customer touched, such as Google, Meta, TikTok and Amazon, instead of letting each platform credit itself. Platform-reported conversions overlap, so they cannot simply be added up. A cross-channel view starts from a conformed table of spend and results by channel, like the one in this guide, and then applies one rule to every channel.

How do you measure cross-channel attribution?

Start with numbers that cannot double count: total ad spend against total revenue from your order system (blended ROAS or MER). For credit by channel, the common methods are a multi-touch model on order-level journeys, marketing mix modeling on weekly spend and sales, and incrementality tests such as geo-lift holdouts. Each needs the same clean cross-channel spend table underneath.

Sources

Want this built for you?

See how we approach it in dbt and Airflow for ad data, or talk to an engineer about your accounts.

Talk to an engineer