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:
If your 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"
data-blockingmode="auto"
></script>
Then the code to implement in template.php should look like this:
<?php function theme_preprocess_html(&$variables) { $cookiebot = array( '#type' => 'markup', '#markup' => '<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid="00000000-0000-0000-0000-000000000000" type="text/javascript" data-blockingmode="auto"></script>' . "\n"
);
drupal_add_html_head($cookiebot, 'cookiebot_banner');
}
Once implemented the cookie banner will display on the visitor's first visit to your website, regardless of which entry page the visitor lands on.
Installation video:
Implementing prior consent on Drupal plugins and modules:
To enable prior consent (block cookies until the visitor has consented), apply the attributedata-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, ], 'google_analytics_tracking_script', ];
Make the following addition (highlighted) 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.:
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;
Comments
0 comments
Please sign in to leave a comment.