Articles on: How to Preserve Analytics While Using IP Anonymization in Google Analytics

How to Allow Google Analytics to Collect Anonymous Statistics Before User Consent (Google Tag Manager Setup)

How to Allow Google Analytics to Collect Anonymous Statistics Before User Consent (Google Tag Manager Setup)


If you're using Google Analytics via Google Tag Manager (GTM) and want to collect data anonymously before users give consent, here’s a step-by-step guide.

For websites using Google Analytics installed directly via HTML (not through GTM), refer to this guide: Read setup instructions here


Note:

If your website collects personally identifiable information (PII) for analysis or marketing purposes, you must first obtain user consent according to PDPA laws.

However, to ensure accurate visitor statistics — regardless of consent — you can anonymize data before consent is granted to reduce privacy risks.


Principle:

Before consent is given, configure Google Analytics to:

  • Not use cookies
  • Not collect granular identity details
  • Use anonymized IP by default ( more info)


Once consent is granted via the Cookie Wow banner, allow normal data collection with cookies.


Step-by-Step Setup via Google Tag Manager


❶ Move the GTM & Analytics tags to the “Necessary” category:



  1. Open GTM, go to the Variables tab.


  1. Create a new Custom JavaScript Variable.


  1. Use this snippet (replace 'category-slug' with the actual category slug you're using, usually 'Analytics'):


function() {
return window.cwcIsUserAccept('category-slug');
}


You can find the correct slug used in your Cookie Wow settings here: How to find slugs


  1. Set "Convert null to false" and "Convert undefined to false"
  2. Name it something like cwcIsUserAcceptConsent, then Save




  • Name: Page View Trigger without User Consent
  • Type: Page View → Some Page Views
  • Condition: cwcIsUserAcceptConsent equals false




  • Name: Page View Trigger with User Consent
  • Type: Page View → Some Page Views
  • Condition: cwcIsUserAcceptConsent equals true





  1. Name it: Universal Analytics without User Consent
  2. Tag Type: Google Analytics: Universal Analytics
  3. Track Type: Page View
  4. Google Analytics Settings: Use your Tracking ID
  5. Enable "Override settings in this tag"
  6. Under More Settings, add these fields:


storage: none
storeGac: false
anonymizeIp: true



  1. Set Trigger to: Page View Trigger without User Consent



  1. Name it: Universal Analytics with User Consent
  2. Tag Type: Google Analytics: Universal Analytics
  3. Track Type: Page View
  4. Use your GA Tracking ID
  5. Set Trigger to: Page View Trigger with User Consent

Updated on: 29/05/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!