We have an ajaxy sort of html based app framework thing and want google analytics to work with it. And I believe we have set things up properly to manually call _trackPageview
where needed.
However things don't seem to be getting reported. Now either I don't have it working right, or GA tracking from javascript with a file://
protocol on the url silently violates some cross domain policy I'm not aware of.
So does GA work with local html via file://
? Or is there something wrong with my GA usage?
Note that the domain we are using doesn't actually exist. We want to use something like the mobile app tracking but from JavaScript rather than a native library. And in order to do this, it looks you setup a fake domain, and tell the tracker what domain it should be reporting as.
At the end of my <head>
:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXACCOUNTID-XX']);
_gaq.push(['_setDomainName', 'myfake.domain.com']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'http://www.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
And in our JS framework we call:
_gaq.push(['_trackPageview', '/some/path/here']);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…