Track clicks on #hash anchor links on Google Analytics

/ Published in: jQuery
Save to your folder(s)

This code allows Google Analytics to monitor hashtags of jQuery activated events. Very useful if you relies on modal boxes.

Este código permite ao Google Analytics monitorar hashtags e âncoras em sites com eventos ativados por jQuery. Muito útil se você utiliza caixas modais.

Copy this code and paste it in your HTML
  1. <a href="#contact" rel="contact">Contact</a>
  3. <script>
  4. $(document).ready(function(){
  5. //
  6. loadOnClick();
  8. function loadOnClick() {
  9. $('a').each(function(){
  10. $(this).attr("onclick", "_gaq.push(['_trackPageview', location.pathname + + jQuery(this).attr('rel')]);" );
  11. });
  12. }
  13. });
  14. </script>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.