Index: googleanalytics.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.js,v retrieving revision 1.1.2.10 diff -u -r1.1.2.10 googleanalytics.js --- googleanalytics.js 15 Mar 2009 20:32:21 -0000 1.1.2.10 +++ googleanalytics.js 22 Aug 2009 12:57:07 -0000 @@ -1,67 +1,66 @@ // $Id: googleanalytics.js,v 1.1.2.10 2009/03/15 20:32:21 hass Exp $ -Drupal.gaTrackerAttach = function(context) { - context = context || document; +$(document).ready(function() { - $('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.body).click(function(event) { + // Catch only the first parent link of a clicked element. + var link = $(event.target).is("a,area") ? $(event.target).get(0) : $(event.target).parents("a:first,area:first").get(0); - try { - // 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)) { - if (ga.LegacyVersion) { - urchinTracker(this.href.replace(isInternal, '')); - } - else { - // Download link clicked. - var extension = isDownload.exec(this.href); - pageTracker._trackEvent("Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')); - } - } - else if (isInternalSpecial.test(this.href)) { - // Keep the internal URL for Google Analytics website overlay intact. - if (ga.LegacyVersion) { - urchinTracker(this.href.replace(isInternal, '')); - } - else { - pageTracker._trackPageview(this.href.replace(isInternal, '')); - } - } - } - else { - if (ga.trackMailto && $(this).is("a[@href^=mailto:]")) { - // Mailto link clicked. - if (ga.LegacyVersion) { - urchinTracker('/mailto/' + this.href.substring(7)); - } - else { - pageTracker._trackEvent("Mails", "Click", this.href.substring(7)); + $(link).filter("a,area").each(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"); + + try { + // 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)) { + if (ga.LegacyVersion) { + urchinTracker(this.href.replace(isInternal, '')); + } + else { + // Download link clicked. + var extension = isDownload.exec(this.href); + pageTracker._trackEvent("Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')); + } + } + else if (isInternalSpecial.test(this.href)) { + // Keep the internal URL for Google Analytics website overlay intact. + if (ga.LegacyVersion) { + urchinTracker(this.href.replace(isInternal, '')); + } + else { + pageTracker._trackPageview(this.href.replace(isInternal, '')); + } } } - else if (ga.trackOutgoing) { - // External link clicked. Clean and track the URL. - if (ga.LegacyVersion) { - urchinTracker('/outgoing/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')); - } - else { - pageTracker._trackEvent("Outgoing links", "Click", this.href); + else { + if (ga.trackMailto && $(this).is("a[@href^=mailto:],area[@href^=mailto:]")) { + // Mailto link clicked. + if (ga.LegacyVersion) { + urchinTracker('/mailto/' + this.href.substring(7)); + } + else { + pageTracker._trackEvent("Mails", "Click", this.href.substring(7)); + } + } + else if (ga.trackOutgoing) { + // External link clicked. Clean and track the URL. + if (ga.LegacyVersion) { + urchinTracker('/outgoing/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')); + } + else { + pageTracker._trackEvent("Outgoing links", "Click", this.href); + } } } - } - } catch(err) {} - }); -}; - -if (Drupal.jsEnabled) { - $(document).ready(function() { - Drupal.gaTrackerAttach(this); + } catch(err) {} + }); }); -} +});