Skip to main content
Sanity → SegmentIntegration guide

Connecting Sanity to Segment

Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. 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 front-end conversion, not a Sanity record 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

Segment on a Sanity front end: page calls named by content type

Segment runs in the Sanity front end: call page on every client-side route change after the document loads, with category set to _type, name to the document title and _id as a property. Carry landing click IDs as properties and identify traits, send conversions server-side from commerce or CRM with the same userId, and filter ad destinations by consent.

Segment sits in the front-end application on a Sanity site, so the integration is about what the front end sends. Use Sanity's document type and title in the page call. Segment's page method accepts a category and a name, and setting category to the _type and name to the document title gives every downstream tool the same page grouping without each one parsing URLs.

Single-page routing is the usual break. Call page once on every client-side route change, after the new document has loaded, or the properties describe the previous page. Add the _id as a property so the warehouse can join to a Sanity export. Carry click IDs from the landing URL as properties on the first page call and as traits on identify, so they reach destinations with the rest of the visitor's data.

Conversions come from your commerce or CRM backend as server-side track calls with the same userId, or the browser's anonymousId if the visitor wasn't identified yet. Pass consent state through and filter ad destinations on it, because Segment forwards page calls everywhere by default. Content page views are useful in the warehouse and in analytics; most ad destinations don't need every article view.

Sanity → Segment · what breaks

Why this join usually fails — Sanity → Segment

  1. 01

    The userId and anonymousId never reaches Sanity

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  2. 02

    A headless stack diagnosed at the wrong layer

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  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.

Sanity → Segment · the fix

What working looks like — Sanity → Segment

  • The userId and anonymousId on every conversion

  • Conversions arriving in Segment

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

  • Reconciled against the source

Sanity → Segment · architecture

How Sanity and Segment actually connect

  1. 1

    Sanity holds the truth

    Sanity's real-time content APIs make it excellent at what it does and irrelevant to conversion measurement. Establishing that early saves the client money.

  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 front-end conversion, not a Sanity record.

  4. 4

    The event source decides reliability

    Send from wherever the money is recorded, not from the content layer.

  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.

Sanity → Segment · normal or broken

Working vs. broken, side by side — Sanity → Segment

Normal, not a fault

  • The userId and anonymousId present on the conversion

  • Sent from your commerce or CRM system

  • 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

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  • Sent from the browser

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  • 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

Sanity → Segment · diagnose

Diagnostic order — Sanity → Segment

  1. 01

    Count conversions carrying the userId and anonymousId

  2. 02

    Follow one real conversion end to end

  3. 03

    Identify the front-end framework, not the CMS

    The routing behaviour that breaks tracking belongs to Next.js, Nuxt or whatever renders the site.

  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.

Sanity → Segment · prove

How it gets proven — Sanity → Segment

Source of truth

Your commerce, CRM or billing system — Sanity has no orders and no customers.

  • The userId and anonymousId confirmed present on a live conversion.
  • An anonymous session confirmed aliased to a known user, with the event visible in at least one downstream destination.
  • The conversion confirmed sourced from the commerce system, with front-end routing verified separately.

Sanity → Segment · free audit

What we check in the free audit

  • Count conversions carrying the userId and anonymousId
  • Follow one real conversion end to end
  • Identify the front-end framework, not the CMS
  • Check identity resolution before checking anything downstream
  • Read the match rate, not the success message

Checked against

Your commerce, CRM or billing system — Sanity has no orders and no customers.

Get my free conversion tracking audit

Free30 minutesNo obligation

Sanity → Segment · when not to buy

When you don't need this — Sanity → Segment

  • Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the userId and anonymousId.
  • There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
  • 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.

Sanity → Segment · what we deliver

What gets built — Sanity → Segment

  • Identifier capture into Sanity

    Capture and persist the identifier server-side in the front-end application, then carry it into the system that records the sale.

  • Event source: your commerce or CRM system

    Send from wherever the money is recorded, not from the content layer.

  • 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

    Handled by the commerce system.

Written guarantee

95%+ tracking accuracy

Measured against Your commerce, CRM or billing system — Sanity has no orders and no customers.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Sanity → Segment questions, answered

Call analytics.page on each client-side route change after the new content loads, with the Sanity document type as category and the title as name. Check in the Segment debugger that each navigation sends exactly one call.

Free · 30 min

Get Sanity and Segment joined properly

Free30 minutesNo obligation