Using NoNonsense Cookie with Google Tag Manager
Learn how to integrate NoNonsense Cookie with Google Tag Manager to fire tags only after visitors give consent.
How the integration works
NoNonsense Cookie dispatches JavaScript events on the window whenever a visitor makes a consent choice. You can listen for these events in Google Tag Manager to conditionally fire tags based on which cookie categories the visitor has accepted.
Consent events
The following custom events are dispatched by the NoNonsense Cookie widget:
Fired when consent preferences are updated
nncookie_consent_update
Fired when the visitor accepts cookies
nncookie_consent_given
Fired when the visitor rejects all optional cookies
nncookie_consent_rejected
Setting up GTM triggers
Create a Custom Event trigger
In GTM, go to Triggers > New > Custom Event. Enter "nncookie_consent_update" as the event name. This trigger will fire whenever the visitor updates their consent preferences.
Add a Data Layer variable
The consent event includes details about which categories were accepted. Create Data Layer variables for "analytics", "marketing", and "preferences" to use them as conditions in your triggers.
Configure your tag triggers
For each tag (e.g., Google Analytics, Facebook Pixel), set the trigger to your custom event and add a condition that the relevant consent category is "true". For example, fire your GA4 tag only when analytics is true.
Test with GTM Preview mode
Use GTM's Preview mode to verify that tags only fire after the visitor gives consent. Open your website, interact with the cookie banner, and check that tags fire at the correct moment.
Example: listening for consent events
If you prefer to work with custom JavaScript rather than GTM triggers, you can listen for consent events directly:
<script>
window.addEventListener('nncookie_consent_update', function(e) {
if (e.detail.analytics) {
// Analytics consent given — fire your GA4 tag
gtag('consent', 'update', {
'analytics_storage': 'granted'
});
}
if (e.detail.marketing) {
// Marketing consent given — fire your ads tags
gtag('consent', 'update', {
'ad_storage': 'granted'
});
}
});
</script>
Google Consent Mode v2
NoNonsense Cookie is compatible with Google Consent Mode v2. The widget automatically sets the appropriate consent signals (analytics_storage, ad_storage, etc.) so that Google tags respect your visitors' choices without any additional configuration.