Trackum

Magento 2 GA4: set up Google Analytics 4 in your shop

Magento 2 can send data to GA4 in two ways: the built-in module or Google Tag Manager with a dataLayer. Here is how to choose, set it up and check the purchase event.

Guide · · 5 min read · Written with AI, AI-assisted review on

Magento 2 GA4: set up Google Analytics 4 in your shop
📷 Andras Vas · Unsplash

How does Magento 2 send data to GA4?

Magento 2 sends data to Google Analytics 4 (GA4) either through its built-in Google module or through Google Tag Manager fed by a dataLayer. Since release 2.4.5, the built-in module in Magento Open Source and Adobe Commerce uses the Google tag and accepts a GA4 measurement ID. Google Tag Manager needs an extension or theme code that writes ecommerce data into the dataLayer, but it gives you one place to manage GA4, Google Ads, the Meta Pixel and consent. Whichever route you choose, use only one, because running both is the most common reason for doubled figures in Magento 2 GA4 reports.

Many UK and Irish shops still run on Magento 2 after years of upgrades, and their tracking often carries layers from different agencies: an old Universal Analytics snippet in the theme, a module from 2019 and a Google Tag Manager container added later. Before you set up anything new, find out what is already there.

A short inventory is enough. Search the theme templates for gtag, analytics.js and googletagmanager, list the installed extensions with Google, analytics or tag in their name, and check the Google API settings in the admin. Then open the shop with the browser developer tools and filter the network panel for collect and gtm.js. Every measurement ID and container ID you find should have an owner and a reason to exist. Anything without an owner is a candidate for removal before you add a new setup.

How do you set up the built-in GA4 module?

The built-in module is the fastest route for a shop that only needs GA4. According to the Adobe Commerce documentation, the setting sits under Stores, Settings, Configuration, Sales, Google API, Google GTag, Google Analytics4. Set Enable to Yes, keep the account type as Google Analytics4 and enter your measurement ID, which starts with G-. Save, flush the cache and check the result in the GA4 Realtime report.

Then check which ecommerce events the module actually sends in your version and theme. Open DebugView in GA4, browse a product, add it to the basket and place a test order. If view_item, add_to_cart, begin_checkout or purchase are missing, or if the purchase has no items, the module alone will not give you complete ecommerce reports, and Google Tag Manager with a dataLayer is the better choice.

→ Cookie banner with Consent Mode v2: compliant, with no monthly licence

When is Google Tag Manager the better choice for Magento?

Google Tag Manager is the better choice as soon as more than one tool needs shop data. A Magento extension or custom theme code pushes events such as view_item, add_to_cart and purchase into the dataLayer, and Google Tag Manager passes them to GA4, Google Ads and the Meta Pixel. That way every platform receives the same order ID and the same value, and you change tags without deploying new shop code.

Built-in module or Google Tag Manager
CriterionBuilt-in Google moduleGoogle Tag Manager with dataLayer
EffortLow, configuration in the adminMedium, extension or theme code plus tags
Other platformsGA4 onlyGA4, Google Ads, Meta, Microsoft Advertising and more
Consent controlDepends on how the module loadsCentral, with Google Consent Mode v2
Changes laterNeed a shop deploymentPossible in Google Tag Manager

If you choose this route, switch off the built-in Google module so GA4 is loaded only once. Load the Google Tag Manager snippet as high as possible in the head of every page, including the checkout and success page. Test every step in the Google Tag Manager preview before you publish, and keep the previous container version so you can roll back quickly if an order event goes missing.

What must the purchase event contain?

The purchase event is the one that matters most, and it needs four things: a unique transaction_id, the value, the currency and an items array. Use the Magento order increment ID as transaction_id, so GA4 can ignore repeated sends when a customer reloads the success page. Decide whether value includes tax and shipping, document it, and use the same rule in Google Ads. For shops selling in pounds and euros, make sure currency follows the store view, not a fixed setting.

  • transaction_id: the order increment ID, never empty and never reused
  • value: a number without currency symbol or thousands separator
  • currency: GBP or EUR as a three-letter ISO code
  • items: item_id, item_name, price and quantity for each line

→ Setting up Google Consent Mode v2 correctly: no warning in Tag Assistant

Common Magento 2 GA4 problems

Doubled page views and purchases are the most frequent problem, caused by the built-in module and Google Tag Manager both sending to the same measurement ID. Payment referrals come second: customers who pay through PayPal, Klarna or a card provider's secure page return to the success page as a new referral. Add those domains to the list of unwanted referrals in your GA4 data stream. The third problem is consent: if GA4 loads before the cookie banner has been answered, the shop collects data without consent, which generally conflicts with the cookie rules in Ireland and, apart from narrow exceptions, in the UK. This article is not legal advice.

Consider a homeware shop in Leeds on Magento 2.4. After an upgrade, GA4 reported almost twice as many orders as the Magento admin. A browser test showed two GA4 requests per page: one from the built-in module and one from Google Tag Manager. Switching off the module, adding the order increment ID as transaction_id and excluding the payment domains brought GA4 back in line with the admin within a week. A small gap remains normal, because some customers block tracking or reject cookies, but the trend now matches the order book.

How Trackum helps Magento shops

The free check at trackum.app/check opens your shop in a real browser three times, with the cookie banner unanswered, rejected and accepted, and shows which tags and cookies load, so doubled GA4 tags and tags that ignore the banner become visible within two minutes. Trackum fixes the findings in your existing Google Tag Manager for €79 plus VAT, or sets up Google Tag Manager, GA4 and Consent Mode v2 with up to 15 events for €150 plus VAT, tested before anything goes live.

Frequently asked questions

Does Magento 2 support GA4 out of the box?

Since release 2.4.5, the Google module in Magento and Adobe Commerce uses the Google tag (gtag.js) and has a setting for Google Analytics 4. Older versions only supported Universal Analytics, which stopped processing data in 2023, so they need an update or an extension.

Should I use the built-in module or Google Tag Manager?

The built-in module is quick for a basic setup. Google Tag Manager is the better choice if you also run Google Ads, the Meta Pixel or other tags, because all of them can then share one dataLayer and one consent setup.

Why does GA4 show PayPal as a source of purchases?

Customers who return from an external payment page start a new referral from that domain. Add the payment provider's domains to the list of unwanted referrals in your GA4 data stream, so the original source keeps the purchase.

How do I know if my Magento purchase tracking is correct?

Place a test order and watch DebugView in GA4. The purchase event should appear once, with transaction_id, value, currency and an items array that matches the order in the Magento admin.

Sources

  1. Adobe Experience League: Google Analytics in Adobe Commerce and Magento Open Source experienceleague.adobe.com
  2. Google for Developers: Measure ecommerce in GA4 developers.google.com
  3. Google Analytics Help: Identify unwanted referrals support.google.com
Help