Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Johnsen <johphi@gmail.com>2017-01-25 23:54:34 +0300
committerPhillip Johnsen <johphi@gmail.com>2017-01-25 23:54:34 +0300
commit01b90ee1db9276d6c1af0e6e0352fd4759ebb68d (patch)
tree4cc05f5854b0b9f1ff4c4b4c84ccddf8eb5e1b66 /doc/api_assets
parent124d155f5ec22568c740d4a465f4496cda44deb6 (diff)
tools,doc: add Google Analytics tracking.
Adds Google Analytics tracking script to all doc pages when `DOCS_ANALYTICS` is set when running `make`: ```bash $ DOCS_ANALYTICS=<GOOGLE ANALYTICS ID> make ``` By default (when `DOCS_ANALYTICS` is not set), no tracking scripts are included. It respects "Do Not Track" settings end users might have in their browser. Also changes make target `doc-upload` from depending on the `$(TARBALL)` target, to only depend on `doc` directly. PR-URL: https://github.com/nodejs/node/pull/6601 Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'doc/api_assets')
-rw-r--r--doc/api_assets/dnt_helper.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/doc/api_assets/dnt_helper.js b/doc/api_assets/dnt_helper.js
new file mode 100644
index 00000000000..f255d916c2d
--- /dev/null
+++ b/doc/api_assets/dnt_helper.js
@@ -0,0 +1,49 @@
+/**
+ * http://schalkneethling.github.io/blog/2015/11/06/respect-user-choice-do-not-track/
+ * https://github.com/schalkneethling/dnt-helper/blob/master/js/dnt-helper.js
+ *
+ * Returns true or false based on whether doNotTack 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} [userAgent] - An optional mock userAgent string to ease unit testing.
+ * @returns {boolean} true if enabled else false
+ */
+function _dntEnabled(dnt, userAgent) {
+
+ '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 ua = userAgent || 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 = ua.match(/Firefox\/(\d+)/);
+ var ieRegEx = /MSIE|Trident/i;
+ var isIE = ieRegEx.test(ua);
+ // Matches from Windows up to the first occurance of ; un-greedily
+ // http://www.regexr.com/3c2el
+ var platform = ua.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;
+}