I understand that by simply adding a script to the end of the body tag of a html document one makes it processable by Google analytics. My question is, is this likely to hav
Although downloading and running the actual ga.js is fast, what I've noticed all across Europe, on different connections/computers/OSes/browsers, is a MAJOR lag (anywhere from 0 to 30 (thirty) seconds) between the last byte of HTTP request and first byte of HTTP response.
This is understandable, given the immense popularity of GA, but this is happenning before window.onload fires. So, if your page relies on JS and your users hit this lag, they are not going to analyze which component is responsible - they'll assume your site is horribly slow.
A workaround for this is to register a window.onload function which will add the GA script. Example (using "window.onload=function()
" for simplicity):
window.onload = function() {
var gaJsHost = (("https:" == document.location.protocol)
? "https://ssl."
: "http://www.");
var s = document.createElement('script');
s.src = gaJsHost + "google-analytics.com/ga.js";
s.type='text/javascript';
var bodies = document.getElementsByTagName('body');
if (bodies.length > 0) {
bodies[0].appendChild(s);
} else { // this should never happen, but sometimes does (curse you IE6!)
document.appendChild(s);
}
// this says 100ms, but won't happen until ga.js is loaded
window.setTimeout(function(){
if (window['_gat']) {
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
}
},100);
}
Regarding server load, the scripts are pulled from Google's servers, not yours so there will be no noticeable server side impact. Obviously your pages will all be slightly larger than they were without the code to load the JavaScript, but you'll never notice the difference.
If you add the code to the bottom of the page then it probably won't make much of a difference.
If however, you want it to make no difference then I'd take a look at this link:
http://lyncd.com/2009/03/better-google-analytics-javascript/
It describes the approach that Steve Souders took to completely avoid any kind of I/O block.
Yes it does have a performance hit see http://dotnetperls.com/Content/Google-Analytics-Speed.aspx . To speed up its recomended that you download the ga.js file locally and call that instead,Explained here http://www.askapache.com/javascript/google-analytics-speed-tips.html.
Note too I've seen GA download a little GIF file with a hash attached to it... but I doubt the size of this will have much of an affect on performance.
Yes.
I feel browsing speed is much better since I added google analytics to addblock filter.