Get 15% off Mageplaza extensions & subscriptions! Use code HIMAY at checkout.

How to Integrate Google Analytics in Magento 2

Vinh Jacker | 06-17-2019

The Most Popular Extension Builder for Magento 2

With a big catalog of 224+ extensions for your online store

Monitoring your Magento store’s performance is vital for growth and insights. Neglecting this aspect can lead to underperformance and a lack of valuable data.

To address this, tracking your store’s activity is essential, and Google Analytics 4 (GA4) offers a free and effective solution. Unlike other options that may be paid or less efficient, GA4 provides real-time insights into crucial metrics such as visitors, page sessions, and conversions.

In this article, we’ll explore how to seamlessly integrate GA4 with your Magento stores for improved performance tracking.

What is Google Analytics 4?

Google Analytics 4 (GA4) was introduced by Google as a replacement for Universal Analytics (UA). Initially, both platforms coexisted, but as of July 1st, 2023, Google ceased tracking on UA, automatically upgrading accounts that hadn’t been manually updated.

The new GA4 version offers significant improvements over its predecessor. Notable enhancements include improved data tracking, a more streamlined interface, and expanded customization capabilities.

Below, we’ll delve into some of the key differences between the two versions:

Universal Analytics Google Analytics 4
UA primarily tracked page views and didn’t capture other user actions within a session, such as video watching or clicks GA4’s advanced tracking goes beyond page views, capturing individual events like engagements and signups. Page views are just one of many properties tracked, highlighting its broader capabilities.
UA calculated bounce rates based on the percentage of sessions where users viewed only one page and triggered only one request to the Analytics server. GA4 calculates bounce rates as the percentage of sessions that were not engaged sessions. Simply, the bounce rate in GA4 is inversely correlated with the engagement rate.
UA had limited capabilities in terms of predictive data. GA4 leverages advanced machine learning to provide predictive results for three key metrics: Purchase probability, Churn probability, and Predicted revenue.
In UA, report pages weren’t customizable. It’s possible to customize the reports and rearrange data cards.

Benefits of Using Google Analytics 4

There are compelling reasons to integrate GA4 with your Magento store:

  • Free Integration:

GA4 offers a cost-effective solution for tracking, especially when compared to many paid extensions for Magento. Given the expenses involved in building a Magento store, having a robust and free tracking tool like GA4 is advantageous.

  • Improved Report Flow:

Unlike UA, GA4 provides a more refined report flow for Magento analytics. It allows for pinpointed analysis by setting endpoints and retracing each step to comprehensively track the customer journey.

  • Predictive Metrics:

GA4 introduces predictive analytics, a feature absent in several premium tracking tools. While not pinpoint accurate, these predictions provide insights into the potential direction of your store’s metrics.

  • Real-time Analytics:

GA4 keeps track of data in real-time and promptly notifies you of anomalies. This immediate feedback allows you to monitor data closely and take necessary actions as needed.

  • Effortless Funnel Building:

GA4 simplifies funnel building, enabling you to track how visitors move through different stages of your funnels and identify where they drop off. This facilitates the creation of more effective funnels and ultimately improves conversion rates.

  • Compatibility with Web and Apps:

GA4 supports tracking for Web, Android, and iOS, making it seamless to monitor your Magento stores. This feature, absent in the previous version, enhances the versatility of tracking across different platforms.

How to Integrate Magento with Google Analytics 4?

To integrate GA4 with your Magento store for free, follow these step-by-step instructions:

  • Set Up Tag Manager Account

Set Up Tag Manager Account

Sign up on and create an account. Input necessary information, provide a container name, and click Create.

Set Up Tag Manager Account

  • Accept Permissions and Get GTM Codes

Accept Permissions and Get GTM Codes

Accept permissions and obtain GTM installation codes. Copy the <head> and <body>codes for later use.

  • Configure Magento Dashboard

In your Magento Dashboard, navigate to ContentConfigurationEditHTML Head.

Configure Magento Dashboard

Design Configuration

  • Paste GTM Codes

In the HTML Head section, paste the <head> code in Scripts and Style Sheets, and the <body> code in FooterMiscellaneous HTML.

Paste GTM Codes

  • Save Configuration and Clear Cache

Click Save Configuration. Clear the Magento Cache by going to SystemCache ManagementFlush Magento Cache.

Cache Management

  • Preview in Google Tag Manager

Preview in GTM

Go to Google Tag Manager, click Preview. Enter your site’s URL, click Connect.

Connect Tag Assistant to your site

  • Confirmation and Tag Assistant

Once connected, you’ll see a “Connected” message. It will also open your website page with the Tag Assistant Connected message.


Click Continue, and your GA4 is now integrated with your Magento store.

With GA4 powering your Magento store, you’re ready to utilize advanced analytics and tracking. To enhance your store’s performance tracking further, consider implementing the tips provided below.

Another way to integrate GA4 into your Magento 2 store is using the GTM extension. For more detailed instructions, please check How to add Google Analytics 4 code to Magento 2?

How to Execute Effective GA4 Tracking?

Navigating GA4 might seem like an adventure, especially if you’re not familiar with the platform. However, there’s no need to worry, as you can optimize your Magento store tracking with the right approach. Consider the following tips:

  • Define Your Tracking Metrics:

Select only the metrics in GA4 that are relevant to your store’s growth. Avoid tracking irrelevant numbers, as they can muddy your data and impede clear decision-making. Customize your metrics under the ‘REPORT DATA’ section to focus on what matters most.

  • Utilize Custom Reports:

Take advantage of the flexibility to customize reports and key metrics in GA4. Explore different dimensions such as bounce rates, sessions, customer personas, and create dashboards tailored to specific business goals. Access custom reporting under the ‘REPORT DATA’ section in GA4.

  • Don’t Overlook Predictive Numbers:

GA4 provides insights into the future through machine learning, offering results for Churn Probability, Predicted Revenue, and Purchase Probability. While valuable, use these numbers cautiously, as they are indicative and should not be the sole basis for strategy, especially for newer stores with limited data.

  • Track Acquisition Sources:

Understand the channels bringing traffic to your store. Effective tracking of traffic acquisition sources is essential for directing efforts strategically and optimizing resources. Without proper tracking, you risk wasting time and resources, potentially losing valuable customers.

Verifying whether Google Analytics works

The first step is to access the Google Analytics dashboard and go to the Realtime section of your newly created property. In this section, you can track live site visitors and their interactions on your site.

If there are no live visitors visible on your dashboard, follow these steps to troubleshoot possible issues with Magento analytics:

  • Turn off all ads and analytics-blocking features in your browser.

  • Double-check the Google Analytics code in the backend for accuracy.

  • Clear your Magento store’s cache.

When you complete these troubleshooting steps, you should see realtime data on the Google Analytics tracking dashboard. It will show potential customers’ activities as they view products and proceed through the checkout process.


1. Does Magento support analytics?

Yes, Magento provides built-in analytics features. You can track your store’s performance directly on the Magento dashboard by navigating to the Reports section. However, it’s essential to note that these built-in analytics can be pretty basic, and you will need to use advanced analytics tools such as Google Analytics 4 for enhanced performance tracking.

2. How to set up and Integrate GA4 with Magento?

  • There are three main approaches to setting up and integrating GA4 with Magento:
  • Direct Integration Code: GA4 provides integration code you can add to your Magento website.
  • Using Google Tag Manager (GTM): GTM is a free Google tool for managing tags, including GA4, on your website.
  • Using Extensions: Several Magento extensions cater specifically to GA4 integration.

3. What to Consider When Setting Up GA4?

  • GA4 Account Setup: You’ll need to create a new GA4 property or use an existing one.
  • Data Stream Creation: A new data stream needs to be set up within GA4 to track your Magento website.
  • Ecommerce Tracking Configuration: GA4 offers built-in ecommerce tracking features. Configure these features to track crucial events like product views, cart additions, and purchases.
  • Verification: After setup, verify that GA4 is accurately tracking data from your Magento website.

4. Is Magento compatible with GA4?

Absolutely! Magento is fully compatible with GA4. You can seamlessly integrate the two platforms. By pairing Magento with GA4, you gain access to powerful insights into your customers’ journey and overall store experience. GA4 offers event-based tracking, user engagement metrics, and real-time insights.

5. Why integrate GA4 with Magento?

It is important for your Magento 2 store because it helps you to track the full customer journey, get advanced analytics, and measure campaign performance.


In short, integrating Google Analytics 4 (GA4) with Magento 2 stores is a straightforward process. By following the provided steps, you can effectively pair up these platforms and initiate your Magento analytics journey with GA4.

Ensure to maximize GA4’s potential through customization options and explore additional Google tools, such as Ads conversion and Ads remarketing, using the tag manager. Utilize these insights to enhance your store analytics and make informed decisions for optimal performance.

Related Posts:


Hello, I'm the Chief Technology Officer of Mageplaza, and I am thrilled to share my story with you. My deep love and passion for technology have fueled my journey as a professional coder and an ultra-marathon runner. Over the past decade, I have accumulated extensive experience and honed my expertise in PHP development.

Related Post

Website Support & Maintenance Services

mageplaza services

Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.