Skip to main content
Magento → GA4Integration guide

Connecting Magento to GA4

Magento is self-hosted and endlessly customisable, which means every installation is different and full-page caching is always in the way. 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 Magento 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

Magento purchases in GA4 from the observer, with the _ga cookie

Read the GA4 client_id and session_id from the _ga cookies on Magento's place-order request, store them on the order, and send purchase by Measurement Protocol from the observer with transaction_id set to the increment_id. GA4 won't deduplicate against a browser purchase, so pick one sender or fill gaps. Send credit memos as refund events, using grand_total with order currency.

The place-order request in Magento's checkout is an ordinary browser request, so the _ga and _ga_<ID> cookies are present when the order is created. Read the client_id and session_id there, store them on the order, and send purchase by Measurement Protocol from the observer with transaction_id set to the increment_id. That path does not depend on the success page, which full-page cache and off-site payment redirects both undermine.

Decide on one sender. Many Magento stores already fire purchase from the success page through a GTM data layer module. GA4 does not deduplicate a browser purchase against a Measurement Protocol one, so if you keep the browser tag, log which orders it fired for and send only the missing ones from the server, such as customers who paid through an external redirect and never came back.

Use the same order-status rule as your revenue reporting: an order at pending payment is not a purchase yet. Credit memos go to GA4 as refund events with the increment_id as transaction_id, plus the refunded items for partial refunds. Multi-currency stores should send grand_total with the order currency code, not base_grand_total labelled with the order currency.

Magento → GA4 · what breaks

Why this join usually fails — Magento → GA4

  1. 01

    The GA4 client_id never reaches Magento

    Magento's full-page cache serves a stored render to the visitor, which means anything relying on dynamically rendered values can silently fail — and in Magento this has historically included serving one customer's cached block to another, which is a data problem as well as a tracking one.

  2. 02

    Full-page cache between the visitor and your code

    The page the customer saw is not the page your code assumed. This is the defining Magento tracking failure and it produces intermittent, hard-to-reproduce loss.

  3. 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.

  4. 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.

Magento → GA4 · the fix

What working looks like — Magento → 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

Magento → GA4 · architecture

How Magento and GA4 actually connect

  1. 1

    Magento holds the truth

    You own the database, so the truth is as good as the query. Pin down which order statuses count as revenue — processing, complete, or both — because that choice moves the number substantially.

  2. 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. 3

    The identifier is the bridge

    The GA4 client_id, captured at the visit and carried into the Magento order.

  4. 4

    The event source decides reliability

    Fire server-side from the observer rather than from the success page template, which is cached and may not execute anything.

  5. 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.

Magento → GA4 · normal or broken

Working vs. broken, side by side — Magento → GA4

Normal, not a fault

  • The GA4 client_id present on the order

  • Sent from the Magento order placement observer

  • 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

    Magento's full-page cache serves a stored render to the visitor, which means anything relying on dynamically rendered values can silently fail — and in Magento this has historically included serving one customer's cached block to another, which is a data problem as well as a tracking one.

  • Sent from the browser

    The page the customer saw is not the page your code assumed. This is the defining Magento tracking failure and it produces intermittent, hard-to-reproduce loss.

  • 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

Magento → GA4 · diagnose

Diagnostic order — Magento → GA4

  1. 01

    Count orders carrying the GA4 client_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Place a test order as an anonymous visitor through cache

    Not as an admin, which bypasses it. If the order data is missing on the cached path, caching is your cause.

  4. 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.

  5. 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.

Magento → GA4 · prove

How it gets proven — Magento → GA4

Source of truth

Magento's sales order records in your own database, for the same window and order status set.

  • 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 data confirmed populated on an order placed through a fully warmed cache.

Magento → GA4 · free audit

What we check in the free audit

  • Count orders carrying the GA4 client_id
  • Follow one real conversion end to end
  • Place a test order as an anonymous visitor through cache
  • Check whether server events carry a session and a source
  • Read the match rate, not the success message

Checked against

Magento's sales order records in your own database, for the same window and order status set.

Get my free conversion tracking audit

Free30 minutesNo obligation

Magento → GA4 · when not to buy

When you don't need this — Magento → GA4

  • Measure identifier coverage yourself first — pull your last hundred orders and count how many carry the GA4 client_id.
  • If your Magento build has heavy customisation by another team, scope their availability first — the build is usually blocked there.
  • 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.

Magento → GA4 · what we deliver

What gets built — Magento → GA4

  • Identifier capture into Magento

    Capture the identifier and persist it as order data through an observer on order placement, server-side, so it never depends on what the cache served.

  • Event source: the Magento order placement observer

    Fire server-side from the observer rather than from the success page template, which is cached 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

    Credit memos are recorded against the original order and should reduce the reported figure.

Written guarantee

95%+ tracking accuracy

Measured against Magento's sales order records in your own database, for the same window and order status set.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Magento → GA4 questions, answered

Usually because the success-page purchase tag did not run for cached pages or for customers who never returned from payment. A server-side purchase from the order observer, using the stored client_id, closes that gap.

Free · 30 min

Get Magento and GA4 joined properly

Free30 minutesNo obligation