Mixpanel knows what users do after they arrive. Ad platforms know what you paid to bring them there. Putting the two together lets you calculate return on ad spend (ROAS), cost per click (CPC) and cost per acquisition against real in-product conversions, not just platform-reported ones.
This guide explains Mixpanel’s ad spend data model and the four ways to load ad data: the Ad Spend template with Warehouse Connectors, scheduled cloud functions, a managed integration, and other pipeline tools. It ends with how to build ROAS reports.
What ad spend data looks like in Mixpanel
Mixpanel’s documented approach is to send ad performance as a special event called Ad Data, one event per campaign per day.
| Property | Description | Example |
|---|---|---|
time | The day the metrics cover | 2026-11-30 |
source | The ad network | Google, Facebook |
campaign_id | The network’s campaign ID | 12345678 |
cost | Spend for the day | 152.40 |
clicks | Clicks that day | 310 |
impressions | Impressions that day | 18200 |
utm_source, utm_medium, utm_campaign, utm_content, utm_term | Values matching the UTMs on your landing URLs | google, cpc, winter_sale |
$insert_id | Unique ID per network, day and campaign | G-2026-11-30-12345678 |
Three modeling rules from Mixpanel’s guide:
- Send only base metrics: cost, clicks and impressions. Derived metrics like CPC or CTR are calculated in Mixpanel with formulas or custom properties.
- Don’t send a distinct ID. Ad data isn’t tied to a person, so leaving out the distinct ID keeps it out of user-behavior reports such as Funnels and Retention.
- Aggregate to one event per campaign per day, since ad platforms report at daily granularity.
The insert ID pattern
Build $insert_id from network, date and campaign ID, for example G-{date}-{campaign_id} for Google and FB-{date}-{campaign_id} for Meta. If you re-send a day’s data (for example because spend was updated), Mixpanel deduplicates it instead of doubling it. If IDs get long, hash them (Mixpanel suggests MD5) to stay within the insert ID length limit.
Currency
Mixpanel’s examples send cost in USD. If your accounts spend in several currencies, convert to one reporting currency before sending, and do the same for revenue on your conversion events. Google Ads reports cost in micros (millionths of the currency unit), so divide by 1,000,000.
UTM matching
The UTM properties on Ad Data must match the UTMs captured on your site events, character for character. If campaigns are tagged utm_campaign=Winter_Sale on the landing URL and winter_sale in your ad export, ROAS breaks. Decide on one naming convention for campaign tags and apply it in the ad platform’s tracking templates.
Option 1: Ad Spend template with Warehouse Connectors
If ad data is already in BigQuery, Snowflake, Databricks or Redshift (for example via Fivetran, Airbyte or the native BigQuery Data Transfer Service for Google Ads), this is the simplest route. No custom code.
- In Mixpanel, go to Project Settings → Warehouse Sources and connect your warehouse.
- Create a table or view that outputs one row per campaign per day with: date, source, campaign ID, cost, clicks, impressions and UTM fields.
- In Warehouse Data, add a new table and choose the Ad Spend template.
- Map the event name, timestamp, cost, clicks and impressions columns, plus UTM fields.
- Choose a sync schedule (daily is usually enough) and run the first sync.
Warehouse Connectors require the relevant Mixpanel add-on; see post 20 for sync modes.
Option 2: Scheduled cloud functions
Mixpanel’s guide includes example functions for Google Ads and Facebook that run daily on Google Cloud, pull yesterday’s campaign metrics, and send Ad Data events to Mixpanel’s Import API.
Google Ads
- In Google Cloud, enable the Google Ads API and create OAuth credentials.
- Apply for a Google Ads developer token in your manager account.
- Generate a refresh token for the account that has access to your ads data.
- Note your Google Ads customer ID (and login customer ID if you use a manager account).
- Deploy a function (Mixpanel’s example uses Node.js) that queries campaign-level metrics for yesterday with the Google Ads Reporting API (GAQL), converts
cost_microsto currency units, and buildsAd Dataevents. - Send the events to Mixpanel’s
/importendpoint with a service account (post 31).
A simplified query for campaign metrics:
SELECT
segments.date,
campaign.id,
campaign.name,
metrics.cost_micros,
metrics.clicks,
metrics.impressions
FROM campaign
WHERE segments.date DURING YESTERDAY
Meta (Facebook) Ads
- Create a Meta app and generate an access token with the
ads_readpermission (a system user token is the most stable option for automation). - Note your ad account ID (
act_XXXXXXXX). - Deploy a function that calls the Marketing API Insights endpoint for yesterday at campaign level, requesting
spend,clicksandimpressions. - Map campaign names or IDs to the UTMs you use on Meta landing URLs.
- Send the events to Mixpanel’s
/importendpoint.
Scheduling
Run each function once a day with Cloud Scheduler (Mixpanel’s example uses 0 8 * * * in UTC), so the previous day’s data is final. Many teams also re-pull the last 3 to 7 days each run, because ad platforms adjust recent spend. The insert ID pattern makes those re-sends safe.
The same approach works for LinkedIn Ads, TikTok Ads and X (Twitter) Ads, which all provide reporting APIs.
Option 3: Managed integration
Mixpanel’s ad spend docs point to Vendo, a Mixpanel partner, for a no-code integration that brings ad data from Google, Meta and other platforms into Mixpanel. This suits teams without engineering time for cloud functions.
Option 4: Other pipeline tools
ETL tools and automation platforms (such as Zapier, Make, or data pipeline products) can also move ad data into Mixpanel or into your warehouse first. Check that the tool can send aggregated daily rows with a stable insert ID; tools that send one event per lead or click don’t fit the Ad Data model.
Step: Verify the data
- In Mixpanel’s Events view, filter to
Ad Dataand check a few events have the right cost, clicks, impressions and UTMs. - In Insights, sum
costbysourcefor last month and compare with the totals shown in Google Ads and Meta Ads Manager. Small differences are normal from timezone and attribution windows; large ones mean missing days or wrong currency conversion.
Building ROAS and cost reports
With ad data and conversion events in the same project, you can build marketing metrics in Insights with formulas.
Spend by channel
- Metric A:
Ad Data, measured as property sum ofcost, broken down byutm_sourceorsource.
ROAS
- Metric A:
purchase_completed, property sum ofrevenue, broken down byutm_source. - Metric B:
Ad Data, property sum ofcost, broken down byutm_source. - Formula: A ÷ B.
For this to work, your conversion events must carry the UTM values that match the ad data. Decide whether you’re using first-touch or last-touch UTMs, or use Mixpanel’s attribution models (post 5).
CPC, CTR and cost per signup
- CPC = sum of
cost÷ sum ofclicks. - CTR = sum of
clicks÷ sum ofimpressions. - Cost per signup = sum of
cost÷ unique users who didsign_up_completed, broken down by the same UTM field.
Common issues
| Problem | Likely cause |
|---|---|
| Spend appears twice | Missing or inconsistent $insert_id |
| ROAS is blank for a channel | UTM values on Ad Data don’t match those on conversion events |
| Ad Data shows up in funnels | A distinct ID was sent with the event |
| Google spend is a million times too high | cost_micros wasn’t divided by 1,000,000 |
| Totals don’t match the ad platform | Timezone differences or late spend adjustments not re-pulled |
Summary
Send one Ad Data event per campaign per day with cost, clicks, impressions and matching UTMs, no distinct ID, and a deterministic insert ID. Load it through Warehouse Connectors, a scheduled function, or a managed integration. Then use Insights formulas to calculate ROAS, CPC and cost per conversion next to real product behavior.
Sources
- Mixpanel: Ad Spend integration and data model
- Mixpanel: Ad spend how-to (Warehouse Connectors)
- Google Ads API: Reporting overview
- Meta: Marketing API Insights
- Mixpanel API reference: Import Events
