Outgoing Google Analytics links


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.