Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Functionality to verify if "Do not track" is set in the browser configuration.
<?php
/**
* Functionality to verify if "Do not track" is set
* in the browser configuration.
*/
if (array_key_exists('HTTP_DNT', $_SERVER) && (1 === (int) $_SERVER['HTTP_DNT'])) {
echo 'Do not track me enabled';
} else {
echo 'Do not track me disabled';
}
@DragonBe

This comment has been minimized.

Copy link
Owner Author

@DragonBe DragonBe commented Oct 20, 2017

Functionality to verify if "Do not track" is set in the browser configuration for Google Analytics.

<?php if (array_key_exists('HTTP_DNT', $_SERVER) || (1 !== (int) $_SERVER['HTTP_DNT'])): ?>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');
</script>
<?php endif ?>
@DragonBe

This comment has been minimized.

Copy link
Owner Author

@DragonBe DragonBe commented Oct 20, 2017

An example request header:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en;q=0.8,en-US;q=0.6,nl;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
DNT:1
Host:www.in2it.be
Referer:https://www.in2it.be/
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (<script>alert('You should filter input');</script>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.