Connecting Sanity to TikTok Events API
Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. TikTok's audience skews to exactly the browsers and app contexts where browser-side tracking performs worst. The join between them succeeds or fails on one thing: whether the ttclid reaches the front-end conversion, not a Sanity record before the conversion happens, because TikTok can only match a conversion it can tie back to a click it recognizes.
Free30 minutesNo obligation
Specific to this pair
Sanity front ends and TikTok Events API: capture ttclid server-side
Read ttclid in middleware on the first request and set a first-party server cookie, never in a cacheable page response that could share one visitor's ttclid. Pass ttclid and a shared event_id into checkout, send CompletePayment from commerce with the pixel's event_id, disable tracking in Sanity preview, and test from a real TikTok ad on a phone.
TikTok's in-app browser is the least forgiving place for a JavaScript-heavy front end. If the TikTok pixel loads after hydration and the visitor taps to another route first, ttclid can be gone before anything stored it. Read ttclid in middleware on the first request and set a first-party cookie from your server, so the click is recorded even when the pixel is slow or blocked.
Do that in middleware or another uncached step, never in a page response that your CDN or incremental static regeneration might cache. A cached response carrying a Set-Cookie header can hand one visitor's ttclid to everyone who receives that copy, which corrupts matching quietly. Then pass the ttclid and a shared event_id into checkout, and send CompletePayment from the commerce system with the same event_id the pixel used.
As with any Sanity build, tracking should be off in draft preview and visual editing, or your editors become TikTok's audience. Test the whole path from a real TikTok ad inside the app on a phone, because in-app cookie behavior is the variable here, and desktop testing will look fine when it is not.
Sanity → TikTok · what breaks
Why this join usually fails — Sanity → TikTok
- 01
The ttclid 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.
- 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.
- 03
The ttclid is lost in the in-app browser
TikTok traffic arrives through an in-app webview whose storage behavior is inconsistent. An identifier captured but not immediately persisted server-side often is not there by the time the conversion happens.
- 04
Nothing reconciles afterwards
TikTok Events Manager shows received events and their match status. As with Meta, arriving is not the test — deduplicated and matched is. Reconcile TikTok's reported conversions against the source system for the same window.
Sanity → TikTok · the fix
What working looks like — Sanity → TikTok
The ttclid on every conversion
Conversions arriving in TikTok
Events appear in TikTok Events Manager, deduplicated against the pixel, and become usable for optimization.
Reconciled against the source
Sanity → TikTok · architecture
How Sanity and TikTok actually connect
- 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
TikTok Events API needs a click to match
TikTok matches server events using ttclid where available, falling back to hashed contact information. Both should be sent — the fallback is what carries the events where the click ID did not survive.
- 3
The identifier is the bridge
The ttclid, captured at the visit and carried into the front-end conversion, not a Sanity record.
- 4
The event source decides reliability
Send from wherever the money is recorded, not from the content layer.
- 5
Deduplication at the destination
TikTok deduplicates on event_id, the same pattern as Meta: the pixel and the Events API must send the same event_id for the same conversion. Mismatched IDs mean double counting.
Sanity → TikTok · normal or broken
Working vs. broken, side by side — Sanity → TikTok
Normal, not a fault
The ttclid present on the conversion
Sent from your commerce or CRM system
Deduplicated correctly
TikTok deduplicates on event_id, the same pattern as Meta: the pixel and the Events API must send the same event_id for the same conversion. Mismatched IDs mean double counting.
Reconciles with the source
Actually broken
The ttclid 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
TikTok traffic arrives through an in-app webview whose storage behavior is inconsistent. An identifier captured but not immediately persisted server-side often is not there by the time the conversion happens.
Nobody has reconciled it
Sanity → TikTok · diagnose
Diagnostic order — Sanity → TikTok
- 01
Count conversions carrying the ttclid
- 02
Follow one real conversion end to end
- 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.
- 04
Measure ttclid capture rate on TikTok traffic specifically
Not on all traffic. TikTok's in-app browser is the failure case, so a healthy overall capture rate can hide a poor one on exactly the traffic that matters.
- 05
Read the match rate, not the success message
TikTok Events Manager shows received events and their match status. As with Meta, arriving is not the test — deduplicated and matched is. Reconcile TikTok's reported conversions against the source system for the same window.
Sanity → TikTok · prove
How it gets proven — Sanity → TikTok
Source of truth
Your commerce, CRM or billing system — Sanity has no orders and no customers.
- The ttclid confirmed present on a live conversion.
- Deduplication confirmed in Events Manager, and ttclid capture rate measured on TikTok traffic specifically.
- The conversion confirmed sourced from the commerce system, with front-end routing verified separately.
Sanity → TikTok · free audit
What we check in the free audit
- Count conversions carrying the ttclid
- Follow one real conversion end to end
- Identify the front-end framework, not the CMS
- Measure ttclid capture rate on TikTok traffic specifically
- Read the match rate, not the success message
Checked against
Your commerce, CRM or billing system — Sanity has no orders and no customers.
Free30 minutesNo obligation
Sanity → TikTok · when not to buy
When you don't need this — Sanity → TikTok
- Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the ttclid.
- There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
- If TikTok is a small share of spend, the effort is hard to justify. It pays when TikTok is a channel you are actively scaling.
Sanity → TikTok · what we deliver
What gets built — Sanity → TikTok
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 TikTok
Server events to the TikTok Events API with the ttclid, hashed contact information and a matching event_id.
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.
From $400 · See packages
FAQ
Sanity → TikTok questions, answered
The pixel often loads after the first client-side navigation. Capture ttclid on the first server request and store it in a first-party cookie.
From the commerce system that records the payment, with the same event_id the browser pixel used. Sanity is not involved.
Almost always because the ttclid never reached the front-end conversion, not a Sanity record. 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. Measure coverage before debugging the dispatch.
The ttclid — TikTok's click identifier, appended to your landing page URL and also stored in the _ttp cookie. TikTok additionally matches on hashed email and phone. In-app browser behavior makes ttclid capture more fragile than the equivalents on other platforms, so persisting it server-side as soon as it is seen matters more here than elsewhere.
Your commerce or CRM system. Send from wherever the money is recorded, not from the content layer.
TikTok Events Manager shows received events and their match status. As with Meta, arriving is not the test — deduplicated and matched is. Reconcile TikTok's reported conversions against the source system for the same window.
More on Sanity → TikTok
- TikTok · Lead → booked callHow to track lead to booked call for TikTok Ads
- TikTok · Booked call → closed wonHow to track booked call to closed won for TikTok Ads
- TikTok · Free trial → paidHow to track free trial to paid for TikTok Ads
RELATED GUIDES
Where Sanity → TikTok fits in the rest of your tracking
- TikTok · Local servicesTikTok Ads conversion tracking for local service businesses
- TikTok · B2BTikTok Ads conversion tracking for B2B companies
- TikTok × CRM DealsHow to reconcile TikTok Ads against your CRM's closed-won deals
- TikTok · Comparison page → demoHow to track comparison page visit to demo request for TikTok Ads
- Craft → TikTokConnecting Craft CMS to TikTok Events API
- Sanity → RedditConnecting Sanity to Reddit
- Local servicesConversion tracking for local businesses, where most conversions bypass the website
- Statamic → TikTokConnecting Statamic to TikTok Events API
Free · 30 min
Get Sanity and TikTok joined properly
Free30 minutesNo obligation
