Skip to main content
Sanity → X AdsIntegration guide

Connecting Sanity to X Ads

Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. X is a conversation platform where a large share of engagement is discussion rather than intent, which makes the gap between engagement metrics and conversions unusually wide. The join between them succeeds or fails on one thing: whether the twclid click identifier reaches the front-end conversion, not a Sanity record before the conversion happens, because X Ads can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

X Ads on a headless Sanity store: carry twclid to checkout

On a headless Sanity storefront, persist twclid in a first-party cookie on landing and pass it into the cart as an attribute or metadata so it lands on the order. Send the purchase to the X Conversions API from the order webhook with twclid, hashed email and the order ID as conversion ID, and test inside X's in-app browser.

A common Sanity setup is a headless storefront: Sanity for content, a commerce engine for products and checkout, often on a different domain. X ad traffic lands on the front end, usually inside X's in-app browser, carrying twclid. The purchase happens on the checkout domain, where neither your first-party cookie nor the X pixel cookie from the landing page exists.

Persist twclid in a first-party cookie on landing, then pass it into the cart when it's created, as a cart attribute, note or metadata field, whatever your commerce engine supports, so it ends up on the order. Send the purchase to the X Conversions API from the order webhook with twclid, the hashed email and the order ID as the conversion ID. If the X pixel also fires on the checkout's thank-you page, it needs the same order ID.

Test the whole path inside X's in-app browser specifically, from ad click through checkout, because storage there is short-lived and some visitors switch to their main browser midway. If pages are statically generated, make sure twclid capture runs in the browser or at the edge, never at build time. Sanity plays no part in any of this beyond the pages X traffic lands on.

Sanity → X Ads · what breaks

Why this join usually fails — Sanity → X Ads

  1. 01

    The twclid click identifier 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

    Engagement mistaken for intent

    A post can be quoted, argued with and shared widely by people with no interest in buying anything. Optimising toward engagement on this platform reliably finds an audience that will never convert, and the engagement numbers look excellent throughout.

  4. 04

    Nothing reconciles afterwards

    Read the delivered and matched counts in X's reporting rather than assuming a 200 response means the event was usable.

Sanity → X Ads · the fix

What working looks like — Sanity → X Ads

  • The twclid click identifier on every conversion

  • Conversions arriving in X Ads

    The conversion is matched to a click or an engagement and becomes available for optimisation and reporting.

  • Reconciled against the source

Sanity → X Ads · architecture

How Sanity and X Ads 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

    X Ads needs a click to match

    An event X recognises, a conversion identifier for deduplication, hashed customer information, and the click identifier where you have it.

  3. 3

    The identifier is the bridge

    The twclid click identifier, 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

    X deduplicates browser and server events on a shared conversion ID. Send both without pairing them and every conversion counts twice — worth testing deliberately, because X volumes are often small enough that a doubling reads as a good week.

Sanity → X Ads · normal or broken

Working vs. broken, side by side — Sanity → X Ads

Normal, not a fault

  • The twclid click identifier present on the conversion

  • Sent from your commerce or CRM system

  • Deduplicated correctly

    X deduplicates browser and server events on a shared conversion ID. Send both without pairing them and every conversion counts twice — worth testing deliberately, because X volumes are often small enough that a doubling reads as a good week.

  • Reconciles with the source

Actually broken

  • The twclid click identifier 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

    A post can be quoted, argued with and shared widely by people with no interest in buying anything. Optimising toward engagement on this platform reliably finds an audience that will never convert, and the engagement numbers look excellent throughout.

  • Nobody has reconciled it

Sanity → X Ads · diagnose

Diagnostic order — Sanity → X Ads

  1. 01

    Count conversions carrying the twclid click identifier

  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

    Compare engagement rate against conversion rate by campaign

    On X the two frequently move in opposite directions, and that divergence is the finding rather than a measurement fault.

  5. 05

    Read the match rate, not the success message

    Read the delivered and matched counts in X's reporting rather than assuming a 200 response means the event was usable.

Sanity → X Ads · prove

How it gets proven — Sanity → X Ads

Source of truth

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

  • The twclid click identifier confirmed present on a live conversion.
  • Conversions reconciled per order against imported figures, with deduplication verified on a live test.
  • The conversion confirmed sourced from the commerce system, with front-end routing verified separately.

Sanity → X Ads · free audit

What we check in the free audit

  • Count conversions carrying the twclid click identifier
  • Follow one real conversion end to end
  • Identify the front-end framework, not the CMS
  • Compare engagement rate against conversion rate by campaign
  • 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 → X Ads · when not to buy

When you don't need this — Sanity → X Ads

  • Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the twclid click identifier.
  • There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
  • If X is a brand and community channel for you rather than a performance one, measure it that way and do not force a conversion pipeline onto it.

Sanity → X Ads · what we deliver

What gets built — Sanity → X Ads

  • 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 X Ads

    The X Conversions API, posted server-side with the click identifier and hashed customer data.

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

Store twclid when the visitor lands, pass it into the cart so it reaches the order, and send the purchase server-side from the order webhook with the order ID as the conversion ID.

Free · 30 min

Get Sanity and X Ads joined properly

Free30 minutesNo obligation