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.
Why Magento Needs a Custom GA4 Setup
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:
- GA4 does not track ecommerce events (like
add_to_cart
, purchase
, checkout_step
) unless manually configured.
- AJAX-based checkout flows in Magento are not visible to GA4 without enhanced tracking.
- Product attributes and variations may not be passed properly.
- Server-side orders (via admin panel) are invisible unless handled separately.
These issues make it crucial to use Google Tag Manager for Magento to bridge the gap between your frontend and analytics system.
What You’ll Need
To ensure a complete setup of Google Analytics 4 on Magento, you’ll need:
- A Google Tag Manager container properly embedded in your Magento theme
- A Magento-compatible Data Layer that pushes structured ecommerce data
- Event tags and triggers in GTM to send data to GA4
- Debugging tools to verify accuracy
- Optional: server-side tagging for greater reliability
Step-by-Step Integration Guide
Step 1: Add Google Tag Manager to Magento
Use a Magento 2 extension to insert GTM into your theme safely:
Once installed:
- Enter your GTM Container ID (e.g.,
GTM-XXXXX
)
- Confirm it’s loading properly using Google Tag Assistant or Chrome DevTools
- This lays the foundation for your Google Analytics 4 Magento implementation.
Step 2: Set Up GA4 Tags in GTM
Create a GA4 Configuration Tag with your Measurement ID.
- Trigger it on all pages
- Optional: Use a consent trigger if your store complies with GDPR or similar privacy laws
Step 3: Push Ecommerce Events to the Data Layer
Magento does not have a native Data Layer for GA4. You will need to either:
- Custom-code the Data Layer
- Use an extension (like MagePal Enhanced Ecommerce)
You should track:
- Product views (
view_item
)
- Add to cart (
add_to_cart
)
- Begin checkout (
begin_checkout
)
- Purchases (
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” tag
purchase
event sends order revenue, ID, and items
Ensure each tag uses the correct GA4 Event Name and pulls parameters from the Data Layer.
Step 5: Validate with GA4 DebugView
Use GA4’s built-in DebugView to confirm:
- Tags are firing
- Parameters are complete
- No duplicate or missing purchase events
Common issues include:
- Missing
transaction_id
- Incorrect formatting of
items
array
- Currency mismatches
Step 6 (Optional): Use Server-Side Tracking
Client-side tracking can be blocked by browsers, extensions, or privacy settings. Using server-side Google Tag Manager for Magento gives you:
- Higher accuracy
- Visibility into backend-created orders
- Support for long-term data privacy compliance
Tools like Stape.io or MagePal’s Server-Side GTM can assist in setup.
Best Practices for Google Analytics 4 Magento Integration
-
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
How Magehouse Handles It
At Magehouse, we specialise in professional GA4 integration for Magento 2 stores. Our process includes:
- Installing and configuring Google Tag Manager for Magento
- Building a fully functional Data Layer for ecommerce events
- Creating and testing all relevant GA4 tags
- Optionally setting up server-side tracking
- Ongoing support and optimisation
A well-executed Google Analytics 4 Magento setup ensures not only clean reporting — but also better decision-making.