Tack anchor link with Google Analytics

Posted by Fredrik on Pro Webmasters See other posts from Pro Webmasters or by Fredrik
Published on 2013-10-10T19:45:31Z Indexed on 2013/10/17 16:25 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

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?

© Pro Webmasters or respective owner

Related posts about html

Related posts about google