diff --git a/googleanalytics.debug.js b/googleanalytics.debug.js index 331bc43..4344576 100644 --- a/googleanalytics.debug.js +++ b/googleanalytics.debug.js @@ -15,7 +15,8 @@ $(document).ready(function() { console.info("Closest element '%o' has been found. URL '%s' extracted.", this, this.href); // Is the clicked URL internal? - if (Drupal.googleanalytics.isInternal(this.href)) { + if (Drupal.googleanalytics.isInternal(this.href) || Drupal.settings.googleanalytics.trackDomainMode == 2 && + Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains)) { // Skip 'click' tracking, if custom tracking events are bound. if ($(this).is('.colorbox')) { // Do nothing here. The custom event will handle all tracking. @@ -44,14 +45,9 @@ $(document).ready(function() { ga("send", "event", "Mails", "Click", this.href.substring(7)); } else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { - if (Drupal.settings.googleanalytics.trackDomainMode != 2 || (Drupal.settings.googleanalytics.trackDomainMode == 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) { - // External link clicked / No top-level cross domain clicked. - console.info("Outbound link '%s' has been tracked.", this.href); - ga("send", "event", "Outbound links", "Click", this.href); - } - else { - console.info("Internal link '%s' clicked, not tracked.", this.href); - } + // External link clicked / No top-level cross domain clicked. + console.info("Outbound link '%s' has been tracked.", this.href); + ga("send", "event", "Outbound links", "Click", this.href); } } }); @@ -127,7 +123,7 @@ Drupal.googleanalytics.isDownload = function (url) { * @return boolean */ Drupal.googleanalytics.isInternal = function (url) { - var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); + var isInternal = new RegExp("^(https?):\/\/(?:.+\\.)?" + window.location.host, "i"); return isInternal.test(url); }; diff --git a/googleanalytics.js b/googleanalytics.js index 1eed3c3..4bba479 100644 --- a/googleanalytics.js +++ b/googleanalytics.js @@ -12,7 +12,8 @@ $(document).ready(function() { $(event.target).closest("a,area").each(function() { // Is the clicked URL internal? - if (Drupal.googleanalytics.isInternal(this.href)) { + if (Drupal.googleanalytics.isInternal(this.href) || Drupal.settings.googleanalytics.trackDomainMode == 2 && + Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains)) { // Skip 'click' tracking, if custom tracking events are bound. if ($(this).is('.colorbox')) { // Do nothing here. The custom event will handle all tracking. @@ -34,10 +35,8 @@ $(document).ready(function() { ga("send", "event", "Mails", "Click", this.href.substring(7)); } else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { - if (Drupal.settings.googleanalytics.trackDomainMode != 2 || (Drupal.settings.googleanalytics.trackDomainMode == 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) { - // External link clicked / No top-level cross domain clicked. - ga("send", "event", "Outbound links", "Click", this.href); - } + // External link clicked / No top-level cross domain clicked. + ga("send", "event", "Outbound links", "Click", this.href); } } }); @@ -109,7 +108,7 @@ Drupal.googleanalytics.isDownload = function (url) { * @return boolean */ Drupal.googleanalytics.isInternal = function (url) { - var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); + var isInternal = new RegExp("^(https?):\/\/(?:.+\\.)?" + window.location.host, "i"); return isInternal.test(url); };