How To Setup Magento 2 Google Analytics 4 (GA4) Ecommerce Tracking

If you're running an online store on Magento 2, tracking user behavior and purchases is critical for making data-driven business decisions. With Google Analytics 4 (GA4), you get advanced insights into your customers' journey — from product views to conversions. In this guide, we’ll walk you through how to set up GA4 eCommerce tracking in Magento 2, even if you're not a developer.

This guide uses Google Tag Manager (GTM) and a Magento 2 GA4 extension to simplify implementation.

Why Use Google Analytics 4 for Magento 2?

GA4 offers:

  • Event-based tracking instead of session-based.

  • Cross-device user journey mapping.

  • Enhanced eCommerce tracking to monitor the full sales funnel.

  • AI-powered insights and predictions.

If you’re still using Universal Analytics, migrating to GA4 is essential — UA is deprecated and no longer tracks new data.

Prerequisites Before You Begin

  • A Magento 2 store (version 2.3+ recommended).

  • A Google Analytics 4 property created in your Google account.

  • A Google Tag Manager container.

  • A Magento 2 GA4 Extension (like MageDelight’s GA4 Extension).

Step-by-Step Setup Guide for Magento 2 GA4 Ecommerce Tracking


1. Create a Google Analytics 4 Property

Create a Google Analytics 4 Property

  1. Visit Google Analytics and log in.

  2. Navigate to Admin > Create Property.

  3. Choose GA4, fill in your store name and URL.

  4. Create a Web Data Stream and copy your Measurement ID (e.g., G-XXXXXXX).

2. Set Up Google Tag Manager (GTM)

Set Up Google Tag Manager

  1. Go to Google Tag Manager.

  2. Create a new account or use an existing one.

  3. Add a new container and select "Web" as the platform.

  4. Copy the Container ID (e.g., GTM-XXXXXX).

3. Install a GA4 Magento 2 Extension

To streamline data layer setup and event tracking, use a GA4 Magento extension:

  • Choose a trusted provider (e.g., MageDelight, Meetanshi, Mageplaza).

  • Install via Composer or Magento Admin Panel.

  • Run upgrade and deployment commands if needed:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush


4. Configure the Extension in Magento 2 Admin

Configure the Extension in Magento 2 Admin

  1. Go to Stores > Configuration > Google API (or vendor-specific tab: e.g. MageDelight > GA4 with GTM).

  2. Enter the GA4 Measurement ID and GTM Container ID.

  3. Enable Enhanced Ecommerce Tracking.

  4. Save the settings and clear the Magento cache.

5. Import GTM JSON Template (If Provided by Extension)

Import GTM JSON Template

Most GA4 Magento extensions provide a ready-to-use GTM JSON container file:

  1. In GTM, go to Admin > Import Container.

  2. Upload the JSON file.

  3. Choose to merge with the existing workspace.

  4. Review Tags & Triggers before publishing.

The preconfigured container usually includes events like:

  • view_item_list

  • view_item

  • add_to_cart

  • begin_checkout

  • purchase

6. Enable Enhanced Ecommerce Settings in GA4 Tags

  1. In GTM, open your GA4 Event Tags.

  2. Under “Event Parameters,” enable "Send Ecommerce data".

  3. Set the data source to "Data Layer".

  4. Save changes and publish your container.

7. Test the Setup

Test the Setup

  • Use GTM Preview Mode to verify tags are firing on your store.

  • In GA4, open Realtime reports to check incoming data.

  • Use Chrome GA Debugger Extension for more technical troubleshooting.

What GA4 Tracks in Magento 2?

A properly configured setup tracks the full user journey:

Event Name Description
view_item_list Product listing views
view_item Product detail views
add_to_cart Product added to cart
remove_from_cart Product removed from cart
begin_checkout Checkout started
add_shipping_info Shipping method selected
add_payment_info Payment method selected
purchase Order completed
refund Refunds (if supported by extension)

Key GA4 Enhanced Ecommerce Reports to Explore

1. Shopping Behavior Report

Understand how users progress through:

  • Product view → Cart → Checkout → Purchase.

  • Identify drop-off points and low-performing stages.

2. Checkout Behavior Report

  • Visualize each checkout step.

  • Track abandonments and optimize UX.

3. Product Performance

  • See which products get views, clicks, and purchases.

  • Track product revenue and add-to-cart rate.

4. Sales Performance

  • Monitor total revenue, AOV, conversion rate.

  • Segment by campaign, source, or device.

5. Ecommerce Purchases

  • Deep dive into product categories, quantity, refunds.

  • Analyze bundled purchases and coupon usage.

Direct GA4 Code vs. GTM: Which One Should You Use?

Feature Direct Code GTM (Recommended)
Ease of Setup
Flexibility
Data Layer Integration ❌ Manual ✅ Auto via plugin
Enhanced Ecommerce ❌ Complex ✅ Prebuilt
Ongoing Changes ❌ Developer Required ✅ Admin-friendly

FAQs

Q1: Can I set up GA4 without Google Tag Manager?
Yes, but it requires manual code injection and custom event setup, which is error-prone. GTM is highly recommended for scalability.

Q2: Which Magento 2 GA4 extension is best?
MageDelight’s Google Analytics 4 Extension for Magento 2 offers prebuilt GTM templates and full Enhanced Ecommerce support.

Q3: How do I know if GA4 is working correctly?
Use GTM’s preview mode and GA4 Realtime reports to validate events. You should see triggered events under the Events tab.


Final Thoughts

Setting up Google Analytics 4 Ecommerce Tracking in Magento 2 helps you unlock valuable customer insights, improve conversion funnels, and make smarter marketing decisions. By leveraging Google Tag Manager and a robust GA4 extension, you can automate most of the work and start tracking within hours.

Ready to take your Magento 2 store analytics to the next level?