title: How to set an Google Opt Out Cookie FOR GOOGLE ANALYTICS 4 - not universal one - the new ga4
body: <p>For a new project I want to use Google Analytics 4. <br></p>
  <p>Until today I was using the normal Google Analytics and on my privay policy page I have had an Google Opt Out Cookie. <br>
  This was implement by an simple JavaScript Code. <br>The code was loooking like this:</p>
  <pre><code>&lt;script&gt;
  // 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') &gt; -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;
  }
  &lt;/script&gt;
  </code></pre>
  <p>And with this code I was able to set an Google Opt Out Cookie on the page I wantet</p>
  <p><code>&lt;a href=&quot;javascript:gaOptout()&quot;&gt;Click here to opt-out of Google Analytics&lt;/a&gt;</code></p>
  <p>So now I have the problem, that with the new ga4 this is not working. On the developer page of ga4 there is an code to disable ga4.</p>
  <pre><code>&lt;!-- Global site tag (gtag.js) - Google Analytics --&gt;
  &lt;script async src=&quot;https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID&quot;&gt;&lt;/script&gt;
  &lt;script&gt;
    window['ga-disable-MEASUREMENT_ID'] = true;
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
  
    gtag('config', 'MEASUREMENT_ID');
  &lt;/script&gt;
  </code></pre>
  <p><strong>How I have to set up the Button Link to disable GA4? <br>Anybody can help me here???</strong><br>
  Thanks already, stay healthy and enjoy your Life :)</p>