From 03c880be7f9b09ce9990b2191ac4a6d7ca51c8fd Mon Sep 17 00:00:00 2001 From: Ryan Jacobs Date: Thu, 12 Jul 2012 12:44:17 -0500 Subject: [PATCH] Issue #1580144: Use mousedown instead of click for link tracking. Also add related README notes about Link Tracking. --- README.txt | 17 +++++++++++++++++ googleanalytics.js | 6 +++++- 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/README.txt b/README.txt index bcbf7dd..3c63276 100644 --- a/README.txt +++ b/README.txt @@ -65,6 +65,23 @@ Scope: Visitor More details about Custom variables can be found in the Google API documentation at http://code.google.com/intl/en/apis/analytics/docs/tracking/gaTrackingCustomVariables.html +Link Tracking +============= +This module includes special support for tracking outbound, file and mailto +links, which the inclusion of the Analytics tracking code alone does not +provide. This link tracking uses jQuery to capture in-page click events (for +links that do not point to other internal Drupal pages) and reports these clicks +directly to Analytics. By default this activity is reported as "Events" in +Analytics. Link tracking can be configured on the settings page at +admin/settings/googleanalytics. + +Please note that link tracking is currently not 100% supported across all +browsers. As a result a small percentage of outbound, file and mailto clicks +may not be captured in your Analytics reports. Though this percentage is +estimated to be somewhat nominal for most user's reporting requirements, it's +important to keep this limitation in mind if scrutinizing browser trends across +events, etc. For more information see: http://drupal.org/node/1580144 + Advanced Settings ================= You can include additional JavaScript snippets in the custom javascript diff --git a/googleanalytics.js b/googleanalytics.js index 70cc0f2..4a1db21 100644 --- a/googleanalytics.js +++ b/googleanalytics.js @@ -2,7 +2,11 @@ $(document).ready(function() { // Attach onclick event to document only and catch clicks on all elements. - $(document.body).click(function(event) { + // Instead of 'click' we use 'mousedown' as this introduces a slight delay + // (estimated at 50ms-200ms) between the event and the link being followed by + // the browser. In some cases this delay helps ensure the tracking code + // finishes in time. @see: http://drupal.org/node/1580144 + $(document.body).mousedown(function(event) { // Catch only the first parent link of a clicked element. $(event.target).parents("a:first,area:first").andSelf().filter("a,area").each(function() { -- 1.7.7.5 (Apple Git-26)