GTM dataLayer
The script pushes these events to window.dataLayer automatically:
| Event | When |
|---|---|
OptSensLoaded | The script finished loading |
OptSensConsentReady | Consent state resolved on page load |
OptSensConsentUpdate | Consent given or changed |
OptSensBannerShown | Banner displayed |
OptSensBannerHidden | Banner closed |
OptSensPreferencesShown | Preference center opened |
OptSensPageView | SPA route change (when using onRouteChange()) |
GTM trigger example
Create a Custom Event trigger in Google Tag Manager:
- Trigger type: Custom Event
- Event name:
OptSensConsentUpdate
Use it to fire tags only after consent.
Google Consent Mode v2
Consent Mode is integrated automatically. No dataLayer work is needed for it. The script fires the default state before any Google tag runs:
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
functionality_storage: 'denied',
personalization_storage: 'denied',
security_storage: 'granted',
});
After consent:
gtag('consent', 'update', {
ad_storage: 'granted', // advertising category
analytics_storage: 'granted', // analytics category
ad_user_data: 'granted', // advertising category
ad_personalization: 'granted', // advertising category
functionality_storage: 'granted', // functional category
personalization_storage: 'granted', // performance category
});
Works with Google Analytics 4, Google Ads and Google Tag Manager. See Google Consent Mode v2 for the full framework page.