Connecting Sanity to GA4
Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. GA4 is where the business goes to understand what happened, which makes an unattributed conversion there expensive in decisions rather than in ad spend. The join between them succeeds or fails on one thing: whether the GA4 client_id reaches the front-end conversion, not a Sanity record before the conversion happens, because GA4 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 GA4: page views and purchases that add up
GA4 issues here belong to the front end: keep only one of enhanced measurement history tracking or a GTM history trigger to avoid double page views, and preserve UTMs through redirects. Send purchases from commerce via Measurement Protocol with the client_id passed to checkout, add Sanity document type or slug as a content_group, and block preview traffic.
On a Sanity-backed site, GA4 problems belong to the front-end framework. With client-side routing, GA4's enhanced measurement can record page views from browser history changes, and if GTM also has a history-change trigger sending page_view, every route counts twice. Check which one is active and turn the other off. Redirects in middleware that run before GA4 loads, for locales or trailing slashes, can drop UTM parameters and file the session as direct.
Purchases come from the commerce system, sent through Measurement Protocol with the client_id the front end passed into checkout. What Sanity does contribute is content context: send the Sanity document type or slug as a content_group or custom parameter on page_view, and you can see which pieces of content precede conversions. That is the one GA4 report this stack makes easier than most.
The pair-specific pollution is preview traffic. Sanity's visual editing and draft previews load the real front end, often inside an iframe in the Studio, and if GA4 fires there, every editor's session counts as a visitor. Gate the GA4 tag on preview or draft mode in the front end, and filter internal traffic as a backstop.
Sanity → GA4 · what breaks
Why this join usually fails — Sanity → GA4
- 01
The GA4 client_id 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
Everything lands under (direct)/(none)
The classic Measurement Protocol symptom, and it always means the same thing: the client_id was missing or wrong, so GA4 had no session to attach the event to and invented a new user.
- 04
Nothing reconciles afterwards
GA4 DebugView shows events arriving with their parameters, and Realtime confirms the user and session they attached to. Neither tells you whether you are double-counting — for that, compare GA4's conversion count against the source system's record for the same window.
Sanity → GA4 · the fix
What working looks like — Sanity → GA4
The GA4 client_id on every conversion
Conversions arriving in GA4
Conversions appear in GA4 attributed to the original session's source and medium, so acquisition reporting reflects what actually drove revenue.
Reconciled against the source
Sanity → GA4 · architecture
How Sanity and GA4 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
GA4 needs a click to match
GA4 needs the client_id to attach a server event to the user and session that produced the click. Without it there is no attribution to inherit and the event is orphaned.
- 3
The identifier is the bridge
The GA4 client_id, 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
GA4 has no built-in deduplication for Measurement Protocol. If the browser also sends the event, it counts twice. The only reliable approach is to decide per event which side sends it, and enforce that decision — GA4 will not protect you from your own duplicates.
Sanity → GA4 · normal or broken
Working vs. broken, side by side — Sanity → GA4
Normal, not a fault
The GA4 client_id present on the conversion
Sent from your commerce or CRM system
Deduplicated correctly
GA4 has no built-in deduplication for Measurement Protocol. If the browser also sends the event, it counts twice. The only reliable approach is to decide per event which side sends it, and enforce that decision — GA4 will not protect you from your own duplicates.
Reconciles with the source
Actually broken
The GA4 client_id 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
The classic Measurement Protocol symptom, and it always means the same thing: the client_id was missing or wrong, so GA4 had no session to attach the event to and invented a new user.
Nobody has reconciled it
Sanity → GA4 · diagnose
Diagnostic order — Sanity → GA4
- 01
Count conversions carrying the GA4 client_id
- 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
Check whether server events carry a session and a source
In GA4 Realtime or DebugView, find the event and look at its session and traffic source. A brand-new user with no source on every server event is the missing-client_id signature.
- 05
Read the match rate, not the success message
GA4 DebugView shows events arriving with their parameters, and Realtime confirms the user and session they attached to. Neither tells you whether you are double-counting — for that, compare GA4's conversion count against the source system's record for the same window.
Sanity → GA4 · prove
How it gets proven — Sanity → GA4
Source of truth
Your commerce, CRM or billing system — Sanity has no orders and no customers.
- The GA4 client_id confirmed present on a live conversion.
- Server events confirmed in DebugView attaching to an existing session with the original traffic source intact.
- The conversion confirmed sourced from the commerce system, with front-end routing verified separately.
Sanity → GA4 · free audit
What we check in the free audit
- Count conversions carrying the GA4 client_id
- Follow one real conversion end to end
- Identify the front-end framework, not the CMS
- Check whether server events carry a session and a source
- 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 → GA4 · when not to buy
When you don't need this — Sanity → GA4
- Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the GA4 client_id.
- There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
- GA4 is reporting, not bidding. If your problem is ad platform optimization, fix the ad platform destination first — GA4 will not change what any campaign does.
Sanity → GA4 · what we deliver
What gets built — Sanity → GA4
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 GA4
Measurement Protocol events with the client_id, session_id and the correct measurement ID and API secret, sent server-side.
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 → GA4 questions, answered
Usually enhanced measurement's history-based page views and a GTM history-change trigger are both on. Keep one.
They can, because previews render the live front end. Disable the GA4 tag in preview and draft mode.
Almost always because the GA4 client_id 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 client_id, from the _ga cookie. Measurement Protocol events without it are rejected or create a brand-new user with no session and no source, which is how server events end up filed under (direct)/(none) and make paid channels look worse than they are. Send session_id alongside it so the event joins the existing session, and include engagement_time_msec or the event may not appear as expected in reports.
Your commerce or CRM system. Send from wherever the money is recorded, not from the content layer.
GA4 DebugView shows events arriving with their parameters, and Realtime confirms the user and session they attached to. Neither tells you whether you are double-counting — for that, compare GA4's conversion count against the source system's record for the same window.
More on Sanity → GA4
- Stripe → GA4Connecting Stripe to GA4
- PayPal → GA4Connecting PayPal to GA4
- HubSpot → GA4Connecting HubSpot to GA4
RELATED GUIDES
Where Sanity → GA4 fits in the rest of your tracking
- Craft → GA4Connecting Craft CMS to GA4
- Concrete CMS → GA4Connecting Concrete CMS to GA4
- Webflow → GA4Connecting Webflow to GA4
- Sanity → Adobe AnalyticsConnecting Sanity to Adobe Analytics
- Sanity → PostHogConnecting Sanity to PostHog
- Local servicesConversion tracking for local businesses, where most conversions bypass the website
- Ghost → GA4Connecting Ghost memberships to GA4
- Statamic → GA4Connecting Statamic to GA4
Free · 30 min
Get Sanity and GA4 joined properly
Free30 minutesNo obligation
