Guide d'installation

Comment ajouter le consentement aux cookies à Drupal

Installation avec Composer, activation avec Drush, configuration via Configuration > Système > ConsentTrustee. Export de configuration, vidage du cache, nettoyage à la désinstallation.

Publié le

Comment ajouter le consentement aux cookies à Drupal

Drupal's module ecosystem and Composer-based install flow make adding a CMP feel different from the WordPress or Joomla equivalent — closer to a real software install than a plugin upload. That's mostly a good thing. This guide covers installing the ConsentTrustee Drupal module on Drupal 9, 10, and 11, configuring it for typical site setups, and the gotchas that come up in production.

Compatibility

ConsentTrustee's Drupal module supports Drupal 9.5+, Drupal 10.x, and Drupal 11.x. Drupal 7 and 8 are no longer supported by Drupal itself (end-of-life), and our module targets the current contrib API. PHP 8.1 or later is required (matches Drupal 10's minimum).

Install via Composer

The recommended install path for Drupal 9+ is Composer:

composer require consenttrustee/cookie-consent

This downloads the module to your modules/contrib/ directory and adds the dependency to your composer.json.

Then enable it:

drush en consent_trustee -y

Or via the Drupal UI: Extend → search for “ConsentTrustee” → check the box → Install.

Configuration

Once enabled, the module adds a configuration page at Configuration → System → ConsentTrustee. Fields:

Domain slug. From your ConsentTrustee dashboard. Required.

Google Consent Mode v2. Checkbox. Recommended if you run any Google Analytics or Ads.

Geo-targeting. Checkbox. Enable if you want region-specific banner behaviour (EU vs US).

Script blocking rules. List of URL patterns to auto-block. Useful for catching scripts injected by other modules that you can't modify directly.

Save the configuration. The module injects the CMP script via Drupal's standard hook_page_attachments() on every page render. To verify, load any page on your site in incognito and check the source for the ConsentTrustee script tag in <head>.

Config export with Drupal's config management

Drupal's config management exports module settings to YAML files, which is how teams version-control their site configuration. After configuring ConsentTrustee:

drush config:export -y

This writes the CMP configuration to config/sync/consent_trustee.settings.yml (or wherever your config sync directory is). Commit this to your repository.

On other environments, run:

drush config:import -y

...to import the same configuration. This is the standard Drupal workflow and the CMP module respects it fully — no manual configuration needed per environment.

Drush commands

The module ships with a few Drush commands for common operations:

  • drush ct:status — show current configuration and connection status to the CMP API.
  • drush ct:scan — trigger a cookie scan immediately (normally runs on a schedule).
  • drush ct:cache-clear — clear the local cache of the CMP configuration (force fresh fetch on next request).

Cache rebuild after config changes

Drupal aggressively caches rendered pages, blocks, and configuration. After changing the module configuration, rebuild the cache:

drush cr

Or via UI: Configuration → Performance → Clear all caches.

Without this, your old configuration stays in effect until the cache expires naturally. This trips up everyone the first time.

Script blocking for other Drupal modules

Drupal modules that inject tracking scripts (Google Analytics module, Matomo module, Facebook Pixel) need to be wired to respect consent. There are two patterns:

Option 1: Disable the module's script injection and add the script through ConsentTrustee. Most Drupal analytics modules have a setting to disable their built-in script. Disable it, then add the snippet through your ConsentTrustee dashboard's “Custom Scripts” with the appropriate category.

Option 2: Use the module's built-in consent integration if it has one. The Google Analytics module added a “Consent Mode” integration in v4.0. Enable it and point it at ConsentTrustee's event API. This works but requires both modules to be configured correctly and they don't always agree on what consent means.

For most Drupal sites, Option 1 is the simpler and more reliable choice.

Uninstall cleanup

If you remove the module, Drupal's standard uninstall flow removes the module files, but the ConsentTrustee configuration stays in the database unless you explicitly clear it.

To do a clean uninstall:

drush pmu consent_trustee -y
drush config:delete consent_trustee.settings

Then remove the package:

composer remove consenttrustee/cookie-consent

Common Drupal gotchas

Drupal's aggregation. Drupal's CSS/JS aggregation combines and minifies your assets. The CMP script is loaded from a CDN (not aggregated locally), so aggregation doesn't affect it. But if you've configured an external aggregation service like AdvAgg, verify it isn't accidentally pulling the CMP script through the aggregator.

Block placement. If your CMP renders a floating “Cookie settings” button (for re-opening preferences), it's placed via Drupal's block system. Configure it in Structure → Block layout and place in a region that's consistent across page types.

Permissions. Module configuration is permission-gated. By default only administrators can configure the CMP. If you want a separate “Privacy manager” role, grant the “administer consent trustee” permission.

Multilingual. Drupal's multilingual setup is more complex than WordPress's or Joomla's. The CMP detects the active language from Drupal's language manager and serves the matching banner translation. Make sure each language you serve has a translation in your ConsentTrustee dashboard.

What I'd read next

For the legal foundation, GDPR Cookie Consent. For the underlying script-blocking pattern, How to Block Third-Party Scripts. And for Google Consent Mode v2 if you run Google tags, Google Consent Mode v2.