How to Configure Google Analytics to Collect Anonymous User Statistics Before Consent (For Websites Using HTML Integration)
If your website uses Google Tag Manager instead of HTML for Google Analytics, please follow the setup instructions here.
If your website collects personally identifiable information for analytics or marketing, you are required by PDPA to obtain user consent before any data is collected.
However, if your goal is simply to track actual visitor numbers — including those who haven’t given consent — enabling anonymous tracking helps reduce compliance risks while still providing useful insights.
Configure Google Analytics to operate in anonymized mode before the user has given consent. This means:
No cookies are stored
IP addresses are anonymized
Statistics remain rough but functional
Once the user accepts analytic cookies, the script is allowed to operate normally again (using cookies).
In your cookie management settings, move these scripts from Analytics to Necessary:
https://www.googletagmanager.com/gtm.js?id=<GTM-KEY>
https://www.google-analytics.com/analytics.jsThis allows them to load on all visits (but in restricted mode before consent).
Here’s the default format of a Google Analytics (gtag.js) script:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<GA_MEASUREMENT_ID>');
</script>Update it to include consent detection like this:
(Replace 'category-slug' with the actual cookie category slug, such as 'analytics'. How to find a slug)
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
if (window.cwcIsUserAccept && window.cwcIsUserAccept('category-slug')) {
// User has given consent → use normal tracking
gtag('config', '<GA_MEASUREMENT_ID>');
} else {
// No consent yet → use anonymous mode
gtag('config', '<GA_MEASUREMENT_ID>', {
client_storage: 'none',
anonymize_ip: true
});
}
</script>client_storage: 'none' → disables cookies
anonymize_ip: true → masks the user's IP
cwcIsUserAccept('category-slug') → checks if user consent exists using the Cookie Wow script
With this setup, your website can:
Track rough visitor metrics even before consent
Comply with privacy regulations
Enable full analytics only after explicit user approval
For more information about gtag configuration options, visit: Google Analytics gtag.js documentation
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 Analyt...
Preserving Conversion Rate with Google Consent Mode
Google Consent ModeGoogle Consent Mode is an API developed by Google to help improve the accuracy of marketing analysis and planning by u...
Cookie Category Slugs
Cookie Category SlugsCookie Wow assigns a slug to each cookie category. This slug acts as a unique identifier that can be used in code im...
Get in touch and we'll help solve it