Jump to content

[Solved] How to insert Google Analytics code to head.tpl


Recommended Posts

I have tried to insert my Google Analytics code to my prestashop.

I have tried to insert the code just before the </head> tag as Google recommends but im getting a smarty error.

How can I insert the code?

[removed]

 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-xxxxxxx-25']);
 _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[removed].insertBefore(ga, s);
 })();

[removed]



I know Prestashop has a Google Analytics module but its not uptodate for 1.3.6 :(

Link to comment
Share on other sites

the reason why your page fails after inserting the javascript is because the code contains the { and the } characters. The head.tpl file is pareses by the Smarty template engine and attempts to interpret all instances of { and }. The way to resolve this is to wrap the inserted javascript code in {literal}{/literal} tags. e.g.

{literal}

       [removed]
         var _gaq = _gaq || [];
         _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
         _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[removed].insertBefore(ga, s);
         })();
       [removed]

{/literal}

Link to comment
Share on other sites

jeckyl im a little affraid installing it. The topic is all in France and im affraid if its ruin my live webshop.


it's just a module, adn if i give out this information it's because i'm using it on my site and it work very well.
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 2 weeks later...
  • 5 months later...

 

it's just a module, adn if i give out this information it's because i'm using it on my site and it work very well.

 

 

Hey Jeckyl... the module you linked to works fine, but it throws up an error on my one page checkout custom form....

 

"GA checkout form tracker is turned on, but pageTracker variable is undefined."

 

any ideas what that is or how it can be fixed? I'm running 1.3.x

Link to comment
Share on other sites

Hi,

 

 

 

Hey Jeckyl... the module you linked to works fine, but it throws up an error on my one page checkout custom form....

 

"GA checkout form tracker is turned on, but pageTracker variable is undefined."

 

any ideas what that is or how it can be fixed? I'm running 1.3.x

This problem is link to your module OPC and not this module of google analytics.

 

See with the developper of your module.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...