Index: googleanalytics.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.js,v retrieving revision 1.3.2.5 diff -u -r1.3.2.5 googleanalytics.js --- googleanalytics.js 23 Nov 2008 13:18:13 -0000 1.3.2.5 +++ googleanalytics.js 23 Nov 2008 20:14:20 -0000 @@ -1,33 +1,38 @@ // $Id: googleanalytics.js,v 1.3.2.5 2008/11/23 13:18:13 hass Exp $ -Drupal.behaviors.gaTrackerAttach = function(context) { +Drupal.behaviors.gaTrackerAttach = function() { - // Attach onclick event to all links. - $('a', context).click( function() { - var ga = Drupal.settings.googleanalytics; - // Expression to check for absolute internal links. - var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); - // Expression to check for special links like gotwo.module /go/* links. - var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); - // Expression to check for download links. - var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i"); + // Attach onclick event to document only and catch clicks on all elements. + $(document).click(function(event) { + var element = event.target; - // Is the clicked URL internal? - if (isInternal.test(this.href)) { - // Is download tracking activated and the file extension configured for download tracking? - if ((ga.trackDownload && isDownload.test(this.href)) || isInternalSpecial.test(this.href)) { - // Keep the internal URL for Google Analytics website overlay intact. - pageTracker._trackPageview(this.href.replace(isInternal, '')); - } - } - else { - if (ga.trackMailto && this.href.indexOf('mailto:') == 0) { - // Mailto link clicked. - pageTracker._trackPageview('/mailto/' + this.href.substring(7)); + // Is the clicked element a link? + if ($(element).is('a')) { + var ga = Drupal.settings.googleanalytics; + // Expression to check for absolute internal links. + var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); + // Expression to check for special links like gotwo.module /go/* links. + var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); + // Expression to check for download links. + var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i"); + + // Is the clicked URL internal? + if (isInternal.test(element.href)) { + // Is download tracking activated and the file extension configured for download tracking? + if ((ga.trackDownload && isDownload.test(element.href)) || isInternalSpecial.test(element.href)) { + // Keep the internal URL for Google Analytics website overlay intact. + pageTracker._trackPageview(element.href.replace(isInternal, '')); + } } - else if (ga.trackOutgoing) { - // External link clicked. Clean and track the URL. - pageTracker._trackPageview('/outgoing/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')); + else { + if (ga.trackMailto && $(element).is("a[href^=mailto:]")) { + // Mailto link clicked. + pageTracker._trackPageview('/mailto/' + element.href.substring(7)); + } + else if (ga.trackOutgoing) { + // External link clicked. Clean and track the URL. + pageTracker._trackPageview('/outgoing/' + element.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')); + } } } });