Drupal installation

Please note that this is no longer being updated. Kindly visit the new Cookiebot support area (https://support.cookiebot.com/hc/en-us) for updated guides, articles and FAQs. If you do not find the answer to your question there, you are welcome to post it in the Cookiebot community (https://support.cookiebot.com/hc/en-us/community/topics).

Implementing the Cookiebot consent banner in a Drupal site:


Add the attributes of your personal Cookiebot script tag for the consent banner (available under the tab "Your scripts" in the Cookiebot Manager) to the file template.php in your theme folder.

If you Cookiebot script tag looks like this: 

<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid="00000000-0000-0000-0000-000000000000" type="text/javascript" async></script>

Then the code to implement in template.php should look like this:

function theme_preprocess_html(&$var) {
  $script = array(
    '#tag' => 'script',
    '#attributes' => array('type' => 'text/javascript', 'id' => 'Cookiebot', 'src' => 'https://consent.cookiebot.com/uc.js', 'data-cbid' => '00000000-0000-0000-0000-000000000000')
  );
  drupal_add_html_head($script, 'script');
}

The cookie banner will now display on the visitor's first visit to your website, regardless of which entry page the visitor lands on.

Implementing prior consent on Drupal plugins and modules:

To enable prior consent (block cookies until the visitor has consented), apply the attribute "data-cookieconsent" to all script tags that are setting cookies. The scan report in Cookiebot will show you which script tags are setting cookies, including the source code position of the relevant script tags.

On each relevant script tag, set the comma-separated value of the attribute "data-cookieconsent" to one or more of the three types of cookies: "preferences", "statistics" and "marketing" in accordance with the types of cookies being set by each script, which is also stated in the scan report.

Finally change the script tag attribute "type" from "text/javascript" to "text/plain".


Example on the Google Analytics Module:

Edit the module code directly by opening the module file "google_analytics.module".

Locate the following code section in the file:

$page['#attached']['html_head'][] = [
  [
      '#tag' => 'script',
      '#value' => $script,
  ],
  'google_analytics_tracking_script',
];

Make the following addition (yellow markup) to the code section and save the file:

$page['#attached']['html_head'][] = [
  [
      '#tag' => 'script',
      '#value' => $script,
      '#attributes' => array('type' => 'text/plain', 'data-cookieconsent' => 'statistics')
  ],
  'google_analytics_tracking_script',
];

Cookiebot will now automatically activate the Google Analytics script for visitors who have consented to all or at least 'statistics' type cookies.

Showing your cookie declaration in full on a specific Drupal page:

If you want to show your cookie declaration in full on a separate page or as part of your privacy policy, embed your cookie declaration script tag (the second script tag found in Cookiebot's Manager) as described below.

In the content editor for the page where you want to display your cookie declaration in full, switch to html/source view mode and paste the script code at the position in the content where you want the declaration to display,
 e.g.:

<script id="CookieDeclaration" src="https://consent.cookiebot.com/00000000-0000-0000-0000-000000000000/cd.js" type="text/javascript" async></script>

If you are using a rich text/WYSIWYG editor, the script above may be stripped out when saving the page. To avoid this behavior you need to enable JavaScript in the editor, e.g. for the CKEeditor, add the following setting to the configuration section "{...}" of the file "plugins.js" in /sites/all/libraries/ckeditor:

config.allowedContent = true;

Feedback and Knowledge Base