Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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>
share|improve this question

migrated from stackoverflow.com Oct 10 '13 at 19:53

This question came from our site for professional and enthusiast programmers.

1 Answer 1

This code must work:

<a href="#contact" onclick="_gaq.push(['_trackPageview' ,'/contact/']);"><span>Contact</span></a>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.