diff --git a/google_analytics/templates/google_analytics/analytics_template.html b/google_analytics/templates/google_analytics/analytics_template.html index 4bf6b69..4cf0288 100644 --- a/google_analytics/templates/google_analytics/analytics_template.html +++ b/google_analytics/templates/google_analytics/analytics_template.html @@ -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); })(); \ No newline at end of file