Skip to main content
Craft → MixpanelIntegration guide

Connecting Craft CMS to Mixpanel

Craft is a developer-oriented CMS, usually built bespoke by an agency, which means the implementation is whatever that agency decided and nothing is standard. 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 Craft Commerce order 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

Craft Commerce orders in Mixpanel on the right distinct_id

Save the Mixpanel distinct_id to a custom field on the Craft Commerce cart, so the order-complete listener's server event joins the browsing. Call identify with the Craft user ID at login for account stores. Set $insert_id from the order reference, send refunds as their own event, and agree one purchase event name.

Mixpanel needs the purchase on the same distinct_id the browser used, and Craft gives you no default place to keep it. Read the ID from the Mixpanel JavaScript library when the cart is created and save it to a custom field on the cart. Since a Commerce cart is the same Order element that later completes, the server-side event fired from the order-complete listener can use it, and the purchase joins the browsing that led to it.

Decide what identifies a customer before launch. If the store has accounts, call identify with the Craft user ID at login and registration. If most orders are guest checkouts, the order email is the only stable key, and using it as an identity raises its own privacy questions to settle first. Set $insert_id from the order reference so a retried request or a re-saved order doesn't create a second purchase, and send refunds from Commerce transactions as their own event.

The common break is a purchase event fired from a cached Twig confirmation block, which sends nothing or the wrong order. If the product team already tracks Commerce events through another plugin, agree on one purchase event name before adding a server event beside it, or Mixpanel will treat the two as unrelated.

Craft → Mixpanel · what breaks

Why this join usually fails — Craft → Mixpanel

  1. 01

    The distinct_id never reaches Craft

    Craft's template caching and static caching plugins both serve stored output, and because every build is custom, where the capture code lives differs per site. There is no standard place to look.

  2. 02

    Every install is bespoke

    There is no standard Craft setup, so an approach that worked on another Craft site may have nothing to attach to on this one. Read the build before quoting.

  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.

Craft → Mixpanel · the fix

What working looks like — Craft → Mixpanel

  • The distinct_id on every order

  • Conversions arriving in Mixpanel

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

  • Reconciled against the source

    Craft CMS's own records are the reference, not either dashboard.

Craft → Mixpanel · architecture

How Craft and Mixpanel actually connect

  1. 1

    Craft CMS holds the truth

    Craft installs are bespoke by nature. Establish how this particular build models a completed order before assuming anything transfers from another Craft site.

  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 Craft Commerce order.

  4. 4

    The event source decides reliability

    Fire from the event listener in PHP rather than a Twig template, which may be cached.

  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.

Craft → Mixpanel · normal or broken

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

Normal, not a fault

  • The distinct_id present on the order

    Visible on the record itself in Craft CMS, not merely captured somewhere on the site.

  • Sent from the Craft Commerce order-complete event

  • 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

    Mixpanel's count and Craft CMS's records agree within a few percent over a closed window.

Actually broken

  • The distinct_id missing on most records

    Craft's template caching and static caching plugins both serve stored output, and because every build is custom, where the capture code lives differs per site. There is no standard place to look.

  • Sent from the browser

    There is no standard Craft setup, so an approach that worked on another Craft site may have nothing to attach to on this one. Read the build before quoting.

  • 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

    The dashboard shows a number and no one has compared it to Craft CMS.

Craft → Mixpanel · diagnose

Diagnostic order — Craft → Mixpanel

  1. 01

    Count orders carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Read how this specific build handles order completion

    Assumptions carried from another Craft project are the main source of wasted time here.

  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.

Craft → Mixpanel · prove

How it gets proven — Craft → Mixpanel

Against Craft CMS's own records, not against either platform's dashboard.

Source of truth

Craft Commerce's order records in your own database, filtered to completed.

  • The distinct_id confirmed present on a live order.
  • Purchase events reconciled per transaction against your billing system, with identity aliasing verified across the signup boundary.
  • Order custom field confirmed populated on an order placed as an anonymous visitor through cache.

Craft → Mixpanel · free audit

What we check in the free audit

  • Count orders carrying the distinct_id
  • Follow one real conversion end to end
  • Read how this specific build handles order completion
  • List every event name in the project and look for near-duplicates
  • Read the match rate, not the success message

Checked against

Craft Commerce's order records in your own database, filtered to completed.

Get my free conversion tracking audit

Free30 minutesNo obligation

Craft → Mixpanel · when not to buy

When you don't need this — Craft → Mixpanel

  • If Mixpanel already reports conversions that reconcile against Craft CMS's records within a few percent, this join is working and there is nothing to buy.
  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the distinct_id.
  • If the original agency is still engaged, the fastest path is usually specifying the field and having them add the hook.
  • 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.

Craft → Mixpanel · what we deliver

What gets built — Craft → Mixpanel

  • Identifier capture into Craft

    Capture the identifier and store it as a custom field on the order through a Craft event listener, server-side.

  • Event source: the Craft Commerce order-complete event

    Fire from the event listener in PHP rather than a Twig template, which may be cached.

  • Dispatch to Mixpanel

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

  • Reversals where they exist

    Refunds and cancelled orders are recorded against the order.

Written guarantee

95%+ tracking accuracy

Measured against Craft Commerce's order records in your own database, filtered to completed.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Craft → Mixpanel questions, answered

Listen for order completion in a Craft module, read the distinct_id you saved on the cart, and post the event to Mixpanel's ingestion API with the order reference as $insert_id.

Free · 30 min

Get Craft and Mixpanel joined properly

Free30 minutesNo obligation