How do I dynamically load Google Analytics JavaScript?
问题 Without using any other JS frameworks (dojo, jquery, etc), how would I dynamically load Google Analytic's javascript to be used on a web page for web-tracking? The typical appropriate to dynamically loading JS is to do the following: var gaJs = document.createElement("script"); gaJs.type = "text/javascript"; gaJs.src = "http://www.google-analytics.com/ga.js"; document.body.appendChild(gaJs); var pageTracker = _gat._getTracker("UA-XXXXXXXXX"); pageTracker._initData(); pageTracker.