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"));
try
{
var pageTracker = _gat._getTracker("UA-XXXXXXX-1");
pageTracker._trackPageview();
}
catch(err) {}
Would it be possible to call this script from an external JS file? I wanted to to something like:
<script type="text/javascript" src="googleanalytics.js" ></script>
and put one of these on each of my HTML pages.
The code I have above will be inside googleanalytics.js
Google's instructions was to put the code in each page. The problem with that is it makes it harder to change the tracking code. (We use different tracking codes for our DEV and PROD pages).
I've tried it out and it doesn't seem to be working.
Is there something wrong with doing that? Or is there something else causing the problem?
Important FYI Please note that we are using IE6 and 8 browsers (yes, I know, no need to tell me)