How to add Google Analytics 4 (GA4) to Magento 2?

Loading...
Back to Blog
How to add Google Analytics 4 (GA4) to Magento 2?

The eCommerce world was recently taken aback by an announcement made by Google mentioning they would retire the beloved and widely-used Google Analytics Universal Analytics solution. Starting July 1st, 2023, standard Universal Analytics properties will no longer be collecting data and this is huge news because, especially in the eCommerce industry, the difference between having and not having relevant data translates directly into sales.

Google Analytics is, without a doubt, one of the most widely used tracking tools on the market and with it, you can collect data that'll help you make relevant decisions in order to grow your business. A basic implementation of Google Analytics is sufficient to track key metrics about website traffic and visitors such as Page Views, Bounce Rates, Session Times, Traffic Sources, things they search for, and many more! There's also real-time tracking that lets you see how many visitors are on your website at a given time, where they're from, and what they're currently browsing which means you're permanently in the loop with regards to website performance.

While these basic metrics are relevant to any website, eCommerce stores can take it a step further with Enhanced eCommerce Reporting, which opens up a whole new dimension to tracking with Google Analytics, unlocking other important metrics such as Conversion Rate, Product List Views, Checkout Step Drop-off, Per-Product Performance, Measurement of Cart Events, etc.

The ability to perform A/B testing is also a neat feature that can help you gauge which version of your content caters best to your users. Google has removed the option to enable content experiments, however, but has replaced it with Google Optimize, which offers similar functionality.

There's no question about it, Universal Analytics has been an awesome and must-have tool with many benefits for any website, so why is it going away? The answer is simple: it's getting an upgrade! Universal Analytics is being retired to make room for Google Analytics 4 (GA4).

Google Analytics Universal Analytics Dashboard

What is Google Analytics 4 (GA4)?

Google Analytics 4 is a new type of privacy-first property, self-described by Google to be their next-generation measurement solution. It builds and improves upon previous Universal Analytics properties with a privacy-oriented and future-proof approach. It also features comprehensive and deep integrations with Google's advertising platforms and employs machine learning to bolster insights about the user journey across various platforms and devices.

Google Analytics 4, through its use of Google's advanced machine learning algorithms, can observe and analyze significant trends in your website data, such as a specific product or product type growing in sales due to increased demand, enabling it to automatically alert and make you aware of these trends, thereby letting you make data-driven decisions to benefit your business. Moreover, the enhanced capabilities that machine learning provides enable Google Analytics 4 to fill in the significant gaps in data that may be present due to software that blocks tracking scripts, cookie consent rules, and other privacy-related options or configurations, thereby making the data collected much more relevant.

The new Google Analytics 4 platform is built upon the foundation of the Web + App property that Google beta-tested back in 2019, meaning that it centralizes the traffic and data from the web as well as mobile apps. In short, if your brand has a mobile app, you no longer need to separate your data between two platforms (Google Analytics for Firebase in the case of mobile apps and Google Analytics for standard web traffic), as Google Analytics 4 provides a unified picture for both data streams.

Google Analytics 4 Dashboard

Why should I switch from Universal Analytics to Google Analytics 4?

Since Universal Analytics is being retired in 2023, if you're already using Universal Analytics, you may be wondering why you should take the time to switch over to a Google Analytics 4 property. There are a few reasons for this, but it's also important to note that this doesn't mean you need to shut down your existing Universal Analytics property, as they can still be run in parallel. Here are the main reasons you should set up a Google Analytics 4 property as soon as you can:

  1. You'll get a head start on the competition - making use of Google's advanced machine learning models will ensure the data you collect is more relevant. It can also help you predict trends sooner so you can seize business opportunities ahead of your competitors.

  2. You'll start building historic data - having historic data in the new platform is a surefire way to ensure you can keep making data-driven decisions for your business moving forward, while the competition is still wasting time building their data on other platforms.

  3. You'll give the AI time to learn your business patterns - AI needs time to look at patterns and learn from them, which means that the earlier you start, the smarter it'll be! Since it can make assumptions based on existing data, the more data you have, the more accurate it'll be.

Since running a website efficiently isn't possible without relevant data, it becomes a no-brainer that implementing a solution such as Google Analytics 4 and giving it the time to learn your business is paramount and the sooner you do it, the better!

Is Google Analytics 4 right for my business?

Whether you run a blog, a store, a social network, or any other website type, having relevant data about your visitors is crucial to running it properly, regardless of business size, especially considering the fact that more and more businesses are shifting towards the online environment, resulting in more competition.

All you need to do is configure Google Analytics and you'll be ready to start collecting the information its AI requires to help you make sure your website thrives.

Analytics on paper

Tagging your Magento store with Google Analytics 4

Integrating Google Analytics 4 with an online store in order to get some basic tracking set up is quite simple. Let's explore all the settings and configuration steps required to implement basic Google Analytics tracking on your Magento 2 store:

Note: This guide assumes you already have a Google Analytics account and have accepted the Google Analytics terms

Creating a Google Analytics property

The first part of the configuration involves creating a new Google Analytics 4 property and setting it up, so let's see how to do that.

  1. Log in to your Google Analytics dashboard using a Gmail Account and click the settings cog to open up the Account Settings.

    Google Analytics 4 Create New Property
  2. In the Property section, click Create Property. The default property created is now Google Analytics 4, so input your Property Name, Reporting Time Zone, and Currency and then click Next.

    Google Analytics 4 Configure Property
  3. Optionally, you can share some data about your company with Google so they can tailor your experience. Check what you want here and click Create.

    Google Analytics 4 Add Company Info

Note: You can still create a Universal Analytics property by using the Advanced Options in the property creation procedure, however, as Universal Analytics will be decommissioned, it's not recommended.

Setting up a Data Stream and getting the Measurement ID

Now that the property is created, we'll need to get the Global Site Tag to add to our store.

  1. The next step is to set up a Data Stream, which represents the channel through which data is collected. Since we're setting up tracking for an online store, select Web in the Choose a Platform section.

    Google Analytics 4 Data Stream Selection
  2. A window will now display in which we'll be setting up our data stream and getting our Measurement ID so input your Website URL and choose a name for your stream. In the Enhanced Measurement section, you can see what kind of basic tracking and insights you'll be getting with this implementation. If you click the settings cog, you'll be able to read more about the events captured and disable those if you wish.

    Google Analytics 4 Data Stream Configuration
  3. Click the Create button and the Web Steam Details window will pop up. Over here, you'll see your Measurement ID and you'll be able to find the tagging instructions to add the Tracking ID to your store.

    Google Analytics 4 Data Stream Details
  4. In the Tagging Instructions tab, expand the Add new On-Page Tag section and copy the Global Site Tag script displayed here.

    Google Analytics 4 Tagging Instructions

Setting up the Global Site Tag in Magento 2

Since we now have the Google Analytics 4 Global Site Tag, we're ready to head into our Magento Admin section and add it to the website.

Note: This won't require any code modifications or static content deployments via the Command Line, so you won't need a developer for this!

  1. Log in to the Magento Admin and head into Content -> Design -> Configuration.

    Magento 2 Design Configuration
  2. Choose the Magento 2 Store-View you'd like to add the Google Analytics Code (Global Site Tag) to and click the Edit button.

    Magento 2 Store-View Settings
  3. Expand the HTML Head section and paste the Google Analytics Code into the Scripts and Stylesheets section.

    Magento 2 Scripts and Stylesheets
  4. Click the Save Config button and head into the Cache Management section of the Magento 2 Admin by clicking System and navigating to Tools -> Cache Management.

    Magento 2 Cache Management
  5. Click the Flush Magento Cache button and reload the front end of your Magento 2 store.

Your Magento store should now be tagged with the Google Analytics 4 tracking code, so it's time to go ahead and confirm that. There are multiple ways to do this, so let's see a simpler one first, and then we can check out a more advanced method.

Note: This can also be done via the Enable Google API option in Magento, however, this method is even simpler!

Verifying the Magento 2 store is tagged by inspecting the Source Code

The simplest method of making sure the store is properly tagged with the Google Analytics 4 Google Analytics code is to inspect the source of one of your pages.

To do this, simply right-click one of the pages on the front end of the store and click View Page Source.

Magento 2 View Page Source

Inside the tag, you should see the Tracking ID (Global Site Tag) we inserted into the Scripts and Stylesheets section of the Magento Admin, similar to this example:

Magento 2 Page Source

If you don't see the Tracking ID, the store's cache may not have cleared successfully or you may be using a CDN (for example, Cloudflare), from which you'll also need to purge the cache.

Verifying the Magento 2 store is tagged by using the Tag Assistant extension

Another way of verifying the Magento 2 store is properly tagged with the Google Analytics 4 Tracking ID is to use the Tag Assistant browser extension, which will scan the store and output the Google Analytics (and Google Tag Manager, if you're using it) Tags present on the store.

The Tag Assistant extension has many advanced options and debugging capabilities but, for the purpose of this guide, we'll just be using it to confirm that the Google Analytics 4 Tag is present.

To start, if you don't already have the extension, you can add it to Chrome by installing it from the extension store. Once you have it installed, find it in your browser extension list, click on it and click Enable.

Magento 2 Enable Tag Assistant

Afterward, reload the page, click the extension again and you should see the Google Analytics 4 Global Site Tag in the Result of Tag Analysis section.

Magento 2 Tag Assistant Enabled

What's great about Tag Assistant is that, if you're running Google Tag Manager, you can get a lot of neat information about your Google Tag Manager (GTM) Container, such as the Container ID, Account ID, and more information about the GTM Tags.

Note: The Tag Assistant is a legacy extension and you can get more advanced debugging via the Google Tag Manager Preview Mode.

Verifying Real-Time data in Google Analytics 4

Now that we've confirmed the Google Analytics 4 Global Site Tag is present on the store, we can go ahead and make sure the Real-Time data is making it into our Google Analytics 4 property so we can start collecting data about customers' behavior!

  1. To start, log back into your Google Analytics account and make sure the Google Analytics property we created before is selected.

    Google Analytics 4 Dashboard Realtime
  2. Use the menu on the left-hand side to navigate to Home. You won't see much data here yet, as it can take around 24-48 hours for reports to start being built based on the data that flows in. However, you can click the View Realtime link and you should see the current visitors present on the store here, including yourself.

    Google Analytics 4 Real Time Statistics

The information you'll see here, as well as in other sections of the Google Analytics account will be limited to the basic info that the property is collecting, however, it should be enough for you to get a feel for what visitors are doing on your Magento 2 store!

Enhanced eCommerce implementation for Magento 2 via Google Tag Manager

By following the guide above, you'll have implemented a simple Google Analytics 4 tracking integration for your Magento 2 store which will measure the following:

  • Page views

  • Scrolls

  • Site search

  • Outbound clicks

  • Video engagement

  • File downloads

These are all great metrics to have, however, most eCommerce stores using Magento 2 will require more specific and specialized information about their users and products that can help build strategies and steer decisions that'll ensure they stay competitive. These metrics fall under the Enhanced eCommerce category and include things like:

  • Conversion rate

  • Revenue (as well as per-product performance)

  • Product detail metrics

  • Checkout steps (billing step, shipping step, payment step)

  • Checkout step drop-off

  • Product impressions (by position on the Category Page, by position on the Search Page)

  • Product clicks (by position on the Category Page, by position on the Search Page)

  • Cart actions (additions, removals)

  • Coupon code usage

  • Promotional material impressions and clicks

Note: These are just a few of the Enhanced eCommerce metrics you can implement, and there are many others!

Using Magento 2 Enhanced eCommerce Extensions to add Google Analytics 4 tracking via Google Tag Manager

There are multiple ways of implementing Enhanced eCommerce tracking and one of those is via Google Tag Manager. While we won't go through the process of doing so in this guide, for Magento 2 specifically, the implementation be significantly simplified by using an extension that's built for this specific purpose.

There are many such extensions available that are very well-documented and can help you set up Google Analytics 4 tracking via Google Tag Manager in a matter of minutes.

The WeltPixel Google Analytics 4 with Google Tag Manager Support for Magento 2 extension

Among the best extensions is our very own WeltPixel Google Analytics 4 (GA4) with Google Tag Manager Support for Magento 2 extension is built for this specific purpose!

WeltPixel Google Analytics 4 GA4

How does the Google Analytics 4 (GA4) extension for Magento 2 work?

This Enhanced eCommerce extension takes mere minutes to set up and facilitates full integration of your Magento 2 store with the Google Analytics 4 platform, as well as with Google Adwords (Google Ads). The module features an easy configuration with a fully-documented step-by-step guide. All you need to do is install the extension, follow the configuration steps to create a JSON file containing all the new Tags, Triggers, and Variables, import it into Google Tag Manager (where you can overwrite or merge with the old tags), save config and you're ready to go, no code modifications needed!

The extension will start sending Enhanced eCommerce data to Google Analytics 4 via the data layer and start getting measuring the events that really matter for your Magento 2 store so you can get the proper insights to run your business!

Where can I get the Google Analytics 4 (GA4) extension for Magento 2 extension?

You can always find the latest version of the Google Analytics 4 (GA4) for Magento 2 extension on weltpixel.com, along with the full documentation, specifically tailored for the Magento 2 platform. You'll also be able to find a multitude of other Magento 2 extensions, as well as one of the best custom Magento themes, the Pearl Theme for Magento 2!

In the documentation, you'll also find a section that explains how to use the Google Tag Manager Preview Mode to view all the events and debug the data layer to make sure all the information is being sent properly.

Google Tag Manager Preview Mode

Does the extension have Google Adwords (Google Ads) functionality?

It sure does! The process for connecting Magento to Google Ads via the extension can be found in the documentation on the Google Analytics 4 (GA4) for Magento 2 Product Page. Natively, it comes with Adwords Conversion tracking and Adwords Re-marketing tracking, as well as the possibility of sending a custom currency code, which is why it's one of the best extensions available!

WeltPixel Google Analytics 4 Google Ads

Can I still add Google Analytics Universal Analytics to Magento 2?

While Universal Analytics can still be used and will keep collecting data until July 2023, as we've explored here, it's highly recommended you start building your data in Google Analytics 4 as soon as you can!

Related Products