Add JS-function / method to set ga-disable-...

Created on 22 October 2017, about 7 years ago
Updated 4 March 2024, 10 months ago

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;
}
✨ Feature request
Status

Closed: won't fix

Version

4.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands Summit

    Hi, When is this committed please to latest 4.x-dev?
    Thanks for your reply in advance, greetings,

  • Status changed to Closed: won't fix 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    This has been rolled into google tag. Customers should not be using the google analytics module anymore.

Production build 0.71.5 2024