GDPR: Add gaOptout() JavaScript function (and token optionally)

Created on 6 August 2019, over 5 years ago
Updated 24 October 2023, about 1 year ago

This module is on a very very good way to become a better alternative to Google Analytics module because it doesn't use inline Js and has a nice concept to support eu_cookie_compliance. By this it's a great candidate for GDPR compliance, which is very very hard to achieve with google_analytics.

Some years ago I wrote two issues that would help a lot for GDPR compliance - a JavaScript function (and for simple use eventually a token creating that link) to Opt-out from Google Analtics in the privacy policy text, which is a requirement in EU countries.

See:

So what we need is simply


  • var gaProperty = window.google_analytics_uacct;
    var disableStr = 'ga-disable-' + gaProperty;
    function gaOptout() {
      document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
      window[disableStr] = true;
    }

  • var gaProperty = window.google_analytics_uacct;
    var disableStr = 'ga-disable-' + gaProperty;
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
      window[disableStr] = true;
      console.log('ga-disable is enabled, GA disabled.');
    }
    
  • Show a confirmation message after opt-out - in a first step this could be a javascript alert
  • Optionally: A token to call that function, e.g. "javascript:gaOptout(true);"
  • Optionally: Prevent loading the ga script at all from the google server if the user opted-out (for even better GDPR compliance), like in #3011324: Integration with EU Cookie Compliance module

I also wrote a short blog article about that some years ago... https://julian.pustkuchen.com/drupal-cms-google-analytics-gaoptout-daten...

Feature request
Status

Closed: outdated

Version

1.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.

Production build 0.71.5 2024