Jump to content

Google analytic script in tpl file.


Edge_jr

Recommended Posts

Hi,

 

I want to add google analytic in my website.

 

Therefore I try to add following script in header,footer and js files in theme folder.

 

But it is giving me blank page or smarty error.

 



<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-4127837123-1', 'example.com');
  ga('send', 'pageview');
 
</script>


 

Any Idea?

 

-Thanks

Link to comment
Share on other sites

its because your code use brackets } { 

 

use {literal} {/literal} tags to fix this problem

{literal}
<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-4127837123-1', 'example.com');
  ga('send', 'pageview');
 
</script>
{/literal}
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...