It looks like this code is causing a timing problem. At what point after the execution of this script will ga.js run? How can we be sure that ga.js has executed if it's injected in this manner? (Another component depends on it)
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
I know this doesn't strictly answer your question about document.write but it should solve your problem.
ga.js is designed to be used asynchronously. You should be able to do something like this:
var _gaq = _gaq || [];
_gaq.push(function(){
// Use _gat here freely
});
The function pushed into _gaq will be processed once ga.js is loaded.
Also it seems like you are using a fairly old version of this code. The newer version doesn't use document.write.
(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);
})();
If you decide to update your analytics tracking code, I'd recommend you jumping straight to Universal Analytics, that uses a different file called analytics.js instead.