How to Set Up Magento 2 GA4 (Google Analytics 4) Using GTM

Google Analytics 4 is the most advanced version of the web analytics tool offered by Google. Integrating Google Analytics 4 with Magento 2 is important for you to collect more detailed and meaningful insights about the visitors and their behavior.

The advanced version of Google Analytics brings additional complexity along with the advanced reporting abilities, making it difficult for the online store owners to use it with their website. Here’s how you can setup Magento 2 GA4 (Google Analytics 4) using GTM.

Jump to…

Why Integrate Google Analytics 4 with Magento 2?

Web analytics is at the core of online businesses for driving data-driven decisions for molding a better business strategy. Google Analytics is one of the most famous web analytics tools used by websites to analyze traffic, its sources, visitors, their behavior, and much more.

In October 2020, Google launched the most advanced version of its analytics tool — Google Analytics 4 (GA4). According to Google, the older version, i.e. Google Analytics Universal, which supported only the web channel, will stop processing data from July 1, 2023, onwards. Therefore, the website owners must switch to the latest version of the analytics tool and get accustomed to it before the older version stops working.

The Google Analytics 4 is the most advanced version of the free web analytics tool by Google. Unlike the Google Analytics Universal, GA 4 unifies the data from the web and mobile app channels and streamlines the data reporting and analytics for the store owners. It allows the eCommerce store owners to track every specific event in their online stores, resulting in more specific and actionable data.

Google Analytics 4 relies on user and event-based tracking rather than session-based tracking, which allows gathering. The advanced analytics tool by Google is built to meet challenges faced by businesses to understand the complexity of user behavior across the platforms.

Benefits of Setting Up Google Analytics 4 with Magento 2

For online businesses, data means everything. The latest incarnation of the Google Analytics tool allows online businesses to peek into the customer’s journey and collect actionable data. The Magento 2 Google Analytics 4 integration can benefit the store owners in several ways. Some of the core features and benefits are listed below.

  • Detailed Data Reporting & Analysis
  • Enhanced Tracking of Customer’s Journey
  • Better Analysis of Visitor Engagement
  • Easy-to-Setup Goals
  • Unified Web & App Analytics
  • Enhanced Visualization & Tracking
  • Custom Event Creation & Tracking

Finally, let’s begin with the main part!

Here is a step-wise tutorial to setup Magento 2-GA4-Google Analytics 4 using GTM.

How to Set Up Magento 2 Google Analytics 4

Adding Google Analytics code to Magento 2 was easier, but it is not the same with Google Analytics 4. It is a bit complex and requires manual event creation. Our Magento 2 Google Analytics 4 Using GTM extension makes it easier for the store owners to set up Magento 2 GA4 using GTM. In this tutorial, we will be using the extension to connect Magento 2 store with Google Analytics 4. We have developed the extension to make the complex task easier for the Magento 2 store owners.

Magento 2 Google Analytics 4 Using GTM

The extension makes eCommerce tracking easier for the Magento 2 store owners with built-in Google Analytics 4 events. It takes the complex task of event creation out of the Google Analytics 4, ensuring highly accurate eCommerce tracking for the Magento 2 stores. Once you have installed the extension on your Magento 2 store, you can follow the steps provided below to easily integrate Google Analytics 4 with Magento 2.

Note: We presume that you have already set up your Google Tag Manager account, and it is ready to tag your Magento 2 store.

Let’s begin with the steps to set up Magento 2 GA4 using GTM.

Step 1: Enable the Magento 2 Google Analytics 4 Extension

Once you have the extension installed on your store, log into the admin panel, head to Stores → Configuration → Meetanshi → GA4 and enable the extension.

Enable the Extension to Setup Magento 2-GA4-Google Analytics 4 Using GTM

Step 2: Add Google Tag Manager Code to Magento 2

Open a new tab, log into your Google Tag Manager Account, and go to Account → Container. Select the respective container and move to Admin → Install Google Tag Manager, where you can find the Js and non-Js codes that you need to put into your Magento 2 store.

Install Google Tag Manager - Copy Js and Non-Js Code

Copy the codes from the Google Tag Manager, and paste them into respective fields in the Stores → Configuration → Meetanshi → GA4 configuration. Paste the <head> code into the Google Tag Manager JS Code field and <body> code into the Google Tag Manager Non-JS Code field.

Add Js and Non Js Codes to Magento 2

Once you have entered the Google Tag Manager Codes into the extension, click on the Save Configuration button at the top-right corner to save the progress.

Step 3: Configure Magento 2 Google Analytics 4 Extension

The extension supports tracking built-in eCommerce events in Magento 2. You just need to set respective variables, configure the settings from the backend, and you’re good to go! The Magento 2 Google Analytics 4 configuration part is explained in detail below:

  • Product Identifier: Select the product identifier variable in your Magento 2 store.
  • Enable Product Brand: Select ‘Yes’ if you want to track the product brand variable in Google Analytics 4.
  • Enable Variant: Select ‘Yes’ to track product variants in GA 4.
  • Order Success Page Total Calculation: Choose how you want to calculate the order success page total amount. You can choose from the following options:
    • Grand Total: Calculates the amount with discounts.
    • Sub-Total: Calculates the whole amount without discounts.
  • Exclude Tax From Transaction: Select ‘Yes’ if you want to exclude the tax from the transaction amount in Google Analytics 4.
  • Exclude Shipping From Transaction: Select ‘Yes’ if you want to exclude the shipping from the transaction amount while tracking.
  • Exclude Shipping Including Tax: Select ‘Yes’ if you want to exclude the shipping including tax.
  • Success Page Paths: Enter the success page path, in case of custom checkout pages. You can enter multiple success page paths separated by commas.
  • Exclude Orders with 0 Value: Select ‘Yes’ if you do not want to track orders with zero value, such as free goods, products discounted to zero grandtotal, etc.
  • Measure Product Clicks: Select ‘Yes’ if you want to measure product clicks from various locations in your store.
  • Child Vs Parent: Select whether you want to track the parent product or each of the child products separately.

Configure Magento 2 Google Analytics 4 Extension

Once you are done with the above configuration part, click on ‘Save Config’ button at the top right corner to save the progress.

Step 4: Magento 2 Google Tag Manager API Configuration

After the configuration part, it is time to configure the GTM API with the Magento 2 extension. You need to get the account ID and container ID from the GTM account and enter them into the extension.

Log into your Google Tag Manager Account, and go to Account → Container → Workspace. The URL of the Workspace will contain the account ID after the accounts/ and container ID after the containers/ part. Refer to the following screenshot for a better understanding.

Get Google Tag Manager Account ID and Container ID

Now, in your Magento 2 admin panel, go to Stores → Configuration → Meetanshi → GA4, expand the GTM API Configuration section, and enter the Account ID and Container ID in the respective fields.

Add Account ID and Container ID in Magento 2 Google Analytics 4

You also need to enter the measurement ID into the extension to connect your Magento 2 store with Google Analytics 4. For that, go to Property → View in your GA 4 account, click on Admin under the respective property, and select Data Streams. Select your data stream and copy the measurement ID under the stream details.

Copy Measurement ID from GTM

Now, go back to your Magento 2 admin panel, and paste the measurement ID in the respective field under the GTM API configuration section.

Add Measurement ID in Magento 2 Google Analytics 4

After entering the Account ID, Container ID, and Measurement ID in the GTM API configuration, click on the ‘Save Config’ button at the top-right corner to save the progress.

Step 5: Generate JSON Container File & Import it into Google Tag Manager

Once you have configured everything properly; it is time to export all the configuration from the store and import into GTM via a JSON file. For that, you need the public ID of the Google Tag Manager.

Go to your Google Tag Manager account, select the respective container from the account part, and copy the GTM public ID as shown in the screenshot below.

Copy GTM Public ID

Once you have copied the GTM public ID, go back to your Magento 2 admin panel and paste the public ID in the respective field under the JSON Export Options section. After adding the Public ID, save the configuration, and click on the ‘Generate JSON for GTM – Tags, Triggers and Variables’ button to generate a JSON file.

JSON Export Options

After generating the JSON, click on the ‘Download JSON’ button and download the file, which you have to import into your GTM account.

To import the JSON file containing the tags, triggers, and variables into your GTM account, log into your account, go to Account → Container, select the Admin tab, and click on Import Container. Select the JSON file that you downloaded in the earlier step, and upload it. Choose the workspace accordingly and click on the Confirm button to import the JSON file.

Import JSON File into GTM

After submission, you can also preview all the Tags from the Workspace → Tags section and submit the tags.

Preview Tags from the GTM Account

Click on the ‘Submit’ button for the final submission of the tags, and you are done.

You have successfully connected Google Analytics 4 with your Magento 2 store using Google Tag Manager. Now, you can easily track data in the respective Google Analytics 4 account. Below is the screenshot of a fully working data tracking in Google Analytics 4 of Magento 2 store using this extension.

Magento 2 Data Tracking in Google Analytics 4

Our extension makes the Magento 2 Google Analytics 4 integration easier, faster, and flawless. Setting up eCommerce events in GA4 for Magento is easier than ever with the built-in features.

Check Out Magento 2 Google Analytics 4 Using GTM

Conclusion

Integrating Google Analytics 4 with your store is inevitable to continue collecting worthy data, provided the discontinuation of the Google Analytics Universal from July 1, 2023, onwards. Meetanshi’s extension makes it easier for the store owners to set up Magento 2 Google Analytics 4 using GTM. The setup is easier and seamless with the built-in events that are essential for eCommerce. I hope you’ll find this guide helpful to setup Magento 2-GA4-Google Analytics 4 using GTM.

Magento 2 Google Analytics 4 Using GTM

Google Analytics 4 Using GTM

Our Magento 2 Google Analytics 4 (GA4) extension makes it easier for the admins to integrate GA 4 with their Magento 2 stores using Google Tag Manager.

 

2.7
(based on 84 Reviews)
How to Set Up Magento 2 GA4 (Google Analytics 4) Using GTM

Jaydip Pancholi

Jaydip is a passionate digital marketer at Meetanshi. He is an avid learner who loves learning new skills and marketing strategies. You can find him playing cricket, while not working.

Leave a Reply

Your email address will not be published.