Index: googleanalytics.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.js,v
retrieving revision 1.3.2.8
diff -u -r1.3.2.8 googleanalytics.js
--- googleanalytics.js	4 Mar 2009 07:25:47 -0000	1.3.2.8
+++ googleanalytics.js	20 Jun 2009 12:19:40 -0000
@@ -1,41 +1,47 @@
 // $Id: googleanalytics.js,v 1.3.2.8 2009/03/04 07:25:47 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.body).click(function(event) {
+    // Catch only the first parent link of a clicked element.
+    $(event.target).parent('a:first').andSelf().filter('a').each(function() {
+      console.log("Clicked link: " + this.href);
 
-    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)) {
-          // 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.
-          pageTracker._trackPageview(this.href.replace(isInternal, ''));
-        }
-      }
-      else {
-        if (ga.trackMailto && $(this).is("a[href^=mailto:]")) {
-          // Mailto link clicked.
-          pageTracker._trackEvent("Mails", "Click", this.href.substring(7));
+      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)) {
+            // 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.
+            pageTracker._trackPageview(this.href.replace(isInternal, ''));
+          }
         }
-        else if (ga.trackOutgoing) {
-          // External link clicked.
-          pageTracker._trackEvent("Outgoing links", "Click", this.href);
+        else {
+          if (ga.trackMailto && $(this).is("a[href^=mailto:]")) {
+            // Mailto link clicked.
+            pageTracker._trackEvent("Mails", "Click", this.href.substring(7));
+          }
+          else if (ga.trackOutgoing) {
+            // External link clicked.
+            pageTracker._trackEvent("Outgoing links", "Click", this.href);
+          }
         }
-      }
-    } catch(err) {}
+      } catch(err) {}
+
+    });
   });
 }
