Implementing the Usercentrics consent banner in a Drupal site:
Add the attributes of your personal Usercentrics script tag for the consent banner to the file template.php in your theme folder.
If your Usercentrics script tag looks like this:
If your Usercentrics script tag looks like this:
<script
id="usercentrics-cmp"
src="https://app.usercentrics.eu/browser-ui/latest/loader.js"
data-settings-id="XXXXXXXXX"
async
></script>
Then the code to implement in template.php should look like this:
<?php function theme_preprocess_html(&$variables) { $usercentrics = array( '#type' => 'markup', '#markup' => '<script id="usercentrics-cmp" src="https://app.usercentrics.eu/browser-ui/latest/loader.js" data-settings-id="XXXXXXXXX" async></script>' . "\n"
);
drupal_add_html_head($usercentrics, 'usercentrics_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.
Implementing prior consent on Drupal plugins and modules:
To enable prior consent (block cookies until the visitor has consented), apply the attributedata-usercentrics
to all script tags that are setting cookies. The value of the attribute should be the name of the service that needs consent before loading.Finally, change the script tag attribute
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:
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 (bold highlight) to the code section and save the file:
$page['#attached']['html_head'][] = [ [ '#tag' => 'script', '#value' => $script, '#attributes' => array('type' => 'text/plain', 'data-usercentrics' => 'Google Analytics') ], 'google_analytics_tracking_script', ];
Usercentrics will now automatically activate the Google Analytics script for visitors who have consented to the use of Google Analytics.
Comments
0 comments
Please sign in to leave a comment.