mirror of
https://github.com/bigchaindb/site.git
synced 2024-12-24 02:16:10 +01:00
honor DoNotTrack browser setting wherever possible
This commit is contained in:
parent
689d5a938d
commit
ba11e3f50c
@ -5,6 +5,7 @@
|
||||
//=include bigchain/analytics.js
|
||||
//=include bigchain/forms.js
|
||||
//=include bigchain/smoothscroll.js
|
||||
//=include bigchain/dnt.js
|
||||
|
||||
//=include bigchain/form-earlyaccess.js
|
||||
|
||||
@ -13,11 +14,14 @@ jQuery(function($) {
|
||||
//
|
||||
// init modules
|
||||
//
|
||||
GoogleAnalytics.init();
|
||||
Forms.init();
|
||||
SmoothScroll.init();
|
||||
FormEarlyAccess.init();
|
||||
|
||||
if (!_dntEnabled()) {
|
||||
GoogleAnalytics.init();
|
||||
}
|
||||
|
||||
$('.hero .logo').on('animationend webkitAnimationEnd oAnimationEnd',
|
||||
function(e) {
|
||||
$('.hero').addClass('is-ready');
|
||||
|
46
_src/_assets/javascripts/bigchain/dnt.js
Normal file
46
_src/_assets/javascripts/bigchain/dnt.js
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
@ -37,7 +37,9 @@ var FormEarlyAccess = (function(w, d, $) {
|
||||
_config.formBtn.removeClass('disabled');
|
||||
|
||||
// send GA event
|
||||
GoogleAnalytics.gaEventEarlyAccessSuccess();
|
||||
if (!_dntEnabled()) {
|
||||
GoogleAnalytics.gaEventEarlyAccessSuccess();
|
||||
}
|
||||
},
|
||||
error: function(err) {
|
||||
_config.form.find('.alert-danger').removeClass('hide');
|
||||
@ -46,7 +48,9 @@ var FormEarlyAccess = (function(w, d, $) {
|
||||
.attr('value', 'Send');
|
||||
|
||||
// send GA event
|
||||
GoogleAnalytics.gaEventEarlyAccessError();
|
||||
if (!_dntEnabled()) {
|
||||
GoogleAnalytics.gaEventEarlyAccessError();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ svg4everybody.js
|
||||
//
|
||||
-->
|
||||
<script>
|
||||
if (!_dntEnabled()) {
|
||||
(function(window) {
|
||||
|
||||
// Google Analytics async snippet
|
||||
@ -59,6 +60,7 @@ svg4everybody.js
|
||||
};
|
||||
|
||||
}(window));
|
||||
}
|
||||
</script>
|
||||
|
||||
{% if jekyll.environment == "production" %}
|
||||
|
Loading…
Reference in New Issue
Block a user