How to Add Google Analytics in Magento 2: Complete Tutorial

Google Analytics has the ability to statistic of customer activity on your website. It used to track website activity such as session duration, pages per session, bounce rate, etc. of individuals using the site, along with the information on the source of the traffic. With the above features, I think it is very useful for the Magento store owner. In this article, I will introduce you How to Add Google Analytics in Magento 2.

With other CMS, to use Google Analytics, you need to install additional Extensions or Modules. As for Magento, Google Analytics is available by default without any additional installation.

Does Magento 2 Support Google Analytics 4?

Yes, you can add Google Analytics 4 to Magento 2.

You can easily create segment-based events and monitor important user interactions across all devices and platforms directly in the GA4 dashboard. 

Both the platforms work smoothly with each other. 

Options to Add Google Analytics to Magento 2

You can set up Magento 2 Google Analytics 4 in two ways:

  • Use a ready-made extension: One of the easiest ways to add GA4 into your Magento 2 store with all ecommerce events; all you need to do is install the Magento 2 extension and configure it in your store in just a few steps. 
  • Manual integration through Magento’s built-in Google Analytics settings: You will need to manually add the GA4 tracking code and set ecommerce tracking events yourself, which might require technical support. 

I will cover both methods for you, and then you can decide which one to opt for. 

How to Add Google Analytics in Magento 2

Method 1: Set up Google Analytics 4 in Magento Using Extension (Easy Method)

Using the extension, you only need to follow four simple steps to get GA4 up and running in your store. You will first need to configure the extension, then generate JSON and upload them to GTM. 

The process is much simpler and straightforward without the need for any technical understanding. 

 Before you start setting up, make sure you have these two things in place:

  • GA4 Property for Your Store
  • Google Tag Manager (GTM) account 

Now, with this, let’s jump into the steps. 

Step 1: Install Magento 2 GA4 Extension

First, you need to install a GA4 module into your store. We recommend using Magento 2 Google Analytics 4 by Meetanshi. It offers an easy way to set up Google Analytics tracking and has all the necessary e-commerce events in-built.

Once the extension is installed, head to Stores > Configuration > Meetanshi > GA4 to configure it.

Step 2: Enter GTM Codes into Magento 2

In the extension configuration, enable the module and enter the JS and Non-JS code from your GTM account. You can get these codes from your GTM account > Account > Container > Admin > Install Google Tag Manager section.

Step 3: Configure Tracking Preferences & Generate JSON for Tags

In the configuration, set your data tracking preferences.

Here, you can select the attribute for product identifier, enable or disable brand tracking, variants tracking, set custom success path, etc.

You can also set your preferences for tracking revenue calculation and choose between child and parent products.

Once your preferences are set, head to Google Tag Manager, and copy the Public ID and paste it into the Magento 2 GA4 extension configuration.

Click the “Save” button at the top-right.

Finally, generate and download the GTM JSON file from the extension interface.

Step 4: Upload JSON File to GTM

Now, it is time to add the downloaded JSON file into GTM. Head to Google Tag Manager and go to Admin > Import Container.

Select the Import Container option from the right side and upload the JSON file.

Finally, click “Confirm” to create a container and then publish it.

That’s it. You’ve successfully added Google Analytics 4 to Magento 2 store. The GA4 report will start showing real-time data in the store.

Method 2: Manual Method to Add Google Analytics to Magento 2

Step 1: Log in to Magento Admin Panel with Admin account.

Dashboard

Step 2: On the menu bar, select STORES, then select Configuration in Settings section.

Stores Configuration in Settings section

Step 3: In the Configuration panel, select SALES, click Google API.

In the Configuration panel, select SALES, click Google API.

Step 4: Under Enable, select Yes.

Under Type, select Google Analytics.

For Account Number, enter your Google Analytics tracking ID. (If you don’t have a Google Analytics account, you can sign up at http://www.google.com/analytics/)

Item Enable IP anonymization:

  • Select Yes: anonymous IP visitors.
  • Select No: monitor visitors’ IP.
Enable Google Analytics

In Magento 2, you can also connect your GA4 account and start basic tracking.

Enable the Google Analytics 4 under Google GTag as shown below and enter your measurement ID. (You can get the measurement ID from Data Streams in your Google Analytics 4)

Step 5: Click Save Config.

That’s it – you’ve successfully connected Google Analytics 4 to Magento 2 store. Please note that this method offers basic analytics setup. You may not be able to track events like item product view, add to cart, purchases using it.

Note: After installation is complete, it takes up to about 24 hours for Google Analytics to work on your Magento site.

Tips for Effective GA4 E-commerce Tracking

After you have successfully added GA4 and you get into the GA4 dashboard, it can feel a little overwhelming as there is so much to do with multiple options available. 

Here are a few tips that will help you get started the right way: 

  • Start with a clear idea of what you want to track (clicks on products, product views, etc) and only focus on those metrics first. 
  • Look at your traffic sources, which will help you understand how your visitors are getting into your store, and you can optimize the platform accordingly. 
  • Find and create customized reports you need in GA4. You don’t need to stick to the default reporting, which you generally get; you can go ahead and make a report with your preferred metrics.

Good luck!

It comes to the end of tutorial: How to Add Google Analytics in Magento 2.

Follow us for more helpful tutorials!

We hope this is useful blog for you.

Thank you for reading!

4.8 4 votes
Article Rating

Adam Roger

CEO and Founder of Magetop. A friend, a husband and a dad of two children. Adam loves to travel to experience new cultures and discover what is happening with ecommerce all around the world.

Leave a Reply or put your Question here

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x