How to Set Up Google Analytics 4

Overview

Set up Google Analytics 4 (GA4) with enhanced ecommerce tracking to see the full customer journey—from product views to purchases—so you can optimize conversion rates, reduce acquisition costs, and improve store performance. With purchase events in GA4, you can: track revenue and average order value by channel, build remarketing audiences (for example, cart abandoners or high-value buyers), import conversions into Google Ads for Smart Bidding, and diagnose drop-off in the product-to-checkout funnel. Many merchants see improved ROAS within 2–6 weeks after importing reliable GA4 purchase conversions into Google Ads.

Version compatibility and path selection:

  • Magento 2.4.5+: Use Stores > Configuration > Sales > Google API > Google Tag to add your GA4 Measurement ID ( recommended for most merchants). Do not also install GA4 via GTM unless intentionally architected to avoid duplicates.
  • Magento < 2.4.5: Use Google Tag Manager (GTM) or a Marketplace extension to deploy GA4.
  • Choose a single path to avoid duplicate tags. If you must use both Google Tag and GTM, ensure only one source sends page_view and purchase.

Prerequisites

Before you begin, make sure you have:

  • Admin-only path (no code):
    • A GA4 property with a Web data stream and Measurement ID (G-XXXXXXXXXX)
    • Access to Magento Admin (appropriate scope permissions)
    • A GTM Web container (only if you choose the GTM path)
  • Code path (theme/module):
    • Magento development environment and deployment access (staging and production)
    • Ability to clear caches and deploy static content in production mode
    • Basic PHP/XML/JS familiarity (for theme or module edits)
  • Testing:
    • Access to a staging store and a test payment method to place orders
    • Ability to use Tag Assistant (GTM Preview) and GA4 DebugView

What You'll Accomplish

By following this guide, you will:

  • Set up Google Analytics 4 with ecommerce tracking for your Magento store, including page views and purchase events.

Step-by-Step Instructions

Before you start the steps, choose one implementation path to avoid duplicate data:

  • Option A (recommended for Magento 2.4.5+): Use Magento’s native Google Tag (GA4) integration for a no-code install.
  • Option B: Use Google Tag Manager if you manage multiple tags or need advanced control.
  • Option C: Manual theme/module edits (developers) when Admin/GTM options are unavailable.

Follow only one option or coordinate carefully to prevent duplicate events.

Step 0: Create a GA4 property and web data stream

In Google Analytics, create a new GA4 property. Add a Web data stream for your storefront domain and note the Measurement ID (format: G-XXXXXXXXXX). Enable Enhanced Measurement.

If you plan to use GTM (Option B), in Google Tag Manager, create a new container for your domain (target type: Web). Note your container ID (format: GTM-XXXXXXX).

Note: If you’re on Magento 2.4.5+ and do not need GTM, you can use Magento’s Google Tag integration in Step 2 instead. Avoid installing both unless you understand and prevent duplicate events.

Step 2: Install GTM on Magento via Admin (if available)

For Magento 2.4.5+ (Option A: Google Tag GA4, recommended):

  • Go to Stores > Configuration.
  • In the top-left Scope dropdown, select the Website/Store View you want to configure.
  • Navigate to Sales > Google API > Google Tag.
  • Enter your GA4 Measurement ID (G-XXXXXXXXXX), enable the integration, and Save.
  • Go to System > Cache Management and Flush Magento Cache.
  • Multi-store note: Configure per Website/Store View as needed. Uncheck “Use Default” to override values at lower scopes.

About GTM via Admin:

  • The legacy Google Tag Manager module is not included by default in 2.4.4+ unless installed separately. If you don’t see Google Tag or GTM settings in Admin, proceed to Step 3 to add the container via your theme.

Step 3: Install GTM on Magento via theme (alternative)

If your Admin lacks Google Tag or GTM settings, add the GTM snippets via theme/layout.

  • Head script snippet:
    • Preferred: add the GTM