Set up the Variable


In Google Tag Manager, open a Container where you’ll be implementing this feature. Go to Variables > New, then click Variable Configuration. 


  • Type: Custom JavaScript
  • Paste this code (if the variable returns “1”, then Do Not Track is enabled, otherwise it will be undefined<script>
function () { if (navigator.doNotTrack == "1" || window.doNotTrack == "1") { return "1"; } }

GTM Custom JS



Blocking tracking scripts

Create a blocking trigger and add it as an exception to all tracking tags within GTM container. Here’s a trigger:


GTM Exception

GTM GA Pageview


Read More: https://www.analyticsmania.com/post/respect-do-not-track-parameter-google-tag-manager