Q:

Google analytics - _trackEvent before _setAccount? Does order matter?

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 the visitor can come by a link like http://example.com?autoPlay=Wind? So then the video is already requested, and starts playing, generating:
var _gaq = _gaq || [];
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);

event. But then the regular tracking code still runs at the bottom of the page, that's why 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 have to move at least the _setAccount to the top, or will it just work as it's already in the queue by the time I call ga.js? Or I could just make my own queue... But here I see a clue that they made sure not to delete _gaq if something is already in it even before _setAccount. And also there are multiple trackers for different contexts... So does this mean it's perfectly legal to ignore the order altogether? Sorry for the simple question, but I can found exactly nothing on what is allowed with async and what is not.
Thanks for help!

A:

You've got to have the _setAccount before any commands that log data, like _trackPageview or _trackEvent.
If you look at the tracking pixel that's sent by _trackEvent when _setAccount hasn't run yet, you'll see that it logs to a default account, something like UA-XXXXX-X.
I've used this on development or staging systems where I want the analytics code to run, but don't want it to pollute production tracking data. Comment out the _setAccount line, and all data ends up logged to a non-existent account.

Assuming you never initialized a tracker named 'mumble' (with _gaq.push(['mumble._setAccount', 'UA-65432-1']), the following code shows the ID of an uninitiated tracker is 'UA-XXXXX-X':
echo(_gat.getTrackerByName('mumble')_getAccount())

