Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brunobuddy
Last active April 30, 2019 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunobuddy/b87cbb6174d9dae967b9b0d320a12eb9 to your computer and use it in GitHub Desktop.
Save brunobuddy/b87cbb6174d9dae967b9b0d320a12eb9 to your computer and use it in GitHub Desktop.
Custom script for Google Tag Manager to enable or disable Google Analytics tracking based on the presence of the "accept_cookies" cookie
<script>
// If no cookie
if( document.cookie.indexOf('accept_cookies=') == -1) {
// Disable Google Analytics
window['ga-disable-UA-XXXXXXXX-X'] = true;
}
else {
// Enable Google Analytics
window['ga-disable-UA-XXXXXXXX-X'] = false;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment