Skip to main content
Magento → PostHogIntegration guide

Connecting Magento to PostHog

Magento is self-hosted and endlessly customisable, which means every installation is different and full-page caching is always in the way. 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 Magento 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

Magento checkout funnels in PostHog with one distinct_id per buyer

Join Magento's checkout funnel in PostHog by reading posthog-js's distinct_id in the order placement observer, storing it on the order and sending the order via the capture API with increment_id as a property. Identify logged-in customers by customer_id, keep guests anonymous, send a separate refund event for credit memos, and whitelist a PostHog subdomain in csp_whitelist.xml.

PostHog is most useful on Magento for the checkout funnel: cart, shipping step, payment step, order. The browser events come from posthog-js, which runs after the cached page loads and so is not affected by the full-page cache. The order itself should come from the server, because the success page misses buyers who pay off-site and never return. The two halves form one funnel only if they share a distinct_id.

posthog-js keeps the anonymous distinct_id in its own cookie. Read it in the order placement observer from the place-order request, store it on the order, and send the order event through the capture API with that distinct_id and the increment_id as a property. For logged-in customers, call identify with the Magento customer_id so orders from different devices merge. For guests, keep the anonymous ID rather than identifying on email, or a shared household address merges several people into one.

Send money as properties: base_grand_total, order currency, item count, coupon code and shipping method. PostHog will not change a past event when a credit memo is issued, so send a separate refund event with the same increment_id and subtract in insights. If you serve PostHog from a subdomain, add that host to Magento's csp_whitelist.xml, since the Content Security Policy module can block posthog-js on checkout pages.

Magento → PostHog · what breaks

Why this join usually fails — Magento → PostHog

  1. 01

    The distinct_id never reaches Magento

    Magento's full-page cache serves a stored render to the visitor, which means anything relying on dynamically rendered values can silently fail — and in Magento this has historically included serving one customer's cached block to another, which is a data problem as well as a tracking one.

  2. 02

    Full-page cache between the visitor and your code

    The page the customer saw is not the page your code assumed. This is the defining Magento tracking failure and it produces intermittent, hard-to-reproduce loss.

  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.

Magento → PostHog · the fix

What working looks like — Magento → 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

Magento → PostHog · architecture

How Magento and PostHog actually connect

  1. 1

    Magento holds the truth

    You own the database, so the truth is as good as the query. Pin down which order statuses count as revenue — processing, complete, or both — because that choice moves the number substantially.

  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 Magento order.

  4. 4

    The event source decides reliability

    Fire server-side from the observer rather than from the success page template, which is cached and may not execute anything.

  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.

Magento → PostHog · normal or broken

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

Normal, not a fault

  • The distinct_id present on the order

  • Sent from the Magento order placement observer

  • 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

    Magento's full-page cache serves a stored render to the visitor, which means anything relying on dynamically rendered values can silently fail — and in Magento this has historically included serving one customer's cached block to another, which is a data problem as well as a tracking one.

  • Sent from the browser

    The page the customer saw is not the page your code assumed. This is the defining Magento tracking failure and it produces intermittent, hard-to-reproduce loss.

  • 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

Magento → PostHog · diagnose

Diagnostic order — Magento → PostHog

  1. 01

    Count orders carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Place a test order as an anonymous visitor through cache

    Not as an admin, which bypasses it. If the order data is missing on the cached path, caching is your cause.

  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.

Magento → PostHog · prove

How it gets proven — Magento → PostHog

Source of truth

Magento's sales order records in your own database, for the same window and order status set.

  • 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.
  • Order data confirmed populated on an order placed through a fully warmed cache.

Magento → PostHog · free audit

What we check in the free audit

  • Count orders carrying the distinct_id
  • Follow one real conversion end to end
  • Place a test order as an anonymous visitor through cache
  • Check ingestion health and disk before debugging any missing event
  • Read the match rate, not the success message

Checked against

Magento's sales order records in your own database, for the same window and order status set.

Get my free conversion tracking audit

Free30 minutesNo obligation

Magento → PostHog · when not to buy

When you don't need this — Magento → PostHog

  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the distinct_id.
  • If your Magento build has heavy customisation by another team, scope their availability first — the build is usually blocked there.
  • 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.

Magento → PostHog · what we deliver

What gets built — Magento → PostHog

  • Identifier capture into Magento

    Capture the identifier and persist it as order data through an observer on order placement, server-side, so it never depends on what the cache served.

  • Event source: the Magento order placement observer

    Fire server-side from the observer rather than from the success page template, which is cached and may not execute anything.

  • 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

    Credit memos are recorded against the original order and should reduce the reported figure.

Written guarantee

95%+ tracking accuracy

Measured against Magento's sales order records in your own database, for the same window and order status set.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Magento → PostHog questions, answered

Load posthog-js for browser events and send the order from the order placement observer through the capture API, using the distinct_id read from the PostHog cookie on the place-order request.

Free · 30 min

Get Magento and PostHog joined properly

Free30 minutesNo obligation