title: Deactivate Gtag in Angular App on user-opt-out / based on cookie-policy
body: <p>I implemented a cookie-policy banner with settings for tracking-cookies. Therefore in the next step I need to decide, whether to "use" or not use google-analytics (gtag) during runtime.</p>
  
  <p>Google advises to deactivate gtag be adding a property to the window  Object (<a href="https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out" rel="nofollow noreferrer">https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out</a>). </p>
  
  <pre><code>window['ga-disable-GA_MEASUREMENT_ID'] = true;
  </code></pre>
  
  <p>As you browse through the web there are a lot of discussion on how to access the window object, since it can cause problems e.g. during Server-Side-Rendering. But a solution using a Factory and a lot of code seems to big for my little problem: <a href="https://brianflove.com/2018/01/11/angular-window-provider/" rel="nofollow noreferrer">https://brianflove.com/2018/01/11/angular-window-provider/</a></p>
  
  <p>What I basically want to do now is this:</p>
  
  <pre><code>  if (isPlatformBrowser(this.platformId)){
          window['ga-disable-'+environment.GOOGLE_ANALYTICS_ID] = true;
        }
  </code></pre>
  
  <p>The solutions works, but I am not sure if this is a "valid solution", please advise on better approaches</p>