Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Latest commit

 

History

History
27 lines (21 loc) · 931 Bytes

README.md

File metadata and controls

27 lines (21 loc) · 931 Bytes

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