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

schalkneethling/dnt-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Respect user choice and honor DNT, wrap all the things

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published