Skip to content

Instantly share code, notes, and snippets.

@schalkneethling
Created October 7, 2018 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schalkneethling/3cf78412b10400d9447dee0345e3b277 to your computer and use it in GitHub Desktop.
Save schalkneethling/3cf78412b10400d9447dee0345e3b277 to your computer and use it in GitHub Desktop.
Code snippets that go along with the blog post ~ Respect User Choice ~ Do Not Track
// 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}}']));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment