PDA

View Full Version : Google Analytics in Footer


intoys
23-03-09, 17:18
When I try to include my google analytics code in the footer:

<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-7980192-4");
pageTracker._trackPageview();
} catch(err) {}</script>

It will not display my footer at all. When I take it out, it's fine ...

Any help I receive would be greatly appreciated, as I would like to use GA.

IntroSites
23-03-09, 19:41
Put the code between literal tags


{literal}
Analytics code here......
{/literal}


like


{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-7980192-4");
pageTracker._trackPageview();
} catch(err) {}</script>
{/literal}




HTH

intoys
23-03-09, 19:56
Thank you very much!

Worked a treat :)

benfriedman
26-03-09, 12:31
that had been annoying me too! thankyou!

Aspiring Affiliate
18-07-09, 10:55
Thanks introsites, i've been having the same problem!

Andy
18-07-09, 21:56
{literal} is quite powerful.

Sometimes your javascript needs page related data to work (eg: iProductId/sProductName etc)

It is perfectly fine to close literal within the javascript so the variable is parsed, and then open it again for the rest of the javascript, like this snippet Ive taken from a non sw site Im building:


{literal}
<script>

$('#rating_{/literal}{$iProductId}{literal}').text(data)

</script>
{/literal}