The official version fails if the document's first child is something
like a comment. This tries to attach to <head> and, if that doesn't
exist, falls back to body.
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
-document.documentElement.firstChild.appendChild(ga);
+
+// Avoid problems if the document doesn't actually contain a HEAD element:
+var container = document.getElementsByTagName("head")[0] || document.body;
+container.appendChild(ga);
})();
</script>
\ No newline at end of file