SHARE

Step By Step Guide google analytics tracking code in prestashop without module

This is tutorial to how to add google analytics code in your prestashop without using any free module . Prestashop is a free script to create eCommerce websites . Many web developers wants to not to use free module for prestashop .

Because free modules are not 100% safe . To track and analyses web activity google analytics code is required . You can add analytics code in header.tpl file in your current theme .

header.tpl file example in prestashop
header.tpl file example in prestashop

To add code login to cPanel and go to file manager . Go to your prestashop installation folder . Locate folder name “Themes”  and open it . Click on prestashop current theme folder .

Go To header.tpl in themes folder

Locate header.tpl file and code edit by right click on it . In next step login to your google analytics account and get analytics code .Read the article to how to get google analytics .Copy analytics code .

Tracking code Example

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-63865007-2', 'auto');
ga('send', 'pageview');
</script>

Paste tracking code after body tag

Paste this code just after  <body> tag . But this code is not working know and you prestashop website is disappeared or not opened . The reason is analytics code is javascript code . And prestashop not allow to run scripts directly from .tpl file .

Add {literal} command

Prestashop have .tpl file . .tpl are smarty files . You cann’t add javascript in smarty files directly . To add javascript in header.tpl , use {literal} code after <script> and {/literal} just before </script> .

Tracking code with {literal} command

<script>
{literal}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-63865007-2', 'auto');
ga('send', 'pageview');
{/literal}
</script>

Save your header.tpl file . Go to your website and refresh your webpage . Know it is working .

Video Help

See the video for detailed help to add tracking code on header.tpl file .

To check that tracking code is working or not check the real time overview in google analytics dashboard .

For help on real time overview read this . If tracking code is working well then stop your own ip tracking by using filter . It is recommended for accurate data analytics .

Reference –