Google Analytics 4
Google Analytics 4 integration with Consentio
What is Google Analytics 4
GA4 is an analytics tool from Google for tracking website traffic and user behaviour. Consentio sends it the Google Consent Mode v2 signals; the Consentio code has to sit above the GA4 tag.
Cookie Category
Google Analytics 4 belongs to the analytics category.
| Consentio Category | GCM Signal |
|---|---|
| analytics | analytics_storage |
Advanced mode (standard installation)
Keep the standard GA4 tag and place the Consentio code above it. The code sets Google Consent Mode to denied before GA4 reads it. GA4 loads immediately and sends Google anonymous cookieless pings before consent.
HTML
<!-- 1. Consentio code first, above GA4 (no async) -->
<script src="https://consentio.cz/widget/YOUR_KEY/consentio.min.js"></script>
<!-- 2. Then Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
Note: The anonymous pings before consent (conversion modelling) are a grey zone
under ePrivacy. If you want zero risk, use Basic mode below. Once consent is granted, GA4 switches to full mode.
Basic mode: blocked script (recommended)
GA4 loads only after consent and Google receives nothing before that:
HTML
<script type="text/plain" data-category="analytics"
async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX">
</script>
<script type="text/plain" data-category="analytics">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
JavaScript API Alternative
Dynamically load GA4 after consent:
JavaScript
// Put this in an inline script in the page HTML: the event is not repeated for a listener added later
let ga4Loaded = false
window.addEventListener('consentio:consent', (event) => {
if (event.detail.analytics && !ga4Loaded) {
ga4Loaded = true;
// Load GA4
const script = document.createElement('script')
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX'
script.async = true
document.head.appendChild(script)
script.onload = () => {
window.dataLayer = window.dataLayer || []
function gtag(){dataLayer.push(arguments)}
gtag('js', new Date())
gtag('config', 'G-XXXXXXX')
}
}
})
Google Consent Mode v2
| Consentio Category | GCM Signal | Description |
|---|---|---|
| functionality | functionality_storage + personalization_storage |
Functional and personalisation storage |
| analytics | analytics_storage |
Analytics storage |
| marketing | ad_storage + ad_user_data + ad_personalization |
Advertising signals |
Verification
- Open DevTools (F12)
- Check the Network tab —
gtag.jsshould not send full data without consent - Before you click anything in the banner, look at Application → Cookies: there must be no
_gacookie - Grant consent and verify that GA4 begins collecting full data