Google Analytics dosent work

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
tobias81
Forum Members
Forum Members
Posts: 29
Joined: Tue Jan 11, 2011 6:09 am

Google Analytics dosent work

Post by tobias81 »

Hi there...
When i want to have google Analytics on my page ive got wrong messege on page:
string(114) "Smarty error: [in tpl_head:43 line 11]: syntax error: unrecognized tag 'var' (Smarty_Compiler.class.php, line 590)"

Here is the code i use in the <head>

Code: Select all

<__script__ type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2422577-4']);
  _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>
What is wrong?
User avatar
M@rtijn
Power Poster
Power Poster
Posts: 706
Joined: Sat Nov 14, 2009 4:54 pm

Re: Google Analytics dosent work

Post by M@rtijn »

You have to wrap your code in {literal} tags

Code: Select all

    <__script__ type="text/javascript">
{literal}
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-2422577-4']);
      _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);
      })();
{/literal}
    </__script>
Make your community a better place!
tobias81
Forum Members
Forum Members
Posts: 29
Joined: Tue Jan 11, 2011 6:09 am

Re: Google Analytics dosent work

Post by tobias81 »

Strange i try it but ive got that "tracking is not applied".
spike
Forum Members
Forum Members
Posts: 153
Joined: Thu Sep 25, 2008 5:02 pm

Re: Google Analytics dosent work

Post by spike »

Hmmmmn,
1). I'd put the whole js deal inside the literal tags ?
2). It can take up to 24 hours and more for GoogleAnalytics to react.
gruss spike
User avatar
map_1961
Power Poster
Power Poster
Posts: 406
Joined: Fri Apr 20, 2007 7:26 pm

Re: Google Analytics dosent work

Post by map_1961 »

Hi.

I did it like this...

Code: Select all

{literal}
<__script__ type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</__script>
<__script__ type=”text/javascript”>
try {
var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
pageTracker._trackPageview();
} catch(err) {}</__script>
{/literal}
<__body>

..and it works fine...

map_1961
Post Reply

Return to “Layout and Design (CSS & HTML)”