title: Google Analytics, Flutter, cookies and the General Data Protection Regulation (GDPR)
body: <p>Following the <em>General Data Protection Regulation (GDPR)</em> the user has to give his consent before any cookie is set.</p>
  <p>I use google / firebase analytics in a Flutter web site. When the user opens a page immediately two cookies are stored: _ga and _ga_SOMECODE.</p>
  <p>How can I make google analytics postpone these cookies so that I can first ask the user's consent and leave to him the choice to allow a cookie for the use of google analytics - or to reject both?</p>
  <p>I am looking for something like this:</p>
  <ul>
  <li><p>in index.html</p>
  <pre><code>// Initialize Google Analytics
  &lt;script&gt;
    var analyticsConfig = { enabled: false };
    firebase.analytics(analyticsConfig);
  &lt;/script&gt;
  </code></pre>
  </li>
  <li><p>Somewhere on the first page:</p>
  <p><strong>Accept statistics cookies? [yes] [no]</strong></p>
  <p>and in the corresponding dart code:</p>
  <pre><code>// Enable / disable Google Analytics
  FirebaseAnalytics analytics = getAnalytics();
  analytics.setAnalyticsCollectionEnabled(usersAnswer);
  </code></pre>
  </li>
  </ul>
  <p>In the ideal case the analytics code would only be loaded when the user provided a positive answer.  In the case the user's choice would be <strong>[no]</strong> the analytics code in the code base would do nothing.</p>
  <p>How can I implement something similar?</p>
  <p>Thanks, Dietrich</p>