Skip to main content
Medusa → PostHogIntegration guide

Connecting Medusa to PostHog

Medusa is a Node commerce engine you extend in your own codebase, which makes the conversion event a piece of application code — and therefore something that can be tested rather than hoped for. PostHog can be self-hosted, which changes the calculus entirely: the data stays on infrastructure you control, and so does the responsibility for everything that goes wrong with it. The join between them succeeds or fails on one thing: whether the distinct_id reaches the Medusa order before the conversion happens, because PostHog can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Medusa to PostHog: one person from storefront to paid order

Identify signed-in shoppers with the Medusa customer ID, and write guests' anonymous distinct_id into cart metadata so the payment-capture subscriber sends the purchase to the same person. Check for v2's PostHog analytics provider, set the event UUID from the order ID, keep currencies consistent, and build a funnel ending on captured payment.

PostHog's distinct_id has to be the same on the storefront and on the server event, and with Medusa's split storefront and backend that does not happen by default. For signed-in shoppers, call identify on the storefront with the Medusa customer ID and use that same ID as the distinct_id on the server event. For guests, write posthog-js's anonymous distinct_id into cart metadata so the payment-capture subscriber can send the purchase against the person who actually browsed.

Check whether your Medusa version includes the Analytics Module with a PostHog provider; recent v2 releases added one, and it saves writing the HTTP calls yourself, though you still decide which workflow step tracks what. Whichever route, set the event UUID from the order ID so a retried subscriber does not create a second purchase. Send total and currency as properties and keep the currency consistent across Medusa regions, or revenue insights will add dollars to euros.

The analytics worth building with this pair is a checkout funnel that ends on captured payment rather than the confirmation page: storefront steps from posthog-js, final step from the server. That gap shows how many orders are placed but never paid, which is exactly what Medusa can tell you and a browser-only funnel cannot.

Medusa → PostHog · what breaks

Why this join usually fails — Medusa → PostHog

  1. 01

    The distinct_id never reaches Medusa

    The storefront is separate from the backend, and the identifier must be attached to the cart before the order is created.

  2. 02

    Firing on order placed rather than payment captured

    They are different events and the gap between them contains every failed and pending payment. Order-placed is the easier hook and the wrong one.

  3. 03

    Self-hosting the analytics and the outage together

    The advantage of owning the pipeline is that nothing blocks it. The cost is that when the ingestion instance fills its disk on a Saturday, the events are gone and nobody is paged. Hosted tools fail differently and more visibly.

  4. 04

    Nothing reconciles afterwards

    PostHog shows events in the activity view within moments. On a self-hosted instance, check the ingestion lag as well — events that are queued are not events that are lost, and the two need different responses.

Medusa → PostHog · the fix

What working looks like — Medusa → PostHog

  • The distinct_id on every order

  • Conversions arriving in PostHog

    The event lands on the person profile and becomes available in insights, funnels and session replay.

  • Reconciled against the source

Medusa → PostHog · architecture

How Medusa and PostHog actually connect

  1. 1

    Medusa holds the truth

    Because you own the event handlers, the conversion can fire from the payment-captured event specifically rather than from whatever the frontend happened to render.

  2. 2

    PostHog needs a click to match

    PostHog needs a distinct_id, an event name and its properties. Self-hosted instances additionally need the ingestion endpoint reachable and the project API key correct, which is a class of failure hosted tools do not have.

  3. 3

    The identifier is the bridge

    The distinct_id, captured at the visit and carried into the Medusa order.

  4. 4

    The event source decides reliability

    Send orders at payment capture, at the paid total.

  5. 5

    Deduplication at the destination

    PostHog deduplicates on the event UUID where supplied. Without one, a retried batch duplicates, and on a self-hosted instance there is no vendor support desk to notice it for you.

Medusa → PostHog · normal or broken

Working vs. broken, side by side — Medusa → PostHog

Normal, not a fault

  • The distinct_id present on the order

  • Sent from a Medusa subscriber on order payment capture

  • Deduplicated correctly

    PostHog deduplicates on the event UUID where supplied. Without one, a retried batch duplicates, and on a self-hosted instance there is no vendor support desk to notice it for you.

  • Reconciles with the source

Actually broken

  • The distinct_id missing on most records

    The storefront is separate from the backend, and the identifier must be attached to the cart before the order is created.

  • Sent from the browser

    They are different events and the gap between them contains every failed and pending payment. Order-placed is the easier hook and the wrong one.

  • Counted twice, or not at all

    The advantage of owning the pipeline is that nothing blocks it. The cost is that when the ingestion instance fills its disk on a Saturday, the events are gone and nobody is paged. Hosted tools fail differently and more visibly.

  • Nobody has reconciled it

Medusa → PostHog · diagnose

Diagnostic order — Medusa → PostHog

  1. 01

    Count orders carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Check which event your subscriber listens to

    One line of code, and it decides whether you are counting orders or counting money.

  4. 04

    Check ingestion health and disk before debugging any missing event

    On self-hosted instances the answer is infrastructure far more often than it is instrumentation.

  5. 05

    Read the match rate, not the success message

    PostHog shows events in the activity view within moments. On a self-hosted instance, check the ingestion lag as well — events that are queued are not events that are lost, and the two need different responses.

Medusa → PostHog · prove

How it gets proven — Medusa → PostHog

Source of truth

Medusa orders by payment status, emitted from your own subscriber code.

  • The distinct_id confirmed present on a live order.
  • Purchase events reconciled per transaction against your billing system, with ingestion lag checked over the same window.
  • Payment-captured orders reconciled against imported conversions.

Medusa → PostHog · free audit

What we check in the free audit

  • Count orders carrying the distinct_id
  • Follow one real conversion end to end
  • Check which event your subscriber listens to
  • Check ingestion health and disk before debugging any missing event
  • Read the match rate, not the success message

Checked against

Medusa orders by payment status, emitted from your own subscriber code.

Get my free conversion tracking audit

Free30 minutesNo obligation

Medusa → PostHog · when not to buy

When you don't need this — Medusa → PostHog

  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the distinct_id.
  • If every payment method you accept is instant, the two events nearly coincide and the distinction costs more than it returns.
  • If you have no reason to keep the data on your own infrastructure and no team to run it, the hosted product removes the only real downside of this one.

Medusa → PostHog · what we deliver

What gets built — Medusa → PostHog

  • Identifier capture into Medusa

    Write the identifier into cart metadata at first touch so it is carried onto the order automatically at completion.

  • Event source: a Medusa subscriber on order payment capture

    Send orders at payment capture, at the paid total.

  • Dispatch to PostHog

    The PostHog capture API, posted server-side from your backend to your own instance or to PostHog Cloud.

  • Reversals where they exist

    Refunds emit their own event and should reverse.

Written guarantee

95%+ tracking accuracy

Measured against Medusa orders by payment status, emitted from your own subscriber code.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Medusa → PostHog questions, answered

Recent Medusa v2 releases include an Analytics Module with a PostHog provider; check your version's docs. Older setups call PostHog's capture API from a subscriber.

Free · 30 min

Get Medusa and PostHog joined properly

Free30 minutesNo obligation