views:

25

answers:

1

The code I have in place is tracking visits from Chrome, Safari, Firefox, Opera Mini, but not IE. I believe the problem to be a matter or loading order, scope, or possibly the code placement. I am currently using the following:

In my example.html:

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="example.js"></script>

In my example.js:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-########-1']);
_gaq.push(['_trackPageview']);

Where UA numbers have been changed to protect the innocent :).

First option:
- Remove the ga.js from the html file
- Add the script injection code to the example.js file below the _gaq.push calls:

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Has anyone had any success with putting the tracking code inside a javascript file? Or do I have to move all the tracking code to the html file using the snippet from Google.

A: 

We've had similar issue, our problem was, that we had a twoletter domain. Once you set _gaq.push(['_setDomainName', 'xx.com']); it was all solved and worked fine.

Ivan Faltus
Our domain name is longer than 2 characters, so I don't think this will solve my problem. Thanks.
Brett Pontarelli