How to Setup GA4 eCommerce Tracking in Magento 2 using GTM

How to Setup GA4 eCommerce Tracking in Magento 2 using GTM

As of 2025, Google Analytics 4 (GA4) has become the go-to analytics platform, replacing Universal Analytics entirely. If you’re using Magento 2, setting up GA4 eCommerce tracking is essential to gain insights into your customers’ behavior, optimize your sales funnel, and make data-driven decisions.

In this detailed guide, we’ll show you step-by-step how to implement GA4 eCommerce tracking in Magento 2 using Google Tag Manager (GTM). Whether you are a Magento expert or a marketing professional, this guide will help you collect valuable insights with minimal friction.

Why Google Analytics 4 Is Crucial for Magento 2 Stores

GA4 isn’t just a replacement for Universal Analytics; it’s a powerful event-based platform that provides more flexibility and deeper insights into user behavior across devices and platforms. Key benefits for Magento store owners include:

  • Enhanced eCommerce reporting (add-to-cart, checkout, purchase, etc.)
  • Event-driven data model for more accurate tracking
  • Cross-device tracking (web and app)
  • AI-powered insights for better forecasting
  • Improved integration with Google Ads

If you’re not yet using GA4, you’re missing critical visibility into your online store’s performance.

Prerequisites

Before you begin, make sure:

  • You have a Google Analytics 4 property
  • Google Tag Manager (GTM) account is ready
  • Access to Magento 2 Admin Panel
  • Your Magento store is live or on a staging environment

(Optional but ideal) You’re using or plan to install a Magento GTM extension

Step 1: Create Your GA4 Property

  1. Go to Google Analytics
  2. Click Admin > Create Property
  3. Name your property and select your timezone & currency
  4. Choose Web as the data stream
  5. Copy your Measurement ID (G-XXXXXXX) from the Web Stream settings (That is your GA4 tracking ID)

Step 2: Set Up Google Tag Manager in Magento 2

Option A: Manual Installation
  1. Log in to your GTM account and create a container for your Magento site
  2. Copy the container code snippets
  3. Go to Magento Admin:
    • Navigate to Content > Design > Configuration
    • Choose your store view and click Edit
    • Paste the <head> and <body> GTM codes into the appropriate sections (HTML Head and Footer)
  4. Click Save Configuration and Flush Cache.
Option B: Use a Magento GTM Extension

For e-commerce tracking, we strongly recommend installing an extension that supports GA4-ready data layers:

  • WeltPixel GTM for Magento 2
  • MagePal Google Tag Manager
  • Anowave GTM Enhanced eCommerce

These tools inject GA4-compliant dataLayer events automatically, saving time and reducing the need for custom coding.

Step 3: Configure eCommerce Events in GTM

After GTM is installed, it’s time to track user actions and conversions.

Common eCommerce Events in GA4:
  • view_item (Product page view)
  • add_to_cart
  • begin_checkout
  • purchase
How to Set Up GA4 Tags in GTM:
  1. Create GA4 Configuration Tag
    • Go to GTM → Tags → New → GA4 Configuration
    • Enter your Measurement ID
    • Trigger: All Pages
    • Save & Publish
  2. Create GA4 Event Tags
    • Go to GTM → Tags → New → GA4 Event
    • Name the event (e.g., add_to_cart)
    • Use Data Layer variables for items and values
    • Set appropriate triggers (e.g., Click Classes or URL matching)

If you’re using a GTM extension, most of these events are pushed automatically to the dataLayer.

Step 4: Debug and Test Your Setup

Before going live, validate your setup:

  1. Use Google Tag Manager Preview Mode
    • In GTM, click “Preview.”
    • Enter your Magento store URL and start the session
  2. Open your store in a new tab and:
    • View a product
    • Add an item to the cart.
    • Complete a checkout (use test payment method if needed)
  3. In GA4, navigate to Admin > DebugView
    • Confirm that events like view_item, add_to_cart, and purchase are recorded
  4. Use the Google Tag Assistant Chrome Extension for troubleshooting

Step 5: Mark Key Events as Conversions in GA4

To track goals like purchases or checkout starts, mark key events as conversions in GA4.

How to Mark a Conversion:
  1. Go to GA4 → Admin → Events
  2. Find events like purchase, add_to_cart, etc.
  3. Toggle the switch to Mark as conversion

These conversions will now appear in your Reports and can be used for:

  • Google Ads remarketing
  • Attribution modeling
  • Funnel analysis

Bonus Tip: Use GA4 Explorations for Deeper Insights

Once data starts flowing, use GA4 Explorations to analyze:

  • Checkout abandonment rates
  • Product performance
  • Customer journeys
  • Device behavior differences
  • User cohort performance

Explorations are flexible, visual, and far more powerful than standard UA reports.

Final Thoughts

Setting up Google Analytics 4 eCommerce tracking in Magento 2 may seem technical at first, but it’s one of the most impactful steps you can take for your business in 2025. With the right setup, you’ll gain full visibility into customer behavior, optimize your conversion funnel, and improve your marketing ROI.

Quick Setup Checklist:
  • GA4 property created and configured
  • GTM installed in Magento 2
  • eCommerce events implemented (automatically or via custom tags)
  • Debugged with GTM Preview & GA4 DebugView
  • Conversion events marked
  • Reporting customized via GA4 dashboards or Explorations
Need Help?

At WebPlanex, we specialize in Magento 2 development and advanced GA4 tracking solutions. If you need a faster, cleaner implementation or want to audit your current setup, reach out for a free consultation. Our experts can help you unlock the full power of your eCommerce data.

We use cookies to give you the best experience.