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.
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 your Cookiebot script tag looks like this:
Then the code to implement in template.php should look like this:
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 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.
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 (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') ], '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:
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.:
config.allowedContent = true;