Я играл с пользовательскими переменными в Google Analytics и не был уверен, почему на самом деле работает следующее. Почему код отслеживания Google выполняется первым, тем более что он находится внизу страницы?
Оба сценария находятся в самозапускающихся функциях, так как же javascript определяет, какой из них выполнять первым?
// top of the page
<script type="text/javascript">
$(function ()
{
_gaq.push(['_setCustomVar', 1, 'Account', 'PartTime', 1]);
});
</script>
// bottom of the page
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxxx']);
_gaq.push(['_setDomainName', '.xxxxxxxx.com']);
_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>