/
Integration of a cookie configuration

Integration of a cookie configuration

Once your banner is created and customised, code is generated to be integrated into a website. This code is visible in the Tags to be integrated panel:

Contents of this documentation:

WordPress

  1. Install the "Insert headers and footers" extension (https://wordpress.org/plugins/insert-headers-and-footers/) on WordPress.

  2. Once the extension has been installed and activated, copy and paste the code to be included in the "head" section of the extension.

Drupal

  1. In your Drupal site root folder, create a "module" folder;

  2. In the "module" folder, create a "myLibrariesLoader" sub-folder;

  3. In the "myLibrariesLoader" folder, create 3 files as shown below:

    1. myLibrariesLoader.info.yml to declare the module, which must be in the "Custom" package;

    2. myLibrariesLoader.libraries.yml to declare the script tags that will be added to the pages (details below);

      tarteaucitron: version: 1.x header: true js: <url de tarteaucitron (1ère balise du panel d'intégration)>: { external: true } tac_config: version: 1.x header: true css: theme: <url du style personnalisé (3ème balise du panel d'intégration)>: { external: true } js: <url de la configuration personnalisée (2ème balise du panel d'intégration)>: { external: true } dependencies: - myLibrariesLoader/tarteaucitron
  • myLibrariesLoader.module to activate the module and make it use the 2 libraries. Note that the file must begin "<?php", without spaces or line breaks before.

    <?php function myLibrariesLoader_page_attachments(array &$attachments) { $attachments['#attached']['library'][] = 'myLibrariesLoader/tarteaucitron'; $attachments['#attached']['library'][] = 'myLibrariesLoader/tac_config'; }

These three files must have the same name as the folder in which they are located.

Details of myLibrariesLoader.libraries.yml:

  • The tarteaucitron library is declared first because it serves as a dependency on the "tac_config" library;

  • The sources are retrieved via the links provided in "js" parameters: tarteaucitron is retrieved on an official CDN and "tac_config" is the generated configuration file;

  • The 2 libraries have the parameter "header: true" to force the addition of script tags in the <head> of the html pages;

Once these three files have been created, go to the Extensions tab of the Drupal site admin console, then look for the name of the module (here myLibrariesLoader) in the search bar. The module should appear in the list: check the checkbox and then click "Install".

Finally, click on the "update script" link in the text banner at the top of the Extensions page. You will need to click on this link each time the module files have been modified.

To find out more