Skip to main content
Drupal Commerce → PostHogIntegration guide

Connecting Drupal Commerce to PostHog

Drupal Commerce is self-hosted commerce inside a CMS built for complex content, which means the store is one part of a much larger site you fully control. 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 Drupal Commerce 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

Drupal Commerce to PostHog: order UUID as the event UUID

Send the placed Drupal Commerce order to PostHog server-side from the order placement hook, not the complete page. Store the PostHog distinct_id on the order during checkout and use the order's Drupal UUID as the event UUID, so PostHog dedupes retried hooks and late gateway notifications. Identify registered customers by Drupal user ID; leave guest checkouts anonymous.

PostHog's appeal for a Drupal Commerce store is usually the same as Drupal's: you run it, you keep the data. Self-hosted next to the site, its capture endpoint is first-party and survives blockers that kill third-party tags, which makes checkout funnels more complete than a hosted tool shows. Map the funnel to your Drupal checkout flow's own steps, since those are configurable per site and the step names are what your team will recognize.

Send the placed order server-side from the order placement hook, not from the complete page. Store the PostHog distinct_id on the order during checkout so the server event lands on the right person, and use the order's UUID, which every Drupal entity has, as the event UUID. PostHog dedupes on it, so a retried hook or an offsite gateway notification placing the order late does not create a second purchase.

Identify registered customers with their Drupal user ID on login, so the anonymous browsing before login merges with their account. Guest checkouts stay anonymous, which is correct; do not identify them by email just to make funnels look complete unless your privacy policy says you do. Refunds are worth a separate event, so revenue insights can subtract them.

Drupal Commerce → PostHog · what breaks

Why this join usually fails — Drupal Commerce → PostHog

  1. 01

    The distinct_id never reaches Drupal Commerce

    Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.

  2. 02

    Configurable workflow states nobody agreed on

    Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.

  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.

Drupal Commerce → PostHog · the fix

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

Drupal Commerce → PostHog · architecture

How Drupal Commerce and PostHog actually connect

  1. 1

    Drupal Commerce holds the truth

    You own the database, so the truth is exactly as good as the query. Pin down which order states count as revenue before comparing anything — Drupal's workflow states are configurable per install, so no two sites agree by default.

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

  4. 4

    The event source decides reliability

    Fire server-side from the hook rather than the checkout completion template, which is cacheable 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.

Drupal Commerce → PostHog · normal or broken

Working vs. broken, side by side — Drupal Commerce → PostHog

Normal, not a fault

  • The distinct_id present on the order

  • Sent from the Drupal Commerce order placement hook

  • 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

    Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.

  • Sent from the browser

    Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.

  • 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

Drupal Commerce → PostHog · diagnose

Diagnostic order — Drupal Commerce → PostHog

  1. 01

    Count orders carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    List the order states in use and agree which count as revenue

    Do this before any technical work — it resolves more Drupal Commerce disputes than any code change.

  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.

Drupal Commerce → PostHog · prove

How it gets proven — Drupal Commerce → PostHog

Source of truth

Drupal's commerce_order records in your own database, filtered to completed states.

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

Drupal Commerce → PostHog · free audit

What we check in the free audit

  • Count orders carrying the distinct_id
  • Follow one real conversion end to end
  • List the order states in use and agree which count as revenue
  • Check ingestion health and disk before debugging any missing event
  • Read the match rate, not the success message

Checked against

Drupal's commerce_order records in your own database, filtered to completed states.

Get my free conversion tracking audit

Free30 minutesNo obligation

Drupal Commerce → PostHog · when not to buy

When you don't need this — Drupal Commerce → PostHog

  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the distinct_id.
  • If your Drupal site is content-only with commerce elsewhere, work at the commerce system instead — this is the wrong layer.
  • 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.

Drupal Commerce → PostHog · what we deliver

What gets built — Drupal Commerce → PostHog

  • Identifier capture into Drupal Commerce

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

  • Event source: the Drupal Commerce order placement hook

    Fire server-side from the hook rather than the checkout completion template, which is cacheable 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

    Order state transitions to refunded or cancelled are recorded and can drive reversals.

Written guarantee

95%+ tracking accuracy

Measured against Drupal's commerce_order records in your own database, filtered to completed states.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Drupal Commerce → PostHog questions, answered

From the order placement hook through PostHog's capture API, with the distinct_id stored on the order and the order UUID as the event UUID.

Free · 30 min

Get Drupal Commerce and PostHog joined properly

Free30 minutesNo obligation