Last active
March 9, 2017 19:14
-
-
Save briezler/44cfd07f707c86927beaff01642af418 to your computer and use it in GitHub Desktop.
GoogleAnalytics Opt Out script
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
USAGE: | |
<a onclick="alert('Google Analytics wurde deaktiviert');" href="javascript:gaOptout()">Google Analytics deaktivieren</a> | |
The Script needs to be included in all pages. | |
<script type="text/javascript"> | |
// Set to the same value as the web property used on the site | |
var gaProperty = 'UA-{GA_ID}-x'; | |
// Disable tracking if the opt-out cookie exists. | |
var disableStr = 'ga-disable-' + gaProperty; | |
if (document.cookie.indexOf(disableStr + '=true') > -1) { | |
window[disableStr] = true; | |
} | |
// Opt-out function | |
function gaOptout() { | |
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; | |
window[disableStr] = true; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment