Connecting Craft CMS to Segment
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. 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 Craft 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
Craft Commerce into Segment: one anonymousId from cart to order
Save the analytics.js anonymousId to a custom field on the Craft Commerce cart, then send Order Completed from the PHP listener with it and any userId, following Segment's ecommerce spec. Carry click IDs and consent as properties, derive messageId from the order reference, and remove any template Order Completed call.
Segment only helps a Craft store if the server-side Order Completed and the browser's page and product events share an identity, and Craft won't arrange that for you. Save the analytics.js anonymousId to a custom field on the cart when it's created. The cart is the same Commerce Order element that completes, so the PHP listener can send Order Completed with that anonymousId, plus a userId when the customer is logged in. Segment's PHP library from a Craft module is the usual route; check the Plugin Store before assuming a maintained Segment plugin exists for your Craft version.
Follow Segment's ecommerce spec: order_id as the Commerce order reference, products from line items with SKU, price and quantity, currency from the order. Carry stored click IDs and the visitor's consent state as properties, so ad destinations downstream can use them and suppress sends where consent wasn't given. Derive messageId from the order reference so a retried listener or a re-saved order doesn't fan out twice.
The common break is the agency's existing analytics.js setup also sending Order Completed from the confirmation template. Two sources with different messageIds produce two orders in every connected tool, so pick the server event and remove the template call. A Craft store feeding a single ad platform is better served by a direct integration.
Craft → Segment · what breaks
Why this join usually fails — Craft → Segment
- 01
The userId and anonymousId 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.
- 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.
- 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.
- 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.
Craft → Segment · the fix
What working looks like — Craft → 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
Craft CMS's own records are the reference, not either dashboard.
Craft → Segment · architecture
How Craft and Segment actually connect
- 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
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
The identifier is the bridge
The userId and anonymousId, captured at the visit and carried into the Craft Commerce order.
- 4
The event source decides reliability
Fire from the event listener in PHP rather than a Twig template, which may be cached.
- 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.
Craft → Segment · normal or broken
Working vs. broken, side by side — Craft → Segment
Normal, not a fault
The userId and anonymousId 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
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
Segment's count and Craft CMS's records agree within a few percent over a closed window.
Actually broken
The userId and anonymousId 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
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
The dashboard shows a number and no one has compared it to Craft CMS.
Craft → Segment · diagnose
Diagnostic order — Craft → Segment
- 01
Count orders carrying the userId and anonymousId
- 02
Follow one real conversion end to end
- 03
Read how this specific build handles order completion
Assumptions carried from another Craft project are the main source of wasted time here.
- 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.
- 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.
Craft → Segment · prove
How it gets proven — Craft → Segment
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 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 custom field confirmed populated on an order placed as an anonymous visitor through cache.
Craft → Segment · free audit
What we check in the free audit
- Count orders carrying the userId and anonymousId
- Follow one real conversion end to end
- Read how this specific build handles order completion
- Check identity resolution before checking anything downstream
- Read the match rate, not the success message
Checked against
Craft Commerce's order records in your own database, filtered to completed.
Free30 minutesNo obligation
Craft → Segment · when not to buy
When you don't need this — Craft → Segment
- If Segment 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 userId and anonymousId.
- If the original agency is still engaged, the fastest path is usually specifying the field and having them add the hook.
- 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.
Craft → Segment · what we deliver
What gets built — Craft → Segment
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 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
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.
From $400 · See packages
FAQ
Craft → Segment questions, answered
Check the Craft Plugin Store for one maintained for your version. Many builds use Segment's PHP library from a small module listening for order completion instead.
Send it from one place only, ideally the server listener, and set messageId deterministically from the order reference so retries are dropped.
Almost always because the userId and anonymousId never reached the Craft Commerce order. 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. Measure coverage before debugging the dispatch.
Segment identifies people by anonymousId before they are known and userId afterwards, and the alias between them is what stitches a session to a customer. Click identifiers travel as event properties or traits rather than as a matching key — Segment does not match anything itself, it forwards. That distinction changes the whole design: get the identity resolution right and every downstream destination inherits it.
The Craft Commerce order-complete event. Fire from the event listener in PHP rather than a Twig template, which may be cached.
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.
More on Craft → Segment
- Craft → Google AdsConnecting Craft CMS to Google Ads
- Craft → MetaConnecting Craft CMS to Meta Conversions API
- Craft → GA4Connecting Craft CMS to GA4
RELATED GUIDES
Where Craft → Segment fits in the rest of your tracking
- Drupal Commerce → SegmentConnecting Drupal Commerce to Segment
- Sitecore → SegmentConnecting Sitecore to Segment
- Duda → SegmentConnecting Duda to Segment
- Craft → BigQueryConnecting Craft CMS to BigQuery
- B2BConversion tracking for B2B, from first touch to closed-won
- Webflow → SegmentConnecting Webflow to Segment
- Concrete CMS → SegmentConnecting Concrete CMS to Segment
- Ghost → SegmentConnecting Ghost memberships to Segment
Free · 30 min
Get Craft and Segment joined properly
Free30 minutesNo obligation
