I’m trying to get the setAllowAnchor flag in Google Analytics to record campaign information but it doesn’t seem to be working.
The site I’m trying to use it on uses hashbang-style URLs BTW – that’s the http://hostname/#!/relative-url style of navigation because there needs to be a persistant audio player across page views.
I’ve tried both of the below, but am not seeing any setAllowAnchor campaign in GA.
/#!/&utm_campaign=setAllowAnchor&utm_medium=hash&utm_source=test
/#utm_campaign=setAllowAnchor&utm_medium=hash&utm_source=test
The function setAllowAnchor is not deprecated. What am I doing wrong?
My Google Analytics code looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1060190-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
_gaq.push(['_setAllowAnchor', true]);
(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);
})();
</script>
Any Google Analytics configuration must come before the
_trackPageviewor any other_track*functions. So if you rewrite your code to issue the_setAllowAnchorbefore the_trackPageviewit should work.Also notice that
_trackPageLoadTimeis not needed anymore. It’s issued by default and so ths function is deprecated.