Monday, May 20, 2024
192
rated 0 times [  193] [ 1]  / answers: 1 / hits: 31973  / 15 Years ago, wed, july 15, 2009, 12:00:00
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)


More From » google-analytics

 Answers
25

Yes this is possible. If it is not working then there is something else going on.



Just a thought, Google Analytics is usually about a day behind in reporting so when you make changes it will take some time before you know it is working. What I like to do is hit a page that does not get traffic very often to assure me that I have my tracking set up correctly.



Also, you might try making the link an absolute link in your <script tag. It might just be looking in the wrong place for the analytics code.


[#99121] Friday, July 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ronaldodarioc

Total Points: 441
Total Questions: 105
Total Answers: 106

Location: Christmas Island
Member since Sun, Mar 7, 2021
3 Years ago
;