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. With Consentio, it works automatically thanks to Google Consent Mode v2.
Cookie Category
Google Analytics 4 belongs to the analytics category.
| Consentio Category | GCM Signal |
|---|---|
| analytics | analytics_storage |
Recommended Approach (Consent Mode)
With Consentio, a standard GA4 installation is sufficient. The widget automatically sets up Google Consent Mode.
HTML
<!-- 1. Consentio first (no async — must run before GA4) -->
<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>
Tip: GA4 with Consent Mode can collect anonymised data even without consent
(conversion modelling). When consent is granted, it switches to full mode.
Alternative: Manual Blocking
If you prefer to block GA4 completely before consent:
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
Consentio.onConsentChange((consent) => {
if (consent.analytics) {
// 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 |
|---|---|---|
| necessary | functionality_storage |
Functional 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 - In the console, run:
dataLayer.push({event: 'consent_test'}) - Grant consent and verify that GA4 begins collecting full data