Hi and thank you much for this great module.
We're using it on many many German Drupal Websites. Sadly data privacy laws in Germany require to disable Google Analytics without a third party tool by a click.
This is typically being solved by a JavaScript function like this:
<script type="text/javascript">// <![CDATA[
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';
// 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>
Google supports it by providing a check against ga-disable- ...: https://developers.google.com/analytics/devguides/collection/analyticsjs...
It would be very helpful to have a helper function included in the D7 and D8 version of this module which can be called on every page via a JavaScript link.
If the maintainer agrees I'd offer to create a patch for that.
Thank you in advance for your feedback.
---
Current workaround: Use this in the BEFORE code:
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
// Debug output:
console.log('ga-disable is enabled, GA disabled.');
}
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2999 23:59:59 UTC; path=/';
window[disableStr] = true;
}