So this will work:
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-65432-1']); _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); })(); _gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
But what if a visitor can follow a link, for example http://example.com?autoPlay=Wind ? So, the video has already been requested and starts playing, generating:
var _gaq = _gaq || []; _gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
event. But then the normal tracking code is still executed at the bottom of the page, so we have async for:
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-65432-1']); _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); })();
So do I need to move at least _setAccount to the top of the page, or will it work, as it is already in the queue, by the time I call ga.js ? Or I could just create my own queue ... But here I see a key that they made sure not to delete _gaq if something is already in it before _setAccount . And also there are several trackers for different contexts ... So, this means that it is completely legal to ignore the order at all? Sorry for the simple question, but I cannot find anything in what is allowed with async and what is not.
Thanks for the help!
source share