#328562: New Download, Mail and Outgoing links tracking with Events
authorhass
Tue, 25 Nov 2008 22:43:30 +0000 (22:43 +0000)
committerhass
Tue, 25 Nov 2008 22:43:30 +0000 (22:43 +0000)
googleanalytics.js

index a6ebf6f..60661cd 100644 (file)
@@ -15,19 +15,24 @@ Drupal.behaviors.gaTrackerAttach = function(context) {
     // 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)) {
+      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.href.indexOf('mailto:') == 0) {
+      if (ga.trackMailto && $(this).is("a[href^=mailto:]")) {
         // Mailto link clicked.
-        pageTracker._trackPageview('/mailto/' + this.href.substring(7));
+        pageTracker._trackEvent("Mails", "Click", this.href.substring(7));
       }
       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('--'));
+        // External link clicked.
+        pageTracker._trackEvent("Outgoing links", "Click", this.href);
       }
     }
   });