Posted By

errkk on 07/08/10


Tagged

event google jquery links external track Analytics


Versions (?)

Track outbound links with GA and jQuery


 / Published in: jQuery
 

  1. // Event Tracking for external Links
  2. //Add expression for external and mailto links
  3. $.expr[':'].external = function(obj){
  4. return !obj.href.match(/^mailto\:/)
  5. && (obj.hostname != location.hostname);
  6. };
  7.  
  8. function track_outbound_links(){
  9. // bind click function to all external links
  10. $('a:external').addClass('external').click(function(){
  11. var link = $(this).attr('href');
  12. _gaq.push(['_trackEvent', 'External Link', link]);
  13. window.location.href = link;
  14. return false;
  15. });
  16. }

Report this snippet  

You need to login to post a comment.