Index: googleanalytics.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_analytics/googleanalytics.js,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 googleanalytics.js
--- googleanalytics.js	23 Nov 2008 13:19:50 -0000	1.1.2.4
+++ googleanalytics.js	23 Nov 2008 20:51:52 -0000
@@ -1,47 +1,62 @@
 // $Id: googleanalytics.js,v 1.1.2.4 2008/11/23 13:19:50 hass Exp $
 
-gaTrackerAttach = function(context) {
-  context = context || document;
+gaTrackerAttach = 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) {
+    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.
-        if (ga.LegacyVersion) {
-          urchinTracker(this.href.replace(isInternal, ''));
-        }
-        else {
-          pageTracker._trackPageview(this.href.replace(isInternal, ''));
-        }
-      }
-    }
-    else {
-      if (ga.trackMailto && this.href.indexOf('mailto:') == 0) {
-        // Mailto link clicked.
-        if (ga.LegacyVersion) {
-          urchinTracker('/mailto/' + this.href.substring(7));
-        }
-        else {
-          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)) {
+          if (ga.LegacyVersion) {
+            urchinTracker(element.href.replace(isInternal, ''));
+          }
+          else {
+            // Download link clicked.
+            var extension = isDownload.exec(element.href);
+            pageTracker._trackEvent("Downloads", extension[1].toUpperCase(), element.href.replace(isInternal, ''));
+          }
+        }
+        else if (isInternalSpecial.test(element.href)) {
+          // Keep the internal URL for Google Analytics website overlay intact.
+          if (ga.LegacyVersion) {
+            urchinTracker(element.href.replace(isInternal, ''));
+          }
+          else {
+            pageTracker._trackPageview(element.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._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.
+          if (ga.LegacyVersion) {
+            urchinTracker('/mailto/' + element.href.substring(7));
+          }
+          else {
+            pageTracker._trackEvent("Mails", "Click", element.href.substring(7));
+          }
+        }
+        else if (ga.trackOutgoing) {
+          // External link clicked. Clean and track the URL.
+          if (ga.LegacyVersion) {
+            urchinTracker('/outgoing/' + element.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--'));
+          }
+          else {
+            pageTracker._trackEvent("Outgoing links", "Click", element.href);
+          }
         }
       }
     }
