Respect user choice and honor DNT, wrap all the things
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
js
tests/unit
.gitignore
LICENSE
README.md
index.html
package.json

README.md

dnt-helper

Respect user choice and honor DNT, wrap all the things

Basic Usage with Google Tag Manager

First ensure that window.dataLayer is defined to avoid script errors:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
//core dataLayer object goes here
});

Now wrap the analytics include in the _dntEnabled conditional:

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',['{{settings.GTM_CONTAINER_ID}}']));
}

Read the blog post