Google Analytics 4
Intégration de Google Analytics 4 avec Consentio
Qu'est-ce que Google Analytics 4
GA4 est un outil d'analyse de Google permettant de suivre le trafic du site et le comportement des utilisateurs. Avec Consentio, il fonctionne automatiquement grâce à Google Consent Mode v2.
Catégorie de cookies
Google Analytics 4 appartient à la catégorie analytics.
| Catégorie Consentio | Signal GCM |
|---|---|
| analytics | analytics_storage |
Approche recommandée (Consent Mode)
Avec Consentio, une installation standard de GA4 suffit. Le widget configure automatiquement Google Consent Mode.
HTML
<!-- 1. Consentio en premier -->
<script src="https://consentio.cz/widget/YOUR_KEY/consentio.min.js" async></script>
<!-- 2. Puis 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>
Astuce : GA4 avec Consent Mode peut collecter des données anonymisées même sans consentement
(modélisation des conversions). Une fois le consentement accordé, il passe en mode complet.
Alternative : blocage manuel
Si vous préférez bloquer complètement GA4 avant le consentement :
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>
Alternative avec l'API JavaScript
Chargez GA4 dynamiquement après l'obtention du consentement :
JavaScript
Consentio.onConsentChange((consent) => {
if (consent.analytics) {
// Charger 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
| Catégorie Consentio | Signal GCM | Description |
|---|---|---|
| necessary | functionality_storage |
Stockage fonctionnel |
| analytics | analytics_storage |
Stockage analytique |
| marketing | ad_storage + ad_user_data + ad_personalization |
Signaux publicitaires |
Vérification
- Ouvrez les DevTools (F12)
- Vérifiez l'onglet Réseau —
gtag.jsne doit pas envoyer de données complètes sans consentement - Dans la console, exécutez :
dataLayer.push({event: 'consent_test'}) - Accordez le consentement et vérifiez que GA4 commence à collecter des données complètes