How to add Google Analytics code to Magento 2?

Summer avatar
Summer Updated: June 01, 2023
The Most Popular Extension Builder for Magento 2

With a big catalog of 234+ extensions for your online store

There are many factors involved in the success of each ecommerce store, and one of the biggest factors is traffic. Hence, it is crucial for store owners to monitor and keep a complete track of traffic on their stores.

Google offers a free service that allows you to track and monitor the traffic and conversion rate in a few clicks. The service goes by the name of Google Analytics. By using it, you can also determine the user engagement on every page of your store which will help you in improving the SEO of Magento store.

Magento is perhaps the best ecommerce platform out there, so today, I’m going to teach you how to add Google Analytics in Magento 2.

If you are using Magento 1.x, then you can check this article: How to add Google Analytics in Magento.


Google Tag Manager

Google Tag Manager for Magento 2

A clear insight into shopping and behavior of customers with 5 advanced reports

Check it out!


How to Add Google Analytics code to Magento 2 store


Google Analytics

Google Analytics PRO for Magento 2

A clear insight into shopping and behavior of customers with 5 advanced reports

Check it out!


Step 1: Create a Google Analytics Account

First, login to your Gmail account and search for Google Analytics. Now click on Analytics from the top corner of the page.

Create an Account on Google Analytics

Just click on Sign Up.

Create an Account on Google Analytics

Now enter the details of your store (Account Name, Website Name, and Website URL) and click on Get Tracking ID.

Create an Account on Google Analytics

Now read the Google Analytics Terms of Service Agreement and then just click on I Accept.

Create an Account on Google Analytics

Step 2: Set up a property in Google Analytics

First of all, you need to create one property in Google Analytics for each website that you want to collect the data for. After creating a property, your Google Analytics ID will be generated for a later setup. Follow this instruction from Google.

set up property in Google Analytics

Now you will be redirected to the Tracking ID page. Copy the Tracking ID which you have to use in the configuration step.

Set up a property in Google Analytics

Step 3: Add Google Analytics code to Magento 2

Log in to the Admin panel of your store and go to Stores → Configuration.

Configure Google Analytics in Magento 2 6

Scroll down the configuration page and click on Google API under the SALES tab.

Configure Google Analytics in Magento 2

Unfold the Google Analytics section, and select Yes from the Enable drop down menu, enter the Tracking ID (which you copied in the first step) in Account Number text field and select Yes from the Enable Content Experiments drop down menu. Now just click on Save Config.

Configure Google Analytics in Magento 2

Step 4: Enable Ecommerce Tracking for Google Analytics

To enable ecommerce tracking, click on Ecommecre Settings from the Admin area of Google Analytics.

Google Analytics Enable Ecommerce Tracking

Enable Ecommerce and Enhanced Ecommerce Reporting and click on Submit.

Google Analytics Enable Ecommerce Tracking 10

And you’re all done! Visit your store and then go to your Google Analytics. You will be able to see the traffic activity on your Magento 2 store:

Google Analytics Enable Ecommerce Tracking11

Final Words

After following this tutorial, you should now be able to add Google Analytics in Magento 2 to monitor your store’s traffic. You can also check out the Google Analytics Extension or Magento 2 Google Tag Manager (Google Analytics included) by Mageplaza if you want more options. If you have any problem or would like to add to the discussion, feel free to use the comment box below!


Google Analytics

Google Analytics PRO for Magento 2

A clear insight into shopping and behavior of customers with 5 advanced reports

Check it out!


Author Bio

Syed Muneeb Ul Hasan is a Magento Developer and Blogger at Magenticians - a platform for Magento Tutorials. He is an expert in PHP and Magento and prefers to educate users in the implementation of Magento. When not working, he loves to play games and watch cricket. You can follow him on Twitter.

Magento Support
& Maintenance Services

Make sure your M2 store is not only in good shape but also thriving with a professional team yet at an affordable price.

Get Started
avada marketing automation
Subscribe

Stay in the know

Get special offers on the latest news from Mageplaza.

Earn $10 in reward now!

Earn $10 in reward now!

comment
iphone
go up