OpenRA/OpenRAWeb

Add an Opt-out option for Google Analytics

Opened this issue · 1 comments

This can be done by saving a cookie that, if present, will prevent the GA script from execution:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script type="text/javascript">
    var ga_property = 'UA-XXXX-Y'; // Insert GA-property
    var ga_disableStr = 'ga-disable-' + ga_property;
    if (document.cookie.indexOf(ga_disableStr + '=true') > -1) {
        window[ga_disableStr] = true;
    } else {
      // Execute Google Analytics Code
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
      ga('create', ga_property, 'auto');
      ga('set', 'anonymizeIp', true);
      ga('send', 'pageview');
    }
    function gaOptOut() {
      document.cookie = ga_disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
      window[ga_disableStr] = true;
      location.reload();
    }
  </script>
</head>
<body>
  <a href="javascript:gaOptOut()">Deactivate Google Analytics</a>
</body>

The link in the example above would be added to a new privacy page in the section for Google Analytics.

Nobody is interested in such things so closing as not helpful.