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"></script>
<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.