Last active
April 30, 2019 13:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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