How to add Google Analytics code in Magento 2
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 your 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.
Add Google Analytics in Magento 2
- Create an Account on Google Analytics
- Configure Google Analytics in Magento 2
- Enable Ecommerce Tracking
Create an Account on Google Analytics
First, login to your Gmail account and search for Google Analytics. Now click on Analytics from the top corner of the page.
Just click on Sign Up.
Now enter the details of your store (Account Name, Website Name, and Website URL) and click on Get Tracking ID.
Now read the Google Analytics Terms of Service Agreement and then just click on I Accept.
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.
Now you will be redirected to the Tracking ID page. Copy the Tracking ID which you have to use in the configuration step.
Configure Google Analytics in Magento 2
Log in to the Admin panel of your store and go to
Stores → Configuration.
Scroll down the configuration page and click on Google API under the SALES tab.
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.
Enable Ecommerce Tracking
To enable ecommerce tracking, click on Ecommecre Settings from the Admin area of Google Analytics.
Enable Ecommerce and Enhanced Ecommerce Reporting and click on Submit.
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:
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 Google Tag Manager Extension (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!
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.