4 min read
Cookiebot guide

Paste the following code as high in to the <head> of the page as possible. In wordpress this should be loaded before wp_head loop

<!-- The initial config of Consent Mode v2 -->
<script type="text/javascript" data-cookieconsent="ignore">
  window.dataLayer = window.dataLayer || [];
  function gtag() {
    dataLayer.push(arguments);
  }
  gtag('consent', 'default', {
    ad_personalization: 'denied',
    ad_storage: 'denied',
    ad_user_data: 'denied',
    analytics_storage: 'denied',
    functionality_storage: 'denied',
    personalization_storage: 'denied',
    security_storage: 'granted',
    wait_for_update: 1500,
  });
  gtag('set', 'ads_data_redaction', true);
  gtag('set', 'url_passthrough', false);
</script>

Step 2 - Add Cookiebot code to website’s code

Paste the following code as high in to the <head> of the page as possible. If GTM is added using plugin such as Google Tag Manager for Wordpress. If you do not want the automated blocking mode you can use async/defer

<script 
type="text/javascript" 
id="Cookiebot" 
src="https://consent.cookiebot.com/uc.js" 
data-cbid="YOUR COOKIEBOT ID HERE"
data-blockingmode="auto"
data-culture="en"
></script>

When you want to show the banner in different languages, example for different language versions and you do not want automatic language detection to be used.

LanguageCode in ‘data-culture’
ArabicAR
BulgarianBG
CatalanCA
CzechCS
WelshCY
DanishDA
DeutschDE
Greek (modern)EL
EnglishEN
SpanishES
EstonianET
BasqueEU
FinnishFI
FrenchFR
IrishGA
HebrewHE
HindiHI
CroatianHR
HungarianHU
IndonesianID
IcelandicIS
ItalianIT
JapaneseJA
KoreanKO
LithuanianLT
LatvianLV
MacedonianMK
MalayMS
Norwegian BokmålNB
DutchNL
PolishPL
PortuguesePT
Brazilian PortuguesePT-BR
RomanianRO
RussianRU
SinhaleseSI
SlovakSK
SlovenianSL
AlbanianSQ
SerbianSR
SwedishSV
TamilTA
ThaiTH
TurkishTR
UkrainianUK
VietnameseVI
ChineseZH
Traditional ChineseZH-HANT

Paste the following code as to the page that lists cookies.


<script 
type="text/javascript"
id="CookieDeclaration"
src="https://consent.cookiebot.com/YOUR COOKIEBOT ID HERE/cd.js" 
defer
data-culture="en"
></script>

If you want to have a renew button in different location than the default floating button on the left site. A button can be added to website’s footer. Copy following code and add styling if needed.


<button onclick="javascript:Cookiebot.renew();">
  Renew Consent
</button>
  1. Before accepting any cookies open Console and Copy following code to console. After excecution you should see denied for all except security_storage.

// Helper functions for status string and color
const consentStatusString = status => status === undefined ? "" : status ? "granted" : "denied";
const consentStatusColor = status => status === "granted" ? "color: #4AF626" : "color: #ef2929";
    
(() => {
  if (!("google_tag_data" in window) || !window.google_tag_data?.ics?.entries) {
    console.log("No Consent Mode data found");
    return;
  }
    
  const consentEntries = window.google_tag_data.ics.entries;
    
  // Process each consent entry, except 'wait_for_update'
  for (const entry in consentEntries) {
    if (entry === 'wait_for_update') continue; // Skip 'wait_for_update'

    const defaultStatus = consentStatusString(consentEntries[entry]['default']);
    const updateStatus = consentStatusString(consentEntries[entry]['update']);
    
    console.log(`%c${entry}`, 'font-weight: bold; font-size: 14px;');
    
    // Check and log default status
    if (defaultStatus !== "") {
      console.log(`\tdefault: %c${defaultStatus}`, consentStatusColor(defaultStatus));
    } else {
      console.log(`\tdefault: not found`);
    }
    
    // Check and log update status
    if (updateStatus !== "") {
      console.log(`\tupdate: %c${updateStatus}`, consentStatusColor(updateStatus));
    } else {
      console.log(`\tupdate: not found`);
    }
  }
    
  // Check and display 'wait_for_update' if it exists
  if ('wait_for_update' in consentEntries) {
    console.log(`%cwait_for_update`, 'font-weight: bold; font-size: 14px;');
    
    // Safely access the data layer for the initial configuration
    const initialConfig = window.dataLayer?.find(item => item[0] === 'consent' && item[1] === 'default');
    const waitForUpdate = initialConfig?.[2]?.wait_for_update ?? 'not found';
    
    // Apply a specific color to the wait_for_update value
    console.log(`\tdefault: %c${waitForUpdate}`, 'color: #FFA500'); // Using orange color as an example
  }
})();