How to Make Google Analytics Respect “Do Not Track”
It is important that your visitors/users feel safe and respected when visiting your website. That’s why it’s important to let them know what data you collect, why you collect it, and who will have access to it.
According to the law in many places, you also have to give users the opportunity to decide if your website should be allowed to store cookies in their web browsers. You can read Google’s information about it here.
Most current web browsers let users make a setting that notifies the website that you do not want your visit to be tracked. That function is called “Do Not Track” (DNT). The script for Google Analytics does, however, not take into consideration whether you have enabled DNT in your web browser.
Honor Do Not Track
If you want to stop Google Analytics from tracking visits to your website if users have enabled DNT, then use the plugin for Google Analytics that we have built at Outfox.
Including the script is pretty simple. Note: We do not offer any warranties when you are using this free service. It is provided “as is,” and you are using it at your own risk.
After the tracking object has been defined, call the plugin named ‘dnt’:
After the tracking code, include the script for the plugin:
<script async src="//storage.googleapis.com/outfox/dnt_min.js"></script>
Once you’ve done that, no data will be sent to Google Analytics from web browsers used by users who have activated Do Not Track.
Find Out How Many Users Have Activated DNT
To find out which share of your users have activated Do Not Track, configure the plugin for logging. Start by creating a custom dimension (session scope) in Google Analytics, and take note of which index it gets. Update the code below, and specify which dimension it should use:
Note that while you use the plugin in logging mode, data will be sent to Google Analytics even if DNT is activated. It’s only when you turn logging mode off that no data is sent to Google Analytics. You are only supposed to use logging mode to find out which share of visits/users you will lose after turning logging off and activating DNT support.
Create a custom report in Google Analytics to see the number of sessions with DNT activated:
In this example, you’d see 11% fewer visits in Google Analytics after DNT support for Google Analytics is activated using our plugin.