Ad data quality monitoring means catching missing days, partial loads, duplicates and spend that does not match the platform before a client sees them. In most ad warehouses, a small set of dbt tests does that job: source freshness, completeness, grain, reconciliation and anomaly checks, each routed to an owner. The worst way to find a data problem is from a client asking why yesterday's Meta spend is zero.
Ad data quality dbt tests exist to make sure you hear about it first, with enough context to fix it before the morning report goes out. This guide lists the failures we see reach client reports most often in ad pipelines, the dbt tests that catch each one, how to route the alerts, and a starter test pack you can adapt.
It assumes a warehouse with raw ad platform tables, dbt staging models and a cross-channel fact table; the SQL examples use Snowflake syntax. The syntax follows current dbt documentation, where tests are called data tests and test inputs sit under arguments (available from dbt 1.10.5).
The failures that reach client reports
Almost every bad number we have traced in an ad warehouse comes from one of these:
- Missing days. A token expired, an account was disconnected, or a job failed silently. Spend for one account drops to zero, and the dashboard shows a drop, not an error.
- Partial loads. A job timed out halfway through pagination. Some campaigns are present for the day and others are not.
- Duplicates. A retry appended a second copy of a day instead of replacing it. Spend doubles for one account and one date.
- Missed restatements. The pipeline reloads 7 days, the platform restates 28. Conversions for older days stay lower than the platform's UI forever.
- Schema changes. A platform renamed or deprecated a field. The column loads as null, and a sum quietly treats it as zero.
- Unmapped accounts. A new client account starts spending but is not in the account settings or client mapping, so its spend lands in "unknown" or disappears from client views.
- Currency mix-ups. An account in CAD is summed with USD accounts without conversion.
Each of these is cheap to detect and expensive to explain after a client spots it.
Freshness and completeness tests per platform
Freshness answers "did new data arrive?". dbt's source freshness checks the latest load timestamp in each raw table against thresholds you set. In current dbt, freshness and loaded_at_field sit under config:
# models/staging/meta_ads/_sources.yml (example)
sources:
- name: meta_ads
schema: raw_meta_ads
config:
loaded_at_field: _loaded_at
freshness:
warn_after: {count: 26, period: hour}
error_after: {count: 50, period: hour}
tables:
- name: insights_ad_daily
- name: ads
config:
freshness: null
Set thresholds per platform from how often you actually load, not from hope. dbt's guidance is to run freshness checks at least twice as often as your tightest SLA. Note that dbt build does not run source freshness, so schedule dbt source freshness as its own step.
Completeness answers "did data arrive for everything it should?". Freshness passes if one account loaded and forty did not. Completeness needs a list of what should exist: active accounts and the days they should have rows for. A singular test (example):
-- tests/assert_active_accounts_have_daily_rows.sql
with expected as (
select a.platform, a.account_id, d.date_day as report_date
from {{ ref('account_settings') }} a
cross join {{ ref('date_spine') }} d
where a.is_active
and d.date_day between dateadd(day, -7, current_date) and dateadd(day, -1, current_date)
),
actual as (
select distinct platform, account_id, report_date
from {{ ref('fct_ad_performance_daily') }}
)
select e.*
from expected e
left join actual x using (platform, account_id, report_date)
where x.account_id is null
Accounts with genuinely zero delivery will appear here, so the extractor should write a row (or a load marker) even when an account returns no data. That distinction, "no spend" versus "no load", is worth building into every pipeline.
Spend reconciliation against platform totals
Reconciliation is the test clients care about, because it is the one they can check themselves. It matters most in automated client reporting, where a number that disagrees with the platform UI is the first thing a client questions. The idea: pull an independent total from each platform at account level, one row per account per day, and compare it with the sum of your modeled table.
-- tests/assert_spend_reconciles_to_platform.sql
{{ config(severity = 'error', warn_if = '>0', error_if = '>3') }}
with modeled as (
select platform, account_id, report_date, sum(spend) as spend
from {{ ref('fct_ad_performance_daily') }}
where report_date between dateadd(day, -35, current_date) and dateadd(day, -2, current_date)
group by 1, 2, 3
),
platform_totals as (
select platform, account_id, report_date, spend
from {{ ref('stg_platform_account_totals') }}
)
select m.*, p.spend as platform_spend
from modeled m
join platform_totals p using (platform, account_id, report_date)
where abs(m.spend - p.spend) > greatest(1.00, 0.005 * p.spend)
Three details make this reliable. Compare in the account's own currency, before any FX. Use a tolerance (here the larger of one unit or 0.5%), since platforms round differently at different levels. And make sure both sides were loaded in the same run for the dates compared; otherwise restatements create false alarms.
The warn_if and error_if configs let one or two mismatches warn while a wider failure blocks the build.
When the test fails, the stored failing rows tell you where to look. A mismatch on one account and one day is usually a partial load: rerun that unit. A mismatch on every day for one account usually means a mapping or currency problem. A mismatch on every account for recent days only usually means the reconciliation totals and the detailed report were loaded at different times. Write those three cases into the runbook, so whoever is on duty does not have to rediscover them.
Duplicate and grain tests
Every fact table needs a test on its full grain. For a daily campaign table:
models:
- name: fct_ad_performance_daily
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
combination_of_columns: [report_date, platform, account_id, campaign_id]
columns:
- name: spend
data_tests:
- not_null
- name: platform
data_tests:
- accepted_values:
arguments:
values: ['google_ads', 'meta_ads', 'tiktok_ads', 'amazon_ads']
- name: account_id
data_tests:
- relationships:
arguments:
to: ref('account_settings')
field: account_id
Put the same grain test on each staging model too. A duplicate caught in staging names the platform and the load; a duplicate caught in the mart only tells you that something upstream is wrong. If you use incremental models, the unique_key on the merge prevents most duplicates, and this test proves it.
For schema changes, add not_null tests on the raw columns you depend on, at warn severity on raw tables and error severity on staging. A renamed field shows up as a column of nulls on the first load after the change.
Anomaly tests on spend and conversions
Some failures produce plausible numbers: a campaign paused by mistake, a tracking tag removed, a conversion action changed. Anomaly tests compare each account's latest day with its own recent history:
-- tests/warn_spend_anomaly.sql
{{ config(severity = 'warn') }}
with daily as (
select platform, account_id, report_date, sum(spend) as spend
from {{ ref('fct_ad_performance_daily') }}
where report_date >= dateadd(day, -29, current_date)
group by 1, 2, 3
),
baseline as (
select platform, account_id, median(spend) as median_spend
from daily
where report_date < dateadd(day, -1, current_date)
group by 1, 2
)
select d.*, b.median_spend
from daily d
join baseline b using (platform, account_id)
where d.report_date = dateadd(day, -1, current_date)
and b.median_spend > 50
and (d.spend > 3 * b.median_spend or d.spend < 0.2 * b.median_spend)
Run the same pattern on conversions per unit of spend, which catches broken tracking even when spend looks normal. Keep anomaly tests at warn severity: they flag things for a human, they should not block a build.
Watch the cost of tests as tables grow. A uniqueness test over five years of ad-level rows scans the whole table on every run. Use the where config to limit routine tests to the reload window (for example the last 35 days), and run full-history versions weekly. The failures you are trying to catch almost always happen in recent data, because that is the only data the pipeline touches each day. Packages such as dbt-expectations offer ready-made distribution tests if you prefer them to hand-written SQL.
Add unit tests (dbt 1.8 and later) for the logic around these numbers: the ROAS formula, the currency conversion and the conversion action mapping. Unit tests check that your SQL does what you meant with fixed inputs; data tests check that the data is what you expected.
Alerting and ownership
Tests only help if a person sees the failure and knows it is theirs.
- Store failures. Configure
store_failures(project-wide or on key tests) so failing rows land in an audit schema. The alert can then link to the exact accounts and days. - Route by owner. Tag tests and models with the owning team or platform (for example through
meta: {owner: ...}) and route alerts to that owner's channel, not to one shared channel everyone mutes. - Separate warn from error. Errors stop downstream builds and page someone during working hours. Warnings go to a daily digest.
- Hook into the orchestrator. In Airflow, run freshness, then build, then tests as separate tasks, with failure callbacks that post the failing test name and a link to stored failures. dbt Cloud has equivalent job notifications.
- Keep a runbook. For each common failure (expired token, rate limit, schema change), one paragraph on how to fix and backfill.
Reliable monitoring is what lets a data layer grow without a rebuild. The pipelines and automation engine we built for Tinuiti kept pace as the agency grew from 35 to more than 3,500 brands, with no second rebuild needed (Tinuiti case study). For Protego, an Amazon enforcement-risk SaaS, we normalized more than 20 risk signals across Amazon reports, with about five minutes from signal ingestion to risk score update (Protego case study). Freshness targets like that only hold with tests and alerts behind them.
A starter pack of ad data quality dbt tests
If you are starting from nothing, add these in order:
- Source freshness on every raw ad table, with per-platform thresholds
- A completeness test: one row (or load marker) per active account per day for the last 7 days
- Grain uniqueness on every staging model and fact table
not_nullon keys, dates, spend and currencyaccepted_valueson platform and currency, and relationships to account and campaign dimensions- Spend reconciliation against account-level platform totals, with a tolerance
- A restatement check: conversions for days 8 to 28 ago compared with the platform totals reloaded today
- Spend and conversion-rate anomaly warnings per account
- Unit tests for ROAS, FX conversion and conversion action mapping
- Stored failures and owner-based alert routing
Our cross-channel dbt model shows the tables these tests protect, and our post on conversion lag in ROAS reporting explains why the restatement check matters. For how we run this for clients, see pipeline reliability and our marketing data warehouse work, request an ad data plan, or book a free 30-minute ad data review.
Frequently asked questions
What dbt tests should every marketing model have?
At minimum: source freshness on every raw ad table, a uniqueness test on the model's full grain, not_null on keys and spend, accepted values on platform and currency, relationships from facts to account and campaign dimensions, and one reconciliation test that compares warehouse spend with a platform total. Those six catch most of the failures that reach client reports.
How do I check ad spend matches the platform?
Pull an independent account-level total from each platform API (one row per account per day) into its own raw table, separate from the detailed report you model. Then write a singular dbt test that sums your fact table to the same account and day and returns rows where the difference exceeds a small tolerance. Compare against days that have finished restating, or reload both sides in the same run.
How do I alert on missing ad data?
Run dbt source freshness on a schedule at least twice as often as your tightest data SLA, plus a completeness test that expects one row per active account per day. Send failures to a channel the owning engineer watches, with the account and platform in the message, and to a ticket queue if they persist past one run. An alert nobody owns is the same as no alert.
Which ecommerce data quality monitoring tools do we need?
For ad and ecommerce data in a warehouse, dbt's built-in data tests and source freshness cover most needs, with packages such as dbt_utils and dbt-expectations for grain and distribution checks, and your orchestrator for scheduling and alerts. Dedicated data observability tools add automatic anomaly detection and lineage views, which help at larger scale. None of them replaces a reconciliation test against platform totals, because only you know which totals your clients compare.