Connecting Craft CMS to GA4
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. 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 Craft Commerce order 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
Craft Commerce orders to GA4 from PHP, past the cache
Send GA4 purchases through Measurement Protocol from a PHP listener on Craft Commerce order completion, bypassing the cache. Read the _ga cookie during checkout and save client_id and session_id to an order custom field. Remove any browser purchase tag, since GA4 doesn't deduplicate, and send refunds with the same transaction_id.
Most Craft sites send GA4 purchases from a Twig template on the order confirmation page, and on a site running Blitz or Craft's own template caching that page can be served from cache to the wrong visitor, or not run the snippet at all. The reliable route is a Measurement Protocol call from a PHP event listener on order completion (in Commerce, the order's after-complete event; confirm the exact event name against your installed version), which never passes through the cache.
That listener needs the GA4 client_id, and PHP cannot read the visitor's _ga cookie after the fact unless something stored it. Read the _ga cookie during checkout and save the client_id and session_id to a custom field on the order. Because every Craft build is different, check where cart and checkout requests actually reach the server; on headless Craft builds the front end may be a separate app that has to forward the cookie.
Decide who owns the purchase event. If a browser purchase tag already exists in a template, remove it or GA4 counts the order twice; GA4 has no deduplication for Measurement Protocol. Refunds recorded against the Commerce order can be sent as a GA4 refund event with the same transaction_id, which keeps revenue in GA4 consistent with what Commerce shows.
Craft → GA4 · what breaks
Why this join usually fails — Craft → GA4
- 01
The GA4 client_id 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
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.
Craft → GA4 · the fix
What working looks like — Craft → GA4
The GA4 client_id on every order
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
Craft CMS's own records are the reference, not either dashboard.
Craft → GA4 · architecture
How Craft and GA4 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
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 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
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.
Craft → GA4 · normal or broken
Working vs. broken, side by side — Craft → GA4
Normal, not a fault
The GA4 client_id 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
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
GA4's count and Craft CMS's records agree within a few percent over a closed window.
Actually broken
The GA4 client_id 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
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
The dashboard shows a number and no one has compared it to Craft CMS.
Craft → GA4 · diagnose
Diagnostic order — Craft → GA4
- 01
Count orders carrying the GA4 client_id
- 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 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.
Craft → GA4 · prove
How it gets proven — Craft → GA4
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 GA4 client_id confirmed present on a live order.
- Server events confirmed in DebugView attaching to an existing session with the original traffic source intact.
- Order custom field confirmed populated on an order placed as an anonymous visitor through cache.
Craft → GA4 · free audit
What we check in the free audit
- Count orders carrying the GA4 client_id
- Follow one real conversion end to end
- Read how this specific build handles order completion
- Check whether server events carry a session and a source
- 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 → GA4 · when not to buy
When you don't need this — Craft → GA4
- If GA4 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 GA4 client_id.
- If the original agency is still engaged, the fastest path is usually specifying the field and having them add the hook.
- 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.
Craft → GA4 · what we deliver
What gets built — Craft → GA4
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 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
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 → GA4 questions, answered
Usually a purchase tag in a cached Twig template, firing for some orders, not others, or twice on reload. Sending from a PHP listener on order completion avoids both.
Check the Craft Plugin Store for your Craft and Commerce versions. Whatever you use, confirm whether it sends from the browser or the server, because that decides whether caching affects it.
Almost always because the GA4 client_id 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.
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.
The Craft Commerce order-complete event. Fire from the event listener in PHP rather than a Twig template, which may be cached.
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 Craft → GA4
- Craft → Google AdsConnecting Craft CMS to Google Ads
- Craft → MetaConnecting Craft CMS to Meta Conversions API
- Craft → HubSpotConnecting Craft CMS to HubSpot
RELATED GUIDES
Where Craft → GA4 fits in the rest of your tracking
- AEM → GA4Connecting Adobe Experience Manager to GA4
- Contentful → GA4Connecting Contentful to GA4
- Webflow → GA4Connecting Webflow to GA4
- Craft → PostHogConnecting Craft CMS to PostHog
- Craft → MixpanelConnecting Craft CMS to Mixpanel
- Local servicesConversion tracking for local businesses, where most conversions bypass the website
- Duda → GA4Connecting Duda to GA4
- Sanity → GA4Connecting Sanity to GA4
Free · 30 min
Get Craft and GA4 joined properly
Free30 minutesNo obligation
