How to Bring Ad Spend Into Mixpanel

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.

PropertyDescriptionExample
timeThe day the metrics cover2026-11-30
sourceThe ad networkGoogle, Facebook
campaign_idThe network’s campaign ID12345678
costSpend for the day152.40
clicksClicks that day310
impressionsImpressions that day18200
utm_source, utm_medium, utm_campaign, utm_content, utm_termValues matching the UTMs on your landing URLsgoogle, cpc, winter_sale
$insert_idUnique ID per network, day and campaignG-2026-11-30-12345678

Three modeling rules from Mixpanel’s guide:

  1. Send only base metrics: cost, clicks and impressions. Derived metrics like CPC or CTR are calculated in Mixpanel with formulas or custom properties.
  2. 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.
  3. 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.

  1. In Mixpanel, go to Project Settings → Warehouse Sources and connect your warehouse.
  2. Create a table or view that outputs one row per campaign per day with: date, source, campaign ID, cost, clicks, impressions and UTM fields.
  3. In Warehouse Data, add a new table and choose the Ad Spend template.
  4. Map the event name, timestamp, cost, clicks and impressions columns, plus UTM fields.
  5. 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

  1. In Google Cloud, enable the Google Ads API and create OAuth credentials.
  2. Apply for a Google Ads developer token in your manager account.
  3. Generate a refresh token for the account that has access to your ads data.
  4. Note your Google Ads customer ID (and login customer ID if you use a manager account).
  5. 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_micros to currency units, and builds Ad Data events.
  6. Send the events to Mixpanel’s /import endpoint 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

  1. Create a Meta app and generate an access token with the ads_read permission (a system user token is the most stable option for automation).
  2. Note your ad account ID (act_XXXXXXXX).
  3. Deploy a function that calls the Marketing API Insights endpoint for yesterday at campaign level, requesting spend, clicks and impressions.
  4. Map campaign names or IDs to the UTMs you use on Meta landing URLs.
  5. Send the events to Mixpanel’s /import endpoint.

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

  1. In Mixpanel’s Events view, filter to Ad Data and check a few events have the right cost, clicks, impressions and UTMs.
  2. In Insights, sum cost by source for 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 of cost, broken down by utm_source or source.

ROAS

  • Metric A: purchase_completed, property sum of revenue, broken down by utm_source.
  • Metric B: Ad Data, property sum of cost, broken down by utm_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 of clicks.
  • CTR = sum of clicks ÷ sum of impressions.
  • Cost per signup = sum of cost ÷ unique users who did sign_up_completed, broken down by the same UTM field.

Common issues

ProblemLikely cause
Spend appears twiceMissing or inconsistent $insert_id
ROAS is blank for a channelUTM values on Ad Data don’t match those on conversion events
Ad Data shows up in funnelsA distinct ID was sent with the event
Google spend is a million times too highcost_micros wasn’t divided by 1,000,000
Totals don’t match the ad platformTimezone 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