Created
October 7, 2018 17:21
-
-
Save schalkneethling/2ea8e5be0ee84ac4c4a2dce2961e6ddc to your computer and use it in GitHub Desktop.
Code snippets that go along with the blog post ~ Respect User Choice ~ Do Not Track
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var anomalousWinVersions = ['Windows NT 6.1', 'Windows NT 6.2', 'Windows NT 6.3']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the helper | |
<script src="js/libs/dnt-helper.js"></script> | |
// If doNotTrack is not enabled, it is ok to add GTM | |
if (!_dntEnabled()) { | |
(function(w,d,s,l,i,j,f,dl,k,q){ | |
w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});f=d.getElementsByTagName(s)[0]; | |
k=i.length;q='//www.googletagmanager.com/gtm.js?id=@&l='+(l||'dataLayer'); | |
while(k--){j=d.createElement(s);j.async=!0;j.src=q.replace('@',i[k]);f.parentNode.insertBefore(j,f);} | |
}(window,document,'script','dataLayer',['YOUR-GTM-ID}}'])); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dntStatus = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With old versions of IE, DNT did not exist so we simply return false; | |
if (isIE && typeof Array.prototype.indexOf !== 'function') { | |
return false; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} 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'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} else if (isIE && platform && anomalousWinVersions.indexOf(platform.toString()) !== -1) { | |
// default is on, which does not honor the specification | |
dntStatus = 'Unspecified'; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment