Skip to main content
Drupal Commerce → SegmentIntegration guide

Connecting Drupal Commerce to Segment

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. Segment is a customer data platform rather than an ad network, so sending to it is not about matching a conversion — it is about putting one clean event where every other destination can read it. The join between them succeeds or fails on one thing: whether the userId and anonymousId reaches the Drupal Commerce order before the conversion happens, because Segment can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Drupal Commerce to Segment: uid, anonymousId and the cached page

Send Order Completed to Segment from an event subscriber on the Drupal Commerce place transition using Segment's PHP library, with order_id, revenue, currency and a products array. Store the analytics.js anonymousId on the order via a checkout script, use the Drupal uid as userId only when one exists, build messageId from order ID and transition, and include stored consent state.

Segment's identity model maps onto Drupal neatly, with the Drupal uid as userId and the analytics.js anonymousId before login, except for two Drupal habits. Guest checkout leaves orders with no uid, and cached pages mean the server cannot read the anonymousId from rendered output. Write the anonymousId into checkout with a script, store it on the order, and send the server-side Order Completed with it. Use the uid as userId only when one exists, and put the order email in traits rather than using it as the userId.

Send the track call from an event subscriber on the place transition using Segment's PHP library, with order_id, revenue and currency from the order's price field, and a products array built from order items using the same SKU your feeds use. Transitions to canceled or refunded become Order Cancelled or Order Refunded. Build messageId from the order ID and the transition, so a re-run queue item is dropped.

Consent belongs in the payload. Drupal sites often run a consent module whose state lives in a cookie; read it at checkout, store it with the order, and send it as a property so Segment can filter which destinations receive the event. Without that, a server-side event bypasses the banner the browser tags respected. If Segment would feed only one ad platform from this store, a direct integration is simpler.

Drupal Commerce → Segment · what breaks

Why this join usually fails — Drupal Commerce → Segment

  1. 01

    The userId and anonymousId 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

    One bad event multiplied across every destination

    Segment's value is fan-out, which is also its risk. An inconsistent identity or a duplicated event does not break one report — it breaks every connected tool simultaneously, and tracing it back is harder than debugging a direct integration.

  4. 04

    Nothing reconciles afterwards

    Segment's debugger shows events arriving and which destinations accepted them. Arriving is not the test — check a destination you care about and confirm the event landed there with the identity intact, then reconcile against your own records.

Drupal Commerce → Segment · the fix

What working looks like — Drupal Commerce → Segment

  • The userId and anonymousId on every order

  • Conversions arriving in Segment

    Events land in Segment and forward to every connected destination, warehouse included, on one shared definition.

  • Reconciled against the source

Drupal Commerce → Segment · architecture

How Drupal Commerce and Segment 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

    Segment needs a click to match

    Segment needs a consistent identity model — the same userId everywhere, an alias when an anonymous visitor becomes known, and event names that follow one spec. Feeding it inconsistent identities pushes the mess to every connected destination at once.

  3. 3

    The identifier is the bridge

    The userId and anonymousId, 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

    Segment deduplicates on messageId within a window. Because it fans out to many destinations, a duplicate here becomes a duplicate everywhere, which makes idempotent messageIds more important than in any single-destination integration.

Drupal Commerce → Segment · normal or broken

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

Normal, not a fault

  • The userId and anonymousId present on the order

  • Sent from the Drupal Commerce order placement hook

  • Deduplicated correctly

    Segment deduplicates on messageId within a window. Because it fans out to many destinations, a duplicate here becomes a duplicate everywhere, which makes idempotent messageIds more important than in any single-destination integration.

  • Reconciles with the source

Actually broken

  • The userId and anonymousId 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

    Segment's value is fan-out, which is also its risk. An inconsistent identity or a duplicated event does not break one report — it breaks every connected tool simultaneously, and tracing it back is harder than debugging a direct integration.

  • Nobody has reconciled it

Drupal Commerce → Segment · diagnose

Diagnostic order — Drupal Commerce → Segment

  1. 01

    Count orders carrying the userId and anonymousId

  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 identity resolution before checking anything downstream

    If anonymousId is never aliased to userId, every destination sees two people where there is one, and no downstream fix helps.

  5. 05

    Read the match rate, not the success message

    Segment's debugger shows events arriving and which destinations accepted them. Arriving is not the test — check a destination you care about and confirm the event landed there with the identity intact, then reconcile against your own records.

Drupal Commerce → Segment · prove

How it gets proven — Drupal Commerce → Segment

Source of truth

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

  • The userId and anonymousId confirmed present on a live order.
  • An anonymous session confirmed aliased to a known user, with the event visible in at least one downstream destination.
  • Order field data confirmed populated on an order placed through a fully warmed cache as an anonymous visitor.

Drupal Commerce → Segment · free audit

What we check in the free audit

  • Count orders carrying the userId and anonymousId
  • Follow one real conversion end to end
  • List the order states in use and agree which count as revenue
  • Check identity resolution before checking anything downstream
  • 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 → Segment · when not to buy

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

  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the userId and anonymousId.
  • If your Drupal site is content-only with commerce elsewhere, work at the commerce system instead — this is the wrong layer.
  • If you send to one or two destinations, Segment is infrastructure you do not need — direct integrations are simpler and cheaper. It earns its place at genuine fan-out.

Drupal Commerce → Segment · what we deliver

What gets built — Drupal Commerce → Segment

  • 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 Segment

    Server-side track and identify calls with a stable messageId, consistent userId, and the click identifier carried as a trait or property.

  • 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 → Segment questions, answered

Leave it empty, send the anonymousId captured at checkout, and put the email in traits. Using email as userId creates identities you cannot merge cleanly later.

Free · 30 min

Get Drupal Commerce and Segment joined properly

Free30 minutesNo obligation