Posted By

rgsmith007 on 02/05/11


Tagged

link google tracking Analytics async


Versions (?)

Auto-tag Outbound Links for Google Analytics, Async Version


 / Published in: jQuery
 

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('body a').filter(function() {
  4. var theHref = this;
  5.  
  6. if (theHref.hostname && theHref.hostname !== location.hostname) {
  7. $(theHref).not(".noAutoLink").attr('target', '_blank').bind('click keypress', function(event) {
  8. var code = event.charCode || event.keyCode;
  9.  
  10. if (!code || (code && code == 13)) {
  11. var fixedLink = this.href;
  12. var _gaq = _gaq || [];
  13.  
  14. fixedLink = fixedLink.replace(/https?:\/\/(.*)/, "$1");
  15. fixedLink = '/outgoing/' + fixedLink;
  16.  
  17. _gaq.push(['_trackPageview', fixedLink]);
  18. };
  19. });
  20. };
  21. });
  22. });
  23. </script>

Report this snippet  

You need to login to post a comment.