Skip to content

Consent Mode v2 with CookieYes

CookieYes is a popular Consent Management Platform used on WordPress and other CMS platforms. This recipe covers the full GTM-based Consent Mode v2 integration, including the CookieYes GTM template, consent category mapping, and verification steps.

Add this to your <head> before the GTM snippet:

<!-- Google Consent Mode v2 defaults — BEFORE GTM snippet -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
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',
wait_for_update: 500
});
</script>

CookieYes will update these signals after the user interacts with the consent banner.

Step 2 — Install the CookieYes GTM template

Section titled “Step 2 — Install the CookieYes GTM template”
  1. In GTM → Templates → Tag Templates → Search Gallery

  2. Search for CookieYes → select the official template

  3. Click Add to workspace

  4. Create a new tag from the CookieYes template:

    • Tag name: CMP - CookieYes
    • Template: CookieYes
    • Trigger: Consent Initialization - All Pages
    • Priority: 10 (higher than all other tags)
  5. Configure consent category mapping in the template:

    CookieYes uses these category names — map them to Google Consent Mode signals:

    • analyticsanalytics_storage
    • advertisementad_storage, ad_user_data, ad_personalization
    • functionalfunctionality_storage
    • performanceanalytics_storage (if you use CookieYes’s performance category)

Step 3 — Manual integration (if GTM template is unavailable)

Section titled “Step 3 — Manual integration (if GTM template is unavailable)”

If you prefer not to use the GTM template, or if your CookieYes version does not have one, you can integrate manually using CookieYes’s JavaScript callback:

// Custom HTML tag — fires on Consent Initialization
document.addEventListener('cookieyes_consent_update', function(event) {
var consent = event.detail;
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(function() {
gtag('consent', 'update', {
analytics_storage: consent.accepted.includes('analytics') ? 'granted' : 'denied',
ad_storage: consent.accepted.includes('advertisement') ? 'granted' : 'denied',
ad_user_data: consent.accepted.includes('advertisement') ? 'granted' : 'denied',
ad_personalization: consent.accepted.includes('advertisement') ? 'granted' : 'denied',
functionality_storage: consent.accepted.includes('functional') ? 'granted' : 'denied'
});
});
});

Alternatively, use the CookieYes CookieYes.getConsent() method:

// Check consent state at any time
if (typeof CookieYes !== 'undefined') {
var consent = CookieYes.getConsent();
var analyticsGranted = consent && consent.accepted && consent.accepted.includes('analytics');
console.log('Analytics consent:', analyticsGranted ? 'granted' : 'denied');
}
Section titled “Step 4 — CookieYes consent category mapping”
CookieYes CategoryGoogle Consent Signal
analyticsanalytics_storage
advertisementad_storage, ad_user_data, ad_personalization
functionalfunctionality_storage, personalization_storage
performanceanalytics_storage (if used)
necessaryAlways granted
Section titled “Step 5 — Configure Google Tag consent requirements”
  1. Open your Google Tag in GTM

  2. Go to Advanced Settings → Consent Settings

  3. For Additional consent checks: ensure analytics_storage is listed

  4. For Google Ads Conversion Tracking tags:

    • Advanced Settings → Consent Settings
    • Add ad_storage and ad_user_data as required
  5. Publish the workspace

  • No _ga cookie present in browser
  • No _gads or Google Ads cookies present
  • GA4 DebugView shows no events (or shows cookieless pings, depending on your setup)
  • _ga cookie appears
  • GA4 DebugView shows events with session and user data
  • Google Ads conversion tags fire (if on a conversion page)
// After CookieYes loads
CookieYes.getConsent()
// Returns: { accepted: ['analytics', 'advertisement', ...], rejected: [...] }
  1. Open GTM Preview and visit the site
  2. The CookieYes banner should appear
  3. Click Accept All — the consent update should appear as a dataLayer event
  4. In the Variables tab, check analytics_storage shows granted
  5. Navigate between pages — GA4 events should now fire normally

Test all four scenarios to ensure each works correctly:

ScenarioExpected behavior
No cookies (fresh visit)Banner shows, no GA4 cookies, no conversion tags fire
Accept analytics onlyGA4 fires normally, Google Ads tags blocked
Accept allAll tags fire normally
Reject allBanner shows, no cookies, no tags fire
Returning user (accepted)No banner, GA4 fires from first pageview

CookieYes script loads after GTM. If CookieYes’s script tag appears after GTM in your HTML, the consent update may arrive after Google’s tags have already initialised. Always load CookieYes before GTM, or use the wait_for_update: 500 parameter in your consent defaults.

WordPress plugin conflicts. If you manage CookieYes through WordPress and also have GTM through a plugin, the load order can be unpredictable. Verify the rendered HTML order in browser DevTools → View Page Source.

CookieYes categories don’t match your audit. CookieYes auto-detects cookies and assigns them to categories. If your GA4 cookies are placed in the wrong category (e.g., “functional” instead of “analytics”), users may accept functional cookies and expect GA4 to fire, but your mapping blocks it. Audit your CookieYes cookie categorisation.