Posted By

rgsmith007 on 02/05/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

appeltauer


Auto-tag Outbound Links for Google Analytics, Async Version, Event Variant


 / Published in: jQuery
 

This uses the Event Tracking system rather than a '/outbound'

  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.  
  16. _gaq.push(['_trackEvent', 'Outbound', 'Click', fixedLink]);
  17. };
  18. });
  19. };
  20. });
  21. });
  22. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: rgsmith007 on May 5, 2011

Some issues have been reported with the _gaq.push not being tracked. Alternately, you can do the below:

var pageTracker=gat.getTracker("UA-xxxxxxxx-x");

if (pageTracker) { pageTracker._trackEvent('Outbound', 'Click', fixedLink); }

You need to login to post a comment.