Since the deprecation of Universal Analytics, Google Analytics 4 (GA4) has become the go-to platform for web analytics. While GA4 offers powerful features for tracking user behaviour and purchase funnels, integrating it with Magento requires a more technical approach than many platforms.
This guide covers how to fully and accurately integrate Google Analytics 4 with Magento, ensuring data completeness and reliability — especially when using Google Tag Manager for Magento to manage events.
Magento is a highly flexible, complex eCommerce platform. GA4 is designed to be platform-agnostic. That combination means the integration cannot be done “out of the box.” You may encounter issues like:
add_to_cart
, purchase
, checkout_step
) unless manually configured.These issues make it crucial to use Google Tag Manager for Magento to bridge the gap between your frontend and analytics system.
To ensure a complete setup of Google Analytics 4 on Magento, you’ll need:
Use a Magento 2 extension to insert GTM into your theme safely:
Once installed:
GTM-XXXXX
)Create a GA4 Configuration Tag with your Measurement ID.
Magento does not have a native Data Layer for GA4. You will need to either:
You should track:
view_item
)add_to_cart
)begin_checkout
)purchase
)Example Data Layer for a product page:
These events should be the trigger condition for your GA4 Event Tags inside GTM.
Step 4: Create Event Tags in Google Tag Manager
Each event in your Data Layer should have a corresponding tag in GTM:
add_to_cart
event triggers an “Add to Cart” tagpurchase
event sends order revenue, ID, and itemsEnsure each tag uses the correct GA4 Event Name and pulls parameters from the Data Layer.
Use GA4’s built-in DebugView to confirm:
Common issues include:
transaction_id
items
arrayClient-side tracking can be blocked by browsers, extensions, or privacy settings. Using server-side Google Tag Manager for Magento gives you:
Tools like Stape.io or MagePal’s Server-Side GTM can assist in setup.
Always test in staging first
Avoid firing duplicate purchase
events
Track refunds and cancellations as needed
Consider feeding GA4 data into BigQuery for long-term analysis
Periodically audit GTM container for outdated or broken tags
At Magehouse, we specialise in professional GA4 integration for Magento 2 stores. Our process includes:
A well-executed Google Analytics 4 Magento setup ensures not only clean reporting — but also better decision-making.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |