[contact-form-7 id="24078" title="Feedback EN"]

Featured templates

Magento 2.x. How to Integrate Google Analytics

This guide will show you how to integrate the Google Analytics code to your Magento 2 store.

In order to add the Google Analytics code, you should perform the following:

  1. The first step is locating your account ID in Google. You will first need to obtain your tracking code from the Google Analytics account by following this detailed tutorial.

  2. You should get the code similar to the one, presented below:

    <script type="text/javascript">   
    	var _gaq = _gaq || [];    
    	_gaq.push(['_setAccount', 'UA-12345-6']);    
    	_gaq.push(['_trackPageview']);      
    
    	(function() {      
    	var ga = document.createElement('script');  ga.type = 'text/javascript'; ga.async = true;      
    	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';      
    	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);   
    	})(); 
    </script>
  3. UA-XXXXX-X‘ in your code ( where 12345-6 stands for your Account ID number) is your Google Account ID.

  4. Log into your Magento Admin Area and navigate to Stores -> Configuration section.

  5. Access the Sales -> Google API section and expand the Google Analytics option.

    Magento_2.x._How_to_Integrate_Google_Analytics_code1

  6. Enable it and paste the tracking code to the Account Number field. Next, click on the Save Config button to apply the changes.

    Magento_2.x._How_to_Integrate_Google_Analytics_code2

This is the end of the tutorial. Feel free to check the detailed video tutorial below:

Magento 2.x. How to Integrate Google Analytics