what's the javascript "var _gaq = _gaq || []; " for ?
- by parvas
The Async Tracking in google analytics looks like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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);
})();
About The first line
var _gaq = _gaq || [];
I think it ensures that if _gaq is already defined we should use it otherwise we should an array.
Can anybody explain what this is for ?
Also, does it matter if _gaq gets renamed ?
in other words does google analytics rely on a global object named _gaq ?
Thanks
Parvas