• Publisert
  • 3 min

GDPR and Episerver: Honoring the Do Not Track browser setting in Google Tag Manager

To comply with users' privacy preferences, your Episerver site (and all the plugins you use for tracking) needs to honor the Do Not Track browser setting.

Chances are, your Episerver site is using several third party plugins and scripts (collectively called tags in Google Tag Manager) for tracking user behavior, site performance and device statistics. Some users don't want to be tracked, so they signal this by activating the Do Not Track setting that's built-into most modern browsers.

Your site should honor that setting and disable site-wide tracking accordingly. Unfortunately, this does not happen automagically - you need to tweak your Google Tag Manager configuration a little.

It's a 3-step process: 

  1. Detect whether Do Not Track is activated
  2. Make a trigger that is invoked when Do Not Track is activated
  3. Prevent tracking plugins from firing when Do Not Track is activated

 

Creating a custom JS variable that detects whether Do Not Track is activated

Log into your GTM account and go to your site's main workspace.

  • Click Variables, then create a new User-defined Variable called "CustomJS - Do Not Track" or something similar.
  • The variable type should be "Custom Javascript".
  • Paste the following script:
function () {
 if (navigator.doNotTrack == "1" || window.doNotTrack == "1") {
 return true;
 } 
return false; }
  • Save your new variable.

GTM custom JS variable to detect Do Not Track browser setting


You only have to create this variable once (we'll reuse it for all our tags).

This will detect if the Do Not Track browser setting is activated (true) or deactivated (false). To test it, use the Preview button at the top of your workspace:

GTM preview mode


Go to your browser settings and switch Do Not Track on (example here is from Chrome):

Chrome browser setting Do Not Track


Now open a new browser tab with your site - when in Preview mode, the GTM console should appear, showing you which tags and variables are currently loaded. Refresh the page (F5) and the value of your variable in the GTM preview console should read "true" or "false" accordingly:

GTM preview detecting Do Not Track

 

Create a custom trigger that is invoked when Do Not Track is activated

Now that we can detect the Do Not Track setting, we need to configure a trigger (exception) that we can use to disable tracking plugins.

  • From your workspace, create a new Trigger called "Exception - Do Not Track" or something similar.
  • Trigger Type should be "Custom event". 
  • Use regex matching for .*
  • The trigger should fire on "Some custom events", namely when your "CustomJS - Do Not Track" variable equals true.
  • Save your new trigger.

GTM custom trigger for Do Not Track

You only have to create this trigger once (we'll reuse it for all our tags).

Applying the trigger (exception) to your tags

Normally, most of your tags will fire on all pages your users visit. We need to create an exception to this rule.

  • From your workspace, click Tags, then click one of the tags your site is using. (This could be Hubspot as in my example, Google Analytics or any other.)
  • Notice the tag is set to fire on All Pages. Click the little pencil icon, then "Add Exception".
  • Select the "Exception - Do Not Track" trigger that we created earlier.
  • Save the tag.
  • Repeat this step for all your tracking tags.

GTM applying Do Not Track exception to tag
GTM Do Not Track exception added to tag


Important: When done, click "Submit" at the top of your workspace to publish your new configuration:

GTM submit changes


To verify, go to Preview mode and toggle Do Not Track on/off in your browser settings. When activated, your "CustomJS - Do Not Track" variable should read "true":

GTM preview Do Not Track variable detected


... and the tags should not fire on the page:

GTM tags not fired when Do Not Track is activated

That's it - the GTM tags on your site now honor the Do Not Track browser setting. For any additional tags you add later, just add the exception from Step 3.