]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1515144 - Prevent Google Analytics script from being loaded when DNT:1 so that...
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 18 Dec 2018 23:11:13 +0000 (00:11 +0100)
committerGitHub <noreply@github.com>
Tue, 18 Dec 2018 23:11:13 +0000 (00:11 +0100)
extensions/GoogleAnalytics/template/en/default/hook/global/header-additional_header.html.tmpl
extensions/GoogleAnalytics/template/en/default/hook/global/header-start.html.tmpl
extensions/GoogleAnalytics/web/js/analytics.js
extensions/GoogleAnalytics/web/js/dnt-helper.js [deleted file]

index fc0ebc4804342c4fa23f6ff2607b527494f9700f..e1763dd980983c02b949c17cf8a325e5021f85b3 100644 (file)
@@ -6,8 +6,8 @@
   # defined by the Mozilla Public License, v. 2.0.
   #%]
 
-[%# Disable tracking of security group members as well as private bugs #%]
-[% RETURN IF !Bugzilla.params.google_analytics_tracking_id ||
+[%# Disable tracking of DNT-enabled users, security group members as well as private bugs #%]
+[% RETURN IF !Bugzilla.params.google_analytics_tracking_id || Bugzilla.cgi.http('dnt') == '1' ||
     user.in_group(Param('insidergroup')) || (bug.defined && bug.groups_in.size) %]
 
 <meta name="google-analytics" content="[% Bugzilla.params.google_analytics_tracking_id FILTER html %]" data-location="
index 27a8587ef9e82b75efb837b827a12f970daa5f7c..195a2609c2d77dfe3daf07f26e1c0fd877d653b6 100644 (file)
@@ -6,9 +6,14 @@
   # defined by the Mozilla Public License, v. 2.0.
   #%]
 
+[% USE Bugzilla %]
+
+[%# Disable tracking of DNT-enabled users, security group members as well as private bugs #%]
+[% RETURN IF !Bugzilla.params.google_analytics_tracking_id || Bugzilla.cgi.http('dnt') == '1' ||
+    user.in_group(Param('insidergroup')) || (bug.defined && bug.groups_in.size) %]
+
 [% IF !javascript_urls %]
   [% javascript_urls = [] %]
 [% END %]
 
 [% javascript_urls.push('extensions/GoogleAnalytics/web/js/analytics.js') %]
-[% javascript_urls.push('extensions/GoogleAnalytics/web/js/dnt-helper.js') %]
index 86f1f259210793eef29b37c01fc40be1a2588a3b..9be1dfe45b3db4bf9552a60d4611b95ef30b349b 100644 (file)
@@ -8,7 +8,7 @@
 $(function() {
   var meta = $('meta[name="google-analytics"]');
 
-  if (typeof Mozilla.dntEnabled === 'function' && !Mozilla.dntEnabled() && meta.length) {
+  if (meta.length) {
     // Activate Google Analytics
     window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
     ga('create', meta.attr('content'), 'auto');
diff --git a/extensions/GoogleAnalytics/web/js/dnt-helper.js b/extensions/GoogleAnalytics/web/js/dnt-helper.js
deleted file mode 100644 (file)
index 828fdc7..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// create namespace
-if (typeof Mozilla === 'undefined') {
-    var Mozilla = {};
-}
-
-/**
- * Returns true or false based on whether doNotTrack is enabled. It also takes into account the
- * anomalies, such as !bugzilla 887703, which effect versions of Fx 31 and lower. It also handles
- * IE versions on Windows 7, 8 and 8.1, where the DNT implementation does not honor the spec.
- * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1217896 for more details
- * @params {string} [dnt] - An optional mock doNotTrack string to ease unit testing.
- * @params {string} [ua] - An optional mock userAgent string to ease unit testing.
- * @returns {boolean} true if enabled else false
- */
-Mozilla.dntEnabled = function(dnt, ua) {
-    'use strict';
-
-    // for old version of IE we need to use the msDoNotTrack property of navigator
-    // on newer versions, and newer platforms, this is doNotTrack but, on the window object
-    // Safari also exposes the property on the window object.
-    var dntStatus = dnt || navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
-    var userAgent = ua || navigator.userAgent;
-
-    // List of Windows versions known to not implement DNT according to the standard.
-    var anomalousWinVersions = ['Windows NT 6.1', 'Windows NT 6.2', 'Windows NT 6.3'];
-
-    var fxMatch = userAgent.match(/Firefox\/(\d+)/);
-    var ieRegEx = /MSIE|Trident/i;
-    var isIE = ieRegEx.test(userAgent);
-    // Matches from Windows up to the first occurance of ; un-greedily
-    // http://www.regexr.com/3c2el
-    var platform = userAgent.match(/Windows.+?(?=;)/g);
-
-    // With old versions of IE, DNT did not exist so we simply return false;
-    if (isIE && typeof Array.prototype.indexOf !== 'function') {
-        return false;
-    } else if (fxMatch && parseInt(fxMatch[1], 10) < 32) {
-        // Can't say for sure if it is 1 or 0, due to Fx bug 887703
-        dntStatus = 'Unspecified';
-    } else if (isIE && platform && anomalousWinVersions.indexOf(platform.toString()) !== -1) {
-        // default is on, which does not honor the specification
-        dntStatus = 'Unspecified';
-    } else {
-        // sets dntStatus to Disabled or Enabled based on the value returned by the browser.
-        // If dntStatus is undefined, it will be set to Unspecified
-        dntStatus = { '0': 'Disabled', '1': 'Enabled' }[dntStatus] || 'Unspecified';
-    }
-
-    return dntStatus === 'Enabled' ? true : false;
-};