Tack anchor link with Google Analytics
- by Fredrik
I have searched for how to track anchor links in analytics, but couldn't get it working.
I have this code in the header:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('_setAllowAnchor', true);
ga('create', 'UA-*******-1', '****.com');
ga('send', 'pageview');
</script>
And my links looks like this:
<a href='#/contact'><span>Contact</span></a>
I also tried to use this links:
<a href='#/contact' onClick="_gaq.push(['_trackPageview', location.pathname+location.search+location.hash]);"><span>Contact</span></a>
Is there any tips on what I can do?