Consent Mode v2 Setup

User
Consent mode v2 is not correctly setup cookie hub manuall installtion
Assistant
Got it — sounds like you're implementing **Google Consent Mode v2** manually using **CookieHub**, and something’s not set up correctly. Let's walk through how to fix it.

### ✅ Prerequisites:
Make sure you have:
– CookieHub installed via their manual install script.
– Consent Mode v2 tags set up for `ad_storage`, `analytics_storage`, `functionality_storage`, `personalization_storage`, and `security_storage` (as required by Google).
– Updated Google Tags (GTM or gtag.js) to respect consent.

### 🔧 Step-by-step Manual Setup

#### 1. **Load Consent Mode Early**
Insert this **before** any tracking scripts:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    functionality_storage: 'denied',
    personalization_storage: 'denied',
    security_storage: 'granted'
  });
</script>

> Note: `security_storage` should be `'granted'` to ensure basic security functions work.

#### 2. **Install CookieHub Script**
Install CookieHub **after** the default consent mode, like this:

<script type="text/javascript" src="https://cookiehub.net/c2/YOUR-COOKIEHUB-ID.js" data-cookiehub="YOUR-COOKIEHUB-ID"></script>

Replace `YOUR-COOKIEHUB-ID` with your real site ID from CookieHub.

#### 3. **Update Consent When Users Interact**
CookieHub will automatically update consent, but **you must ensure it communicates with gtag**, usually using a callback like:

<script>
  function onCookieHubConsentUpdate(consents) {
    gtag('consent', 'update', {
      ad_storage: consents.marketing ? 'granted' : 'denied',
      analytics_storage: consents.analytics ? 'granted' : 'denied',
      functionality_storage: consents.preferences ? 'granted' : 'denied',
      personalization_storage: consents.personalization ? 'granted' : 'denied',
      security_storage: 'granted'
    });
  }

  window.addEventListener('CookieHubConsentUpdate', function() {
    onCookieHubConsentUpdate(CookieHub.getConsents());
  });
</script>

> You may need to adjust `consents.analytics`, `consents.marketing`, etc., based on your CookieHub categories.

### 🔍 Debug Tips

– ✅ **Check for Consent Mode v2 requirements**: Make sure both `functionality_storage` and `personalization_storage` are included — they’re required as of March 2024.
– ✅ **Use Tag Assistant or Chrome DevTools > Network > `collect?` requests** to check if consent is applied before data is sent.
– ⚠️ **No `gtag('consent')` update = no effect** — your tags won’t defer tracking properly.

If you want, share your current code (or a link to your site) and I’ll help debug it directly.

Leave a Comment

Your email address will not be published. Required fields are marked *