Posted By

dsntos on 08/18/09


Tagged

google blank external target Analytics clicks outgoing


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rickfu


Outgoing Google Analytics links


 / Published in: jQuery
 

Detects all external/outgoing links, adds class, & adds target = _blank. When using a strict doctype, this method is valid when using target manipulation.

  1. $('#wrapper a:not(.popupwindow)').filter(function() {
  2. var theHref = this;
  3. if (theHref.hostname && theHref.hostname !== location.hostname) {
  4. $(theHref).not(".noAutoIcon").addClass("external");
  5. $(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) {
  6. var code=event.charCode || event.keyCode;
  7. if (!code || (code && code == 13)) {
  8. if(pageTracker){
  9. var fixedLink = this.href;
  10. fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
  11. fixedLink = '/outgoing/' + fixedLink;
  12. pageTracker._trackPageview(fixedLink);
  13. };
  14. };
  15. });
  16. };
  17. });

Report this snippet  

You need to login to post a comment.