Skip to content

Commit

Permalink
Better GA init code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Chris Adams committed Dec 2, 2009
1 parent ff09c68 commit b2b5a7c
Showing 1 changed file with 4 additions and 1 deletion.
Expand Up @@ -7,6 +7,9 @@
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>

0 comments on commit b2b5a7c

Please sign in to comment.