How to Configure Google Analytics to Collect Anonymous User Statistics Before Consent (For Websites Using HTML Integration)
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:
This 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:
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)
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
If your website uses Google Tag Manager instead of HTML for Google Analytics, please follow the setup instructions here.
Note:
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.
Concept:
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).
Instructions:
1. Move Google Tags to the "Necessary" category in Cookie Manager
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.js
This allows them to load on all visits (but in restricted mode before consent).
2. Modify Your Google Analytics Script in HTML
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>
Explanation of the Parameters:
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
Updated on: 28/05/2025
Thank you!