Drupal 7 implementation

Please note: This article was originally drafted to help implement Cookiebot prior to the release of the automated cookie control functionality on September 10th 2019.
You may still be using and preferring the manual implementation and markup option. In that case this article may still be relevant for you.

For automatic cookie blocking make sure that your cookie consent banner script includes the data attribute data-blockingmode=”auto” and that “async” is removed from the script example below.

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 your Cookiebot script tag looks like this: 

<script id="CookieConsent" 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' => 'CookieConsent', '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.

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 Cookiebot scan report 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,

Make the following addition (bold highlight) to the code section and save the file:

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

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

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="CookiePolicy" 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;

30 day free trial Cookiebot

Cookie scanner, cookie banner, cookie declaration en cookie consent in one solution.

  • Use cookies on your website compliant with GDPR, ePrivacy and cookie legislation
  • Cookiemanagement completely automated
  • Cookie banner based on your corporate identity
  • Automatic composed cookie declaration, always up to date

De Cookiebot solution runs on 350,000+ websites, manages 8,7 billion User Consents and supports 40+ languages. CookieInfo is the largest Cookiebot partner in Europe.