Magento Google Analytics: How to Set Up and Troubleshoot GA4 in Magento 2

Table of Content

google analytics magento

Making data-driven decisions is crucial for the success of any Magento 2 store. According to Forbes, data-driven companies are 23 times more likely to outperform competitors in customer acquisition, 19 times more likely to remain profitable, and nearly 7 times more likely to retain customers. 

Google Analytics (GA) is a powerful tool for driving data-driven decision-making in e-commerce. With Magento 2 and the latest version of Google Analytics, GA4, store owners can gain valuable insights into user demographics, traffic sources, and conversion rates – critical data for making informed, strategic decisions.

In this guide, we’ll explore the benefits of using Google Analytics with Magento 2, walk you through the setup and integration process, and provide quick fixes for the most common issues.

Why GA4 is Better Than the Deprecated Universal Analytics (UA)

Google Analytics 4 (GA4) is a major upgrade from Universal Analytics (UA), officially deprecated as of July 1, 2023. GA4 offers more advanced tracking, deeper insights, and improved adaptability for modern e-commerce. Here’s why GA4 is superior to UA:

  • Event-Based Tracking Instead of Sessions Unlike UA’s session-based model, GA4 focuses on event-based tracking. This means every user interaction – clicks, scrolls, purchases – is tracked individually.
  • Cross-Device & Cross-Platform Tracking – GA4 integrates web and app data into a single property, allowing you to track users across multiple devices and platforms. UA required separate properties for web and mobile tracking.
  • Better E-commerce Insights with AI & Predictive Metrics – GA4 uses machine learning to provide predictive metrics like purchase probability, churn likelihood, and revenue forecasting.  
  • Enhanced Privacy & Compliance – GA4 is designed for a cookieless future, relying on AI-driven modeling to fill data gaps while staying compliant with GDPR and CCPA. UA heavily relied on cookies, making it less adaptable to privacy regulations.
  • More Flexible Reporting & Customization – GA4 allows for fully customizable reports through Exploration Reports, unlike UA’s predefined reporting structure. 

Read More: Google Analytics 4 vs. Universal Analytics

Why You Need Magento 2 Google Analytics Integration

Integrating Google Analytics with Magento 2 allows for tracking user behavior, optimizing marketing efforts, and improving sales performance. With GA4, you gain insights into key metrics like page views, conversion rates, and customer journeys. 

This data helps you identify high-performing products, detect drop-off points in the checkout process, and refine your marketing strategies. What’s more, linking GA4 with Google Ads and Search Console enables better ad targeting and SEO optimization, ensuring you maximize your store’s growth potential.

How GA4 for Magento Compares to Key Alternatives

FeatureGoogle Analytics 4 (GA4)MatomoAdobe AnalyticsPiwik PRO
CostFreePaidEnterprise pricingPaid (with free core plan)
Event-Based Tracking✅ Yes✅ Yes✅ Yes✅ Yes
AI-Powered Insights✅ Yes (predictive analytics, churn probability)❌ No✅ Yes (advanced machine learning)❌ No
Google Ads Integration✅ Yes (native integration)❌ No✅ Yes (via Adobe Ad Cloud)❌ No
Cross-Platform Tracking✅ Yes (web, app, and offline)✅ Yes✅ Yes✅ Yes
Privacy Compliance (GDPR/CCPA)✅ Yes (via consent mode & data modeling)✅ Yes (full control over data)✅ Yes (enterprise compliance)✅ Yes (EU-hosted, privacy-first)
Data Ownership & Hosting❌ No (Google-controlled data)✅ Yes (self-hosting available)❌ No (Adobe-controlled data)✅ Yes (private cloud or on-premises)
Ease of Use✅ High (Google ecosystem integration)✅ Moderate (requires setup)❌ Complex (enterprise-focused)✅ Moderate (user-friendly)
Best for Magento Owners Who...Want a free, widely used tool with Google Ads integrationNeed full data control and privacyRun large-scale enterprises with deep analytics needsPrioritize GDPR compliance and self-hosting options

Key Benefits of Using Google Analytics with Magento 2

  • Customer Insights – GA provides you with detailed data on visitor demographics, shopping behavior, and acquisition channels. Its Google Ads integration enables precise retargeting strategies.
  • Performance Monitoring – With real-time tracking and custom dashboards, GA helps you analyze bounce rates, high-traffic pages, and conversion rates for quick optimization.
  • Marketing Optimization – GA offers multi-touch attribution models, letting you track Magento SEO, paid ads, and email campaigns in a unified view to improve ROI.
  • E-commerce Tracking – GA’s Enhanced Ecommerce feature provides insights into cart abandonment, checkout funnels, and product performance.

Read More: How E-commerce Can Thrive with Google Analytics 4

Methods for Adding GA4 to Magento 2

There are two primary ways to integrate Google Analytics 4 (GA4) with Magento 2:

For a hassle-free setup, use a GA4 extension with Google Tag Manager (GTM) support, such as Google Analytics 4 with GTM Support. This method simplifies integration, eliminating the need for manual code implementation.

With an extension, you can:

  • Quickly enable GA4 from the Magento backend.
  • Enter your GTM JS and non-JS codes for automatic site-wide tracking.
  • Ensure seamless e-commerce event tracking, such as purchases, product views, and cart actions.

2. Manual Setup of Google Analytics in Magento 2

If you prefer full control over the setup, you can manually integrate Magento 2 and GA4 by adding the Google Tag (gtag.js) to your store’s theme. This method involves editing Magento’s theme files to insert the tracking script, ensuring it loads correctly across all pages. It also requires configuring event tracking to capture key user interactions, so it certainly it takes more effort.

In the next section, we’ll walk you through the process of manually setting up GA4 in Magento 2.

How to Add Google Analytics to Magento 2 Manually: Step-by-Step

Now, let’s explore the steps of manually integrating Google Analytics 4 with Magento 2.

Step 1. Create a New GA Account

Go to Google Analytics. If you're new to Google Analytics, click Start Measuring to begin the setup. If you already have an account, proceed to the next step.

Next, enter a unique Account Name for your Analytics setup and configure your data-sharing settings to manage what information is shared with Google. Click Next to proceed with adding your first property to the account.

How to Add Google Analytics to Magento 2 Manually. Step 1. Create a New GA Account

Step 2. Get Measurement ID for Magento Google Analytics Integration 

To be able to collect statistics, you will need to add a Google Analytics code to Magento 2.
In your GA4 account, go to Admin → Data Streams → Web and copy the Measurement ID (format: G-XXXXXXXXXX).

How to Add Google Analytics to Magento 2 Manually. Step 2. Get Measurement ID for Magento Google Analytics Integration

Step 3. Add Google Analytics API to Magento 2

  1. Log in to your Magento Admin Panel.
  2. Navigate to Stores → Configuration → Sales → Google API.
  3. Expand the Google Analytics section.
  4. Set Enable to Yes.
  5. Enter your Google Analytics Tracking ID (Measurement ID from Step 2).
  6. Click Save Config and clear the cache by going to System → Cache Management and clicking Flush Magento Cache.
How to Add Google Analytics to Magento 2 Manually. Step 3. Add Google Analytics API to Magento 2

Step 4. Set Up Magento 2 Google Analytics Enhanced E-commerce

To get the full potential of Magento 2 Enhanced E-commerce, you need to configure it correctly within your store. 

  1. In your Google Analytics account, go to Admin → Data Streams → Web.
  2. Click on your data stream and toggle on Enhanced Measurement to track e-commerce interactions.
  3. In Magento 2, navigate to Stores → Configuration → Sales → Google API.
  4. Under Google Analytics, set Enable Enhanced E-commerce to Yes.
  5. Click Save Config and clear the cache.

In Magento 2, Google Analytics e-commerce tracking allows you to track important customer interactions, like product views, add-to-cart actions, checkout steps, and purchases, enabling you to gather detailed insights on user behavior and optimize your marketing efforts.

How to Add Google Analytics to Magento 2 Manually. Step 4: Set Up Magento 2 Google Analytics Enhanced E-commerce

Step 5. Check If Everything Works Correctly

In Google Analytics, go to Reports → Realtime and check if data is being recorded. Look for active user data in Google Analytics to confirm tracking is working.

How to Add Google Analytics to Magento 2 Manually. Step 5. Check If Everything Works Correctly

How to Fix the Magento 2 Google Analytics Not Working Issues

If Google Analytics 4 (GA4) isn’t tracking data in your Magento 2 store properly or at all, several common setup mistakes could be the cause. Incorrect configurations, caching issues, or missing consent management can lead to incomplete or missing analytics.

Below are the most frequent mistakes and how to fix them to ensure accurate data collection.

1. Enable Enhanced E-commerce Tracking

Many store owners forget to enable Enhanced E-commerce Tracking in both Google Analytics and Magento 2. Without this, critical data—such as product views, add-to-cart actions, and purchases—won’t be tracked. In GA4, go to Admin → Events and ensure e-commerce tracking is turned on.

If your store serves users in regions with privacy regulations like GDPR or CCPA, you must implement a cookie consent banner to obtain user tracking permissions. Without this, GA4 may block tracking for users who haven’t opted in, leading to incomplete data and potential legal issues.

Read More: Setting Up Google Consent Mode in Magento 2

3. Use the Correct Measurement ID

GA4 uses a Measurement ID (G-XXXXXXXXXX) instead of the older UA-XXXXXXXX-X format from Universal Analytics. Ensure you copy the correct G- ID from Admin → Data Streams and paste it into Magento’s Google API settings under Stores → Configuration → Sales → Google API.

4. Clear Magento Cache After Setup

Magento relies heavily on cached settings, meaning any changes to the Google API settings may not take effect immediately. Always flush the cache by navigating to System → Cache Management → Flush Magento Cache after making updates.

5. Verify Data Collection

Many merchants assume tracking is working without testing. Always verify by:

  • Opening your site in incognito mode and checking Reports → Realtime in GA4.
  • Using Google Tag Assistant or Google Analytics Debugger to detect missing or duplicate tags.
  • Checking Admin → DebugView in GA4 to confirm events are firing correctly.

Many merchants forget to link GA4 to Google Ads and Search Console, missing out on cross-channel insights. Go to Admin → Property Settings → Linked Accounts to ensure these integrations are active for better ad tracking and SEO reporting.

7. Fix Duplicate Tag Issues

If you use multiple tracking methods (e.g., a GA4 module + Google Tag Manager), you may / duplicate events, inflating data like session counts and conversions. Use Tag Assistant to detect redundant tracking codes.

Common Mistakes to Avoid When Setting Up GA4 in Magento 2

Setting up GA4 in Magento 2 can be complex, and even small errors can lead to missing or inaccurate data. Here are some additional pitfalls to watch out for:

  • Incorrect Event Tracking Configuration – Custom events must be properly set up in GA4 to track actions like checkout steps, product clicks, and form submissions. Misconfigured or missing events can result in gaps in analytics.
  • Misplaced Tracking Code – Adding the GA4 tracking code in the wrong location (e.g., not in the global header) can prevent it from firing on all pages.
  • Ignoring Server-Side Tracking – Relying solely on client-side tracking can lead to data loss due to ad blockers or browser privacy settings. Server-side tagging can improve accuracy.
  • Failing to Define Conversions – Without marking key actions as conversions in GA4, you won’t be able to measure business-critical metrics like completed purchases or sign-ups.
  • Overlooking Data Retention Settings – GA4 defaults to a two-month data retention period. Extending this to 14 months in Admin → Data Settings ensures long-term access to user behavior insights.

Address these issues to maximize the accuracy of your GA4 tracking in Magento 2 and make better data-driven decisions.

Additional Magento Analytics Solutions

While Google Analytics is a powerful tool, setting it up and interpreting data can be complex. To simplify data-driven decision-making, Magento 2 offers built-in reporting tools, and Amasty’s specialized extensions provide advanced analytics to help merchants track key metrics effortlessly.

Advanced Reports for Magento 2

For merchants looking to gain deeper insights without relying solely on Google Analytics, Advanced Reports for Magento 2 provides a structured, easy-to-use reporting system. It includes 15 detailed report types grouped into three key categories:

  • Sales Reports – Analyze critical performance indicators such as revenue, order volume, best-selling products, and customer purchasing behavior. Track sales trends by date, product, category, or even order status to identify what drives profitability.
  • Catalog Reports – Gain visibility into product performance, including views, purchases, and stock levels. Understand which items are driving conversions and which may need pricing or promotional adjustments.
  • Customer Reports – Get insights into customer retention and engagement, including new vs. returning customer behavior. Learn how repeat buyers contribute to revenue and identify opportunities for loyalty programs or targeted marketing campaigns.

advanced reports for Magento 2

With real-time data visualization and customizable filters, this extension helps merchants forecast trends, make informed business decisions, and refine their marketing strategies without requiring in-depth knowledge of Google Analytics.

Read More: Magento Advanced Reports – Analytics for Everyone

Advanced Search and Elastic Search for Magento 2 offer valuable analytics through a Search Analytics Dashboard. They help track:

  • Total and Unique Searches – Understand the volume and variety of search queries.
  • User Engagement – Measure how users interact with the search feature.
  • Search Patterns – Identify popular products or categories that may be out of stock.

If customers search for products you don’t have, it’s an opportunity to adjust inventory and restock based on demand.

search analytics elastic for Magento 2

Advanced Search vs. Elastic Search

While both extensions provide powerful search analytics, they differ in the search engine they use:

  • Advanced Search uses Magento MySQL for basic search functionality.
  • Elastic Search leverages Elasticsearch for faster, more advanced features like autocomplete and spell correction.

Elastic Search is ideal for larger stores or complex catalogs, while Advanced Search works well for smaller stores.

Reward Points

A loyalty program is only as effective as the data behind it. Reward Points for Magento 2 not only helps you implement a points-based rewards system but also provides key insights into customer engagement and program effectiveness.

With built-in analytics, you can track:

  • Total points awarded – Understand which promotions or purchase behaviors lead to the most points earned.
  • Points redemption trends – See how frequently customers use their points, indicating how engaged they are with the program.
  • Expired points and customer inactivity – Identify areas where adjustments may be needed, such as better incentives to encourage participation.

 

reward points for Magento 2

Analyzing these insights, you can optimize reward structures, tailor marketing efforts, and increase customer lifetime value through effective loyalty strategies.

Out-of-Stock Notification

Stock availability plays a significant role in conversions and customer satisfaction. Out of Stock Notification for Magento 2 helps you anticipate demand and prevent lost sales by tracking real-time customer interest in unavailable products.

Key data insights from this extension include:

  • Back-in-stock request volume – Measure demand for out-of-stock products to prioritize restocking based on actual customer interest.
  • Notification effectiveness – Track how many customers return to purchase after receiving a restock alert.
  • Purchase completion rates – Identify which products generate the most sales after being restocked.

out of stock for Magento 2

With these insights, merchants can adjust inventory planning, optimize purchasing strategies, and create targeted promotions around high-demand products.

Turn Your Magento Data into Actionable Strategies!

Collecting data is only the first step – the real value comes from using insights to refine your strategy. We hope that this guide has helped you set up Google Analytics in Magento 2 and explore alternative data collection methods. 

Have questions? Drop them in the comments below – we’re here to help!

June 13, 2019
June 19, 2019
May 29, 2019
Comments
Guest
October 29, 2019
0.5
Reply
Ujsh
March 1, 2022
Great Article. On the GOOGLE API section, even after enabling the store view, the ACCOUNT TYPE option is not visible. Can you help what could be the reason behind it?
Reply
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro

Loading