Facebook Ads model

Campaign performance daily

Daily campaign performance with the rates Ads Manager shows: CTR, CPC, CPM, cost per purchase and ROAS.

Grain
date_day x account_id x campaign_id
Built from
  1. 8
    Raw tables
  2. 8
    Staging
  3. 2
    Core
  4. 1
    Analytics
Reads from Facebook Ads
accountadad_roas_insightad_roas_insight_action_valuesad_roas_insight_actionsad_setad_set_attributioncampaign
Ships as
Weld and dbt SQL, open source on GitHub
core.facebook_ads.campaign_performance_daily
1-- core.facebook_ads.campaign_performance_daily
2-- Daily campaign performance with the rates Ads Manager shows: CTR, CPC, CPM,
3-- cost per purchase and ROAS.
4--
5-- Grain: date_day x account_id x campaign_id. Currency: the ad account's.
6-- Depends on: core.facebook_ads.ad_performance_daily
7--
8-- Summed from ads: every Meta delivery is attributed to an ad, so ad totals add
9-- up to campaign totals. Reach does not add up (one person can see several ads)
10-- and is left out. conversions are purchases, as defined in ad_performance_daily.
11-- Rates are ratios of sums; to report a week or a month, re-sum the base columns
12-- and divide again.
13
14SELECT
15    date_day,
16    account_id,
17    account_name,
18    currency,
19    campaign_id,
20    campaign_name,
21
22    SUM(spend)            AS spend,
23    SUM(impressions)      AS impressions,
24    SUM(clicks)           AS clicks,
25    SUM(conversions)      AS conversions,
26    SUM(conversion_value) AS conversion_value,
27
28    SAFE_DIVIDE(SUM(clicks), SUM(impressions))       AS ctr,
29    SAFE_DIVIDE(SUM(spend), SUM(clicks))             AS cpc,
30    SAFE_DIVIDE(SUM(spend), SUM(impressions)) * 1000 AS cpm,
31    SAFE_DIVIDE(SUM(spend), SUM(conversions))        AS cost_per_conversion,
32    SAFE_DIVIDE(SUM(conversion_value), SUM(spend))   AS roas,
33
34    'facebook_ads'                  AS source,
35    MAX(campaign_objective)         AS campaign_objective,
36    SUM(clicks_all)                 AS clicks_all,
37    COUNT(DISTINCT ad_id)           AS active_ads
38FROM {{core.facebook_ads.ad_performance_daily}}
39GROUP BY 1, 2, 3, 4, 5, 6

This model and the 10 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().

Notes

How it counts. And where it stops.

Summed from ads: every Meta delivery is attributed to an ad, so ad totals add up to campaign totals. Reach does not add up (one person can see several ads) and is left out. conversions are purchases, as defined in ad_performance_daily. Rates are ratios of sums; to report a week or a month, re-sum the base columns and divide again.

Raw tables it reads

  • raw.facebook_ads.account
  • raw.facebook_ads.ad
  • raw.facebook_ads.ad_roas_insight
  • raw.facebook_ads.ad_roas_insight_action_values
  • raw.facebook_ads.ad_roas_insight_actions
  • raw.facebook_ads.ad_set
  • raw.facebook_ads.ad_set_attribution
  • raw.facebook_ads.campaign

Put Facebook Ads in front
of your agents.

Connect Facebook Ads, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.