Forum Moderators: DixonJones

Message Too Old, No Replies

Google analytics - What is the differnece?

Not sure what is different

         

cmendla

3:53 pm on May 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello, I had been working on one of my sites and google analaytics suddenly dropped from about 10 visitors/day to zero. I took a look at the GA code and it showed

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



When I go to the "Get tracking code", the code it gives me is

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'nnnnnnn]);
_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>


I'm just wondering why I am seeing two different versions of the code. I am using Joomla for the site and the code is in the footer.

thanks

chris

penders

11:19 pm on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your top code snippet is the older Google Analytics code that goes before the closing </body> tag (at the end of your page). (I'm assuming the syntax is OK)

The 2nd snippet is the newer asynchronous version (replaces the old code), but should be placed at the end of the </head> section or at the top of the <body>. (The help docs say the end of the </head>, whereas Google Analytics suggests top of the <body> ...?!)

Not sure why the drop in visitors though - both should still work?

However, the asynchronous code does offer some advantages, one being that you are less likely to miss visitor stats when the page only partially loads.

See also this thread:
[webmasterworld.com...]