This is an old revision of the document!
Table of Contents
Cookie Consent
Available starting with VuFind 9.0.
The cookie consent prompt and settings allow the user to be informed about cookies used by the service and manage consent for non-essential cookies.
Configuration
The configuration for enabling cookie consent is in the Cookies section of config.ini. It contains the settings to turn on cookie consent and select the categories to display and allow toggling in the cookie settings dialog.
Cookie categories and further configuration is in CookieConsent.yaml. See the comments in the file and the sample configurations below for further information.
Note that if enabled categories or cookies in the categories are changed, the consentRevision setting in config.ini should be incremented. This makes VuFind re-request consent. There is also popup_revision_message_html
translation string that allows you to add a message for those that have previously consented but are now prompted again because of the new revision.
Language Translations
Most text strings used in the cookie consent component have translations in the CookieConsent text domain.
Information for Developers
Checking for Consent
You can check for user's consent in phtml templates:
<?php if ($this->cookieConsent()->isEnabled():?> <?php if ($this->cookieConsent()->isCategoryAccepted('essential')):?> Essential category is accepted (as it should be)! <?php endif; ?> <?php if ($this->cookieConsent()->isServiceAllowed('matomo')):?> Matomo service is allowed! <?php endif; ?> <?php endif; ?>
You can also check consent in JavaScript:
if (VuFind.cookie.isCategoryAccepted('essential')) { ... } if (VuFind.cookie.isServiceAllowed('matomo')) { ... }
JavaScript Events
The following events are emitted:
Event | Description |
---|---|
cookie-consent-done | User has clicked on any of the consent buttons |
cookie-consent-change | User has changed their consent |
cookie-consent-initialized | Cookie consent service has been initialized |
Sample Configurations
VuFind comes with cookie consent category configuration for the built-in cookies and Matomo. The following sample configurations can be added to CookieConsent.yaml (typically in local/config/vufind directory) for additional services. The samples only include the relevant parts for the service, so merge them with the full configuration as required.
Since these are third-party services, you will need to verify that the sample configurations are up to date and suitable for the region.
Note that the sample configuration have all the texts in English. The texts can be replaced with translation strings for multi-language support.
YouTube
At least expiration times may differ depending on region.
The following configuration including the IframeServices part allows you to display videos based on user consent. If the user has allowed the cookies for the category, videos are automatically displayed. If not, the user gets a prompt instead. For this to work, the video must be embedded on the page like this (data-id is the identifier of the video in YouTube):
<html> <div class=“iframemanager” data-service=“youtube” data-id=“5q70TokaSrw”></div> </html>
You can also check if iframe manager is active:
<?php if ($this->plugin('cookieConsent')->isIframeManagerActive()): ?> <div style="width: 560px; height: 315px" class="iframemanager" data-service="youtube" data-id="5q70TokaSrw"></div> <?php else: ?> <iframe width="560" height="315" src="https://www.youtube.com/embed/5q70TokaSrw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <?php endif; ?>
CookieConsent.yaml:
CookieConsent: Categories: video: Title: Cookies for embedded video Description: Cookies set by video platforms when you view embedded media. DefaultEnabled: false Essential: false ControlIframeServices: - youtube Cookies: - Name: yt-player-bandwidth Domain: youtube.com ThirdParty: true Description: Used to estimate bandwidth. Expiration: session - Name: yt-player-headers-readable Domain: youtube.com ThirdParty: true Description: Used to store user's preferences. Expiration: session - Name: GPS Domain: youtube.com ThirdParty: true Description: Used to store user's location. Expiration: session - Name: VISITOR_INFO1_LIVE Domain: youtube.com ThirdParty: true Description: Used to estimate bandwidth. Expiration: 6 ExpirationUnit: months - Name: PREF, __Secure-YEC Domain: youtube.com ThirdParty: true Description: Used to store user's preferences. Expiration: 8 ExpirationUnit: months - Name: YSC, CONSENT, SOCS Domain: youtube.com ThirdParty: true Description: Used to track user's actions for marketing purposes. Expiration: 8 ExpirationUnit: months AutoClearCookies: - Name: '/^(yt-player-.*|GPS|VISITOR_INFO1_LIVE|PREF|__Secure-YEC|YSC|CONSENT|SOCS)$/' IframeServices: youtube: EmbedUrl: 'https://www.youtube.com/embed/{data-id}' #ThumbnailUrl: 'https://i3.ytimg.com/vi/{data-id}/hqdefault.jpg' IframeAllow: accelerometer; encrypted-media; gyroscope; picture-in-picture; fullscreen Description: This content is loaded from https://www.youtube.com. Your consent to store cookies placed by YouTube is required to view the content. AllowOnceText: Show video AllowAlwaysText: Show video and always allow embedded YouTube content
Iframe Manager
If you use iframe manager (like in the YouTube video example above), add this to the essential
category:
- Name: 'cc_*' Domain: '{{vufind_cookie_domain}}' Description: CookieConsent::cookie_description_consent_html Expiration: '{{consent_cookie_expiration}}' ExpirationUnit: days