Connecting Drupal Commerce to GA4
Drupal Commerce is self-hosted commerce inside a CMS built for complex content, which means the store is one part of a much larger site you fully control. 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 Drupal 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
Drupal Commerce to GA4: purchases that do not depend on the page
Send GA4 purchases from an event subscriber on the order's place transition through Measurement Protocol, with the order number as transaction_id, the order's currency and items. Save client_id and session_id from _ga cookies at an earlier checkout step, since offsite gateway notifications lack them. Turn off the dataLayer purchase, and send refunds.
The usual Drupal route is the Google Tag module plus a dataLayer purchase pushed from the checkout complete step, which inherits every cache and reverse-proxy problem on the site. The server route is an event subscriber on the order's place transition (commerce_order.place.post_transition in Commerce 2.x) that posts a Measurement Protocol purchase with transaction_id set to the order number, value and currency from the order total, and items from the order items.
That subscriber needs the visitor's client_id and session_id, and on Drupal you have an advantage: the _ga cookies arrive with every checkout request your own server handles. The trap is off-site payment gateways. When the order is placed from the gateway's return or notify request, there is no browser cookie in that request at all, so read the client_id at an earlier checkout step and save it in the order's data. Multi-store installs need a deliberate choice of which GA4 property each store reports to, and the currency taken from each order rather than a site default.
GA4 will not deduplicate your Measurement Protocol purchase against a dataLayer purchase that also fires, so turn the browser purchase off once the server one is proven. Refunds map cleanly: when an order transitions to the refunded or canceled state you agreed counts, send a refund event with the same transaction_id.
Drupal Commerce → GA4 · what breaks
Why this join usually fails — Drupal Commerce → GA4
- 01
The GA4 client_id never reaches Drupal Commerce
Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.
- 02
Configurable workflow states nobody agreed on
Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.
- 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.
Drupal Commerce → GA4 · the fix
What working looks like — Drupal Commerce → 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
Drupal Commerce → GA4 · architecture
How Drupal Commerce and GA4 actually connect
- 1
Drupal Commerce holds the truth
You own the database, so the truth is exactly as good as the query. Pin down which order states count as revenue before comparing anything — Drupal's workflow states are configurable per install, so no two sites agree by default.
- 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 Drupal Commerce order.
- 4
The event source decides reliability
Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
- 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.
Drupal Commerce → GA4 · normal or broken
Working vs. broken, side by side — Drupal Commerce → GA4
Normal, not a fault
The GA4 client_id present on the order
Sent from the Drupal Commerce order placement hook
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
Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run.
Sent from the browser
Drupal Commerce lets each install define its own order states. Two people reporting on the same store routinely count different states and never reconcile.
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
Drupal Commerce → GA4 · diagnose
Diagnostic order — Drupal Commerce → GA4
- 01
Count orders carrying the GA4 client_id
- 02
Follow one real conversion end to end
- 03
List the order states in use and agree which count as revenue
Do this before any technical work — it resolves more Drupal Commerce disputes than any code change.
- 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.
Drupal Commerce → GA4 · prove
How it gets proven — Drupal Commerce → GA4
Source of truth
Drupal's commerce_order records in your own database, filtered to completed states.
- 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 field data confirmed populated on an order placed through a fully warmed cache as an anonymous visitor.
Drupal Commerce → GA4 · free audit
What we check in the free audit
- Count orders carrying the GA4 client_id
- Follow one real conversion end to end
- List the order states in use and agree which count as revenue
- Check whether server events carry a session and a source
- Read the match rate, not the success message
Checked against
Drupal's commerce_order records in your own database, filtered to completed states.
Free30 minutesNo obligation
Drupal Commerce → GA4 · when not to buy
When you don't need this — Drupal Commerce → GA4
- Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the GA4 client_id.
- If your Drupal site is content-only with commerce elsewhere, work at the commerce system instead — this is the wrong layer.
- 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.
Drupal Commerce → GA4 · what we deliver
What gets built — Drupal Commerce → GA4
Identifier capture into Drupal Commerce
Capture the identifier and persist it as order field data through a hook on order placement, server-side, so it never depends on what the cache served.
Event source: the Drupal Commerce order placement hook
Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
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
Order state transitions to refunded or cancelled are recorded and can drive reversals.
Written guarantee
95%+ tracking accuracy
Measured against Drupal's commerce_order records in your own database, filtered to completed states.. Miss it and we keep working at no cost.
From $400 · See packages
FAQ
Drupal Commerce → GA4 questions, answered
The checkout complete page did not run your tag, because of caching or because the customer never returned from an off-site gateway. Sending the purchase from the order's place transition fixes both.
Yes, through Measurement Protocol from an event subscriber on order placement, using the client_id read from the _ga cookie during checkout and stored on the order.
Almost always because the GA4 client_id never reached the Drupal Commerce order. Drupal's internal page cache and any reverse proxy in front of it serve stored renders, so anything relying on dynamically rendered values fails intermittently. Multilingual and multi-site installs add further paths where the capture code may simply not run. 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 Drupal Commerce order placement hook. Fire server-side from the hook rather than the checkout completion template, which is cacheable and may not execute anything.
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 Drupal Commerce → GA4
- Squarespace → GA4Connecting Squarespace Commerce to GA4
- Drupal Commerce → Google AdsConnecting Drupal Commerce to Google Ads
- Drupal Commerce → MetaConnecting Drupal Commerce to Meta Conversions API
RELATED GUIDES
Where Drupal Commerce → GA4 fits in the rest of your tracking
- Contentful → GA4Connecting Contentful to GA4
- Concrete CMS → GA4Connecting Concrete CMS to GA4
- Craft → GA4Connecting Craft CMS to GA4
- Drupal Commerce → PostHogConnecting Drupal Commerce to PostHog
- Drupal Commerce → MixpanelConnecting Drupal Commerce to Mixpanel
- Local servicesConversion tracking for local businesses, where most conversions bypass the website
- Sitecore → GA4Connecting Sitecore to GA4
- Statamic → GA4Connecting Statamic to GA4
Free · 30 min
Get Drupal Commerce and GA4 joined properly
Free30 minutesNo obligation
