How to Add Google Analytics In Magento 2 Stores?

Adding products is not enough for a successful online business. You need to understand your audience.

This is where Magento Google Analytics comes in handy. It is a tool that will help you track users engagement on every page of your store.

How to Add Google Analytics In Magento 2 Stores

We have broken down this article into different subheads that will help you to add Google Analytics in Magento 2.


  1. Create a Google Analytics Account
  2. Get Tracking Code
  3. Configure API in Magento 2
  4. Enable eCommerce Tracking
  5. Check if the Code is Working Properly

Note: If you are still you using Magento 1, we highly recommend you to migrate from Magento 1 to Magento 2.

1. Create a Google Analytics Account

To start with the process, you will have to create an account on Google Analytics.

1.1 Go to their official website. Fill in your Gmail address and password.

1.2 If you don’t have an account. Here’s how to create one:

  • Click on “Create Account“. Fill in the required information.
 Magento 2 Google Analytics
  • Read the Privacy and Terms carefully and click on “I Agree“.
 Magento 2 Google Analytics

1.3 Once you have created your Gmail account you will be redirected to Google Analytics.

1.4 Click on “Sign Up” to start using Google Analytics.

 Magento 2 Google Analytics

1.5 Carefully fill in all the details about your website. Enter your account and website name, website URL, industry category, and reporting time zone.

 Magento 2 Google Analytics

1.6 Click on “Get Tracking ID” button.

Note: Before starting to fill the information make sure you have selected “Website” on top.

2. Get Tracking Code

On your Google Analytics dashboard, you will see a gear icon on the bottom left corner. This is called an Admin tab.

2.1 Click on Admin tab > Tracking Info > Tracking Code.

 Magento 2 Google Analytics

2.2 Copy this tracking ID. You will have to paste this to your Magento backend.

3. Add Google Analytics Code in Magento Store

3.1 Login to your admin panel.

3.2 Click on Stores > Configuration from the left sidebar.

Magento 2 Google Analytics

3.3 In Sales panel, click on Google API.

Magento 2 Google Analytics

3.4 In the field provided for Account Number, enter your Tracking ID.

Magento 2 Google Analytics

3.5 Also, if you wish to render as anonymous part of your visitors’ IP addresses, set Anonymize IP to “Yes.”

3.6 Click on “Save Config” button on the top right corner.

Note: It might take up to 24 hours before your data gets tracked on Google Analytics.

4. Enable eCommerce Tracking

This is an important step. Make sure you have enabled e-commerce tracking in Google Analytics.

4.1 In your Google Analytics Dashboard, go to Admin.

4.2 Under all website data, click on eCommerce settings.

4.3 You will see an on-off button. Click on the button to enable eCommerce and enhanced eCommerce reporting.

Magento 2 Google Analytics

4.5 Click on “Save”

That’s it!

You have complete adding your Google Analytics in Magento store.

5. Check if the Code is Working Properly

To check whether the tracking code is working, simply go to your store frontend and then in another tab, open Google Analytics.

Click on Real-time > Overview.

Magento 2 Google Analytics

If you see one active user right now that means you have successfully integrated Google Analytics in Magento 2.

6. Reasons why your tracking code isn’t working

If in case you don’t see any active users, don’t panic. Maybe your Magento eCommerce tracking code is not working properly. Look for following pointers to make sure there aren’t any mistakes:

6.1 Cross Check your Analytics Code

If you are copying and pasting the code from a doc file, there is a chance you might break the code. Always copy and paste the code directly from Google Analytics account. Also, make sure there aren’t any extra spaces between the letters.

6.2 Check for Google Analytics Filters

In your Analytics account go to Admin > Filters. Review all the filters you have added to your account. There may be a chance that you have excluded your IP address tracking. As a result, you won’t see any real time users from your IP address.

Also, if you have added multiple “Include” filters, that might also affect your tracking data.

6.3 Google Penalties

Google penalties are very common these days. Since you have an eCommerce site, you need to keep a look out for these. If you aren’t using SSL or you have some suspicious content on your website, Google will penalize your site. As a result, you will see a huge drop in traffic which might be confused with Google Analytics not tracking your traffic.

Wrapping Up

Google Analytics is a free service that will prove very useful for your eCommerce website. All you need to do is create an account on Google Analytics and paste the tracking code in your Magento panel.

Once you start getting traffic on your website, record and analyze to better optimize your website experience.

Also, since you are going to track and store users data be sure to make your Magento GDPR complaint.

If you face any problem with enabling Google analytics in Magento store, you can always contact our Magento experts.

Magento Hosting banner

Enquire now and join 1000+ businesses who have blitzscaled their websites by choosing ServerGuy as their hosting partner.

Latest Magento Tips, Guides, & News

Stay updated with new stuff in the Magento ecosystem including exclusive deals, how-to articles, new modules, and more. 100% Magento Goodness, a promise!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

We can help you. Right now.

Fast growing merchants depend ServerGuy for high-performance hosting. Experience counts. Let's get started.

Talk to a sales representative

USA / Worldwide




Core Web Vitals Book COver

Is your website ready for Core Web Vitals?

Take this FREE book with you and optimize your store for speed.

Learn all about new Google new ranking factors and get that top ranking.