Facebook Ads¶
Connect Facebook Ads as a data source using OAuth 2.0.
Tokens expire every 60 days
Facebook Ads tokens expire after 60 days with no automatic refresh. Set a 45-day calendar reminder to re-authenticate before your syncs stop working. Run dango oauth facebook_ads to renew.
Overview¶
| Feature | Details |
|---|---|
| Auth | OAuth 2.0 (manual token exchange) |
| Incremental | Yes (date-based with lookback) |
| Category | Marketing & Analytics |
Facebook Ads loads campaign data and performance insights into DuckDB. By default, Dango loads all 6 resources: campaigns, ads, ad sets, ad creatives, leads, and daily performance insights.
Managing this source in the Web UI
After setup, manage this source from the Sources page in the Web UI (http://localhost:8800/sources). Trigger syncs, view history, and monitor status without using the CLI. See Web UI — Sources.
Prerequisites¶
Before adding Facebook Ads as a source, you need:
- Facebook Business account with access to an Ad Account
- Ad Account ID — the numeric ID from your Ads Manager URL (without the
act_prefix) - Facebook App (for token exchange) — App ID and App Secret from developers.facebook.com
Token Lifecycle¶
Facebook uses a unique token flow compared to other OAuth providers:
Short-lived token (~1 hour)
↓ exchanged at setup
Long-lived token (60 days)
↓ expires
Must re-authenticate
- At setup: You generate a short-lived token from the Graph API Explorer, then Dango exchanges it for a 60-day long-lived token using your App ID and App Secret.
- During sync: Dango uses the long-lived token directly (no auto-refresh).
- At expiry: After 60 days, you must re-authenticate. If your App ID and App Secret are stored, Dango can extend the token without a full re-auth flow.
Setup¶
Step 1: Create a Facebook App¶
- Go to Facebook Developers
- Click My Apps > Create App
- Select Business type
- Add the Marketing API product
- Note your App ID and App Secret (Settings > Basic)
Step 2: Generate a Short-Lived Token¶
- Go to the Graph API Explorer
- Select your app from the dropdown
- Click Generate Access Token
- Grant the required permissions:
ads_read,ads_management - Copy the token
Step 3: Add Source¶
Or authenticate directly:
The wizard will:
- Prompt for your short-lived access token (from Graph API Explorer)
- Prompt for your App ID and App Secret
- Exchange for a 60-day long-lived token
- Prompt for your Ad Account ID (numeric, without
act_prefix)
? Short-lived Access Token: EAABs...
? Facebook App ID: 123456789
? Facebook App Secret: abc123...
✓ Token exchanged — valid for 60 days (expires 2024-07-15)
? Ad Account ID (numeric): 987654321
Step 4: Sync¶
Configuration¶
sources.yml¶
version: '1.0'
sources:
- name: facebook_campaigns
type: facebook_ads
enabled: true
description: Facebook ad campaign performance
facebook_ads:
account_id: "987654321"
access_token_env: "FB_ACCESS_TOKEN"
initial_load_past_days: 30
.env¶
The long-lived access token is stored in your .env file:
Never commit secrets
.env is gitignored by default. Never add it to version control.
Resources and Tables¶
Available Resources¶
| Resource | Default | Description |
|---|---|---|
campaigns | Yes | Campaign metadata (name, status, objective) |
ads | Yes | Individual ad metadata |
ad_sets | Yes | Ad set targeting and budget |
ad_creatives | Yes | Creative assets and copy |
leads | Yes | Lead form submissions |
facebook_insights | Yes | Daily performance metrics |
Default Tables Loaded¶
Data loads into the raw_{source_name} schema:
-- Campaign metadata
SELECT * FROM raw_facebook_campaigns.campaigns LIMIT 10;
-- Daily performance insights
SELECT * FROM raw_facebook_campaigns.facebook_insights
WHERE date_start >= '2024-01-01'
ORDER BY spend DESC
LIMIT 10;
The facebook_insights table includes key metrics:
- reach — unique users who saw the ad
- impressions — total times the ad was shown
- clicks — total clicks
- spend — amount spent (in account currency)
- ctr — click-through rate
- cpc — cost per click
- cpm — cost per 1,000 impressions
Sync Behavior¶
- Incremental with
attribution_window_days_lag: 28— re-fetches the last 28 days to capture attribution updates (Facebook's dlt source default is 7 days; Dango sets 28 to cover the full attribution window) - First sync loads the past 30 days of insights (configurable via
initial_load_past_days) - Facebook retains insights data for 37 months
- Entity data (campaigns, ads, ad_sets) is fully reloaded each sync
Renewing Tokens¶
Option 1: Auto-Extend (If App Credentials Stored)¶
If you provided your App ID and App Secret during initial setup, Dango can extend the token:
dango oauth facebook_ads
# Dango detects the existing token and offers to extend it
# ✓ Token extended — valid for 60 more days
Option 2: Full Re-Authentication¶
If auto-extend is unavailable, generate a new short-lived token from the Graph API Explorer and run the setup again:
Troubleshooting¶
Token Expired¶
Problem: Error validating access token or sync failures after 60 days
Solution: Re-authenticate immediately:
Set a 45-day calendar reminder to renew before expiry.
Account ID Format¶
Problem: Invalid account ID error
Solution: Use the numeric ID only, without the act_ prefix. For example, use 987654321 instead of act_987654321. Find it in the Ads Manager URL.
Rate Limits¶
Problem: User request limit reached or Application request limit reached
Solution: Facebook rate limits are 200 calls per hour per user and 4,800 per day per app. Solutions:
- Reduce sync frequency
- Remove unused resources (e.g.,
ad_creatives,leads) - Use a dedicated Facebook app for Dango
Permission Errors¶
Problem: OAuthException with code 200 or 10
Solutions:
- Re-generate the access token with
ads_readandads_managementpermissions - Verify your Facebook account has access to the Ad Account
- Check that your Facebook App has the Marketing API product added
Token Debugger¶
Use the Access Token Debugger to check your token's status, permissions, and expiry date.
Next Steps¶
- OAuth Sources - OAuth overview and token management
- Sync Modes - Understand incremental loading
- Deduplication - Handle lookback-day overlaps
- Adding Sources - General source setup guide
- Credentials - Token storage and security