Skip to main content
Sanity → MixpanelIntegration guide

Connecting Sanity to Mixpanel

Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. Mixpanel is a product analytics tool, not an ad platform, which means it has no attribution model of its own and will faithfully report whatever event schema you give it — including a bad one. The join between them succeeds or fails on one thing: whether the distinct_id reaches the front-end conversion, not a Sanity record before the conversion happens, because Mixpanel can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Mixpanel on a Sanity front end: page views and content properties

Mixpanel on a Sanity site lives in the front end: pick one code path that sends page views on each route change, and add the Sanity _type, _id and content category as properties. Call identify at sign-up, send purchases from commerce or billing with the same ID and transaction ID as $insert_id, and never set distinct_id at build time.

Mixpanel on a Sanity site lives entirely in the front-end application. The usual failure isn't Mixpanel or Sanity; it's that a Next.js or Nuxt front end changes routes without a full page load, so page views fire once per session or twice per route depending on how tracking was added. Decide which single code path sends the page view on route change and verify it in Mixpanel's live view.

Register the Sanity _type as a property on content pages and send the _id and content category with each page view, so product and content teams can see which document types sit on the path to signup. Keep event names short and few. A content site with a separate event per template quickly fills Mixpanel with near-duplicates that never share a funnel.

Identity has to be continuous between the front end and the system that records signups or purchases. Call identify with your own user ID at signup so earlier anonymous content views join the identified profile, and send purchases from the commerce or billing backend with that same ID and the transaction ID as $insert_id. If pages are statically generated, make sure the distinct_id comes from the browser at runtime, never from build-time code shared by every visitor.

Sanity → Mixpanel · what breaks

Why this join usually fails — Sanity → Mixpanel

  1. 01

    The distinct_id never reaches Sanity

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  2. 02

    A headless stack diagnosed at the wrong layer

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  3. 03

    One event schema, two teams, no agreement

    Marketing names an event Purchase, the product team names it purchase_completed, and both are sent. Mixpanel treats them as unrelated, every funnel silently splits, and two teams spend a quarter arguing about which number is right when both are.

  4. 04

    Nothing reconciles afterwards

    Mixpanel shows events in the live view within moments. Check that the distinct_id matches the signed-in user rather than a lingering anonymous ID, because that is the failure that quietly breaks every cross-signup funnel.

Sanity → Mixpanel · the fix

What working looks like — Sanity → Mixpanel

  • The distinct_id on every conversion

  • Conversions arriving in Mixpanel

    The event lands on the user profile and becomes available in funnels, retention and cohort analysis.

  • Reconciled against the source

Sanity → Mixpanel · architecture

How Sanity and Mixpanel actually connect

  1. 1

    Sanity holds the truth

    Sanity's real-time content APIs make it excellent at what it does and irrelevant to conversion measurement. Establishing that early saves the client money.

  2. 2

    Mixpanel needs a click to match

    Mixpanel needs a distinct_id, an event name and its properties. Events without a distinct_id are rejected; events with the wrong one land on a stranger's profile.

  3. 3

    The identifier is the bridge

    The distinct_id, captured at the visit and carried into the front-end conversion, not a Sanity record.

  4. 4

    The event source decides reliability

    Send from wherever the money is recorded, not from the content layer.

  5. 5

    Deduplication at the destination

    Mixpanel deduplicates on $insert_id within a time window. Without it, a retried server request creates a second event, and because Mixpanel is where product decisions get made, that inflation ends up in a roadmap rather than in an ad report.

Sanity → Mixpanel · normal or broken

Working vs. broken, side by side — Sanity → Mixpanel

Normal, not a fault

  • The distinct_id present on the conversion

  • Sent from your commerce or CRM system

  • Deduplicated correctly

    Mixpanel deduplicates on $insert_id within a time window. Without it, a retried server request creates a second event, and because Mixpanel is where product decisions get made, that inflation ends up in a roadmap rather than in an ad report.

  • Reconciles with the source

Actually broken

  • The distinct_id missing on most records

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  • Sent from the browser

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  • Counted twice, or not at all

    Marketing names an event Purchase, the product team names it purchase_completed, and both are sent. Mixpanel treats them as unrelated, every funnel silently splits, and two teams spend a quarter arguing about which number is right when both are.

  • Nobody has reconciled it

Sanity → Mixpanel · diagnose

Diagnostic order — Sanity → Mixpanel

  1. 01

    Count conversions carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Identify the front-end framework, not the CMS

    The routing behaviour that breaks tracking belongs to Next.js, Nuxt or whatever renders the site.

  4. 04

    List every event name in the project and look for near-duplicates

    Case differences, tense differences and synonyms are the usual finding, and they are cheap to fix before a year of data is built on them.

  5. 05

    Read the match rate, not the success message

    Mixpanel shows events in the live view within moments. Check that the distinct_id matches the signed-in user rather than a lingering anonymous ID, because that is the failure that quietly breaks every cross-signup funnel.

Sanity → Mixpanel · prove

How it gets proven — Sanity → Mixpanel

Source of truth

Your commerce, CRM or billing system — Sanity has no orders and no customers.

  • The distinct_id confirmed present on a live conversion.
  • Purchase events reconciled per transaction against your billing system, with identity aliasing verified across the signup boundary.
  • The conversion confirmed sourced from the commerce system, with front-end routing verified separately.

Sanity → Mixpanel · free audit

What we check in the free audit

  • Count conversions carrying the distinct_id
  • Follow one real conversion end to end
  • Identify the front-end framework, not the CMS
  • List every event name in the project and look for near-duplicates
  • Read the match rate, not the success message

Checked against

Your commerce, CRM or billing system — Sanity has no orders and no customers.

Get my free conversion tracking audit

Free30 minutesNo obligation

Sanity → Mixpanel · when not to buy

When you don't need this — Sanity → Mixpanel

  • Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the distinct_id.
  • There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
  • If you already have the same events in a warehouse and nobody is running product analysis on them, adding Mixpanel adds a second source of truth rather than an answer.

Sanity → Mixpanel · what we deliver

What gets built — Sanity → Mixpanel

  • Identifier capture into Sanity

    Capture and persist the identifier server-side in the front-end application, then carry it into the system that records the sale.

  • Event source: your commerce or CRM system

    Send from wherever the money is recorded, not from the content layer.

  • Dispatch to Mixpanel

    The Mixpanel ingestion API, posted server-side from your backend with the distinct_id and event properties.

  • Reversals where they exist

    Handled by the commerce system.

Written guarantee

95%+ tracking accuracy

Measured against Your commerce, CRM or billing system — Sanity has no orders and no customers.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Sanity → Mixpanel questions, answered

Fire a page view on each client-side route change, either through the Mixpanel SDK's page view option or your router's navigation events, not both. Check in the live view that each navigation sends exactly one.

Free · 30 min

Get Sanity and Mixpanel joined properly

Free30 minutesNo obligation