bootstrap-cookie-consent-settings
A modal dialog (cookie banner) and framework to handle the EU law (as written by EuGH, 1.10.2019 – C-673/17)
about cookies in a website. Needs Bootstrap 5.
References
Usage
Construct
Initialize the cookie consent framework with the constructor
var cookieSettings = new BootstrapCookieConsentSettings(props)
You should configure the framework with the props
object, at least the properties privacyPolicyUrl
, legalNoticeUrl
and contentURL
. The default configuration is
this.props = {
privacyPolicyUrl: undefined,
legalNoticeUrl: undefined,
contentURL: "/cookie-consent-content",
buttonAgreeClass: "btn btn-primary",
buttonDontAgreeClass: "btn btn-link text-decoration-none",
buttonSaveClass: "btn btn-secondary",
autoShowModal: true,
alsoUseLocalStorage: true,
postSelectionCallback: undefined,
lang: navigator.language,
defaultLang: "en",
categories: ["necessary", "statistics", "marketing", "personalization"],
cookieName: "cookie-consent-settings",
cookieStorageDays: 365,
modalId: "bootstrapCookieConsentSettingsModal"
}
Show dialog
On a new visit the dialog is shown automatically.
To allow the user a reconfiguration you can show the Dialog again with
cookieSettings.showDialog()
Read the settings in JavaScript
Read all cookie settings with
cookieSettings.getSettings()
It should return some JSON like
{
"necessary": true,
"statistics": true,
"marketing": true,
"personalization": true
}
or undefined
, before the user has chosen his cookie options.
Read a specific cookie setting with
cookieSettings.getSettings('statistics')
for the statistics
cookie settings. Also returns undefined
, before the user has chosen his cookie options.
Read the settings from the backend
You can read the settings with all server languages, you just have to read the cookie cookie-consent-settings
.
The content of the cookie is encoded like a http query string.
necessary=true&statistics=false&marketing=true&personalization=true
PHP helper class
I provide a PHP helper class that you can use to read and write the settings from a PHP backend.
It is located in php/Shaack/BootstrapCookieConsentSettings.php
.
You can use it as described in the following example.
$cookieSettings = new \Shaack\BootstrapCookieConsentSettings();
$allSettings = $cookieSettings->getSettings();
$statisticsAllowed = $cookieSettings->getSetting("statistics");
$cookieSettings->setSetting("statistics", false);
Internationalization
You find the language files in ./cookie-consent-content
. You can add here language files or modify the existing. If
you add language files please consider a pull request to also add them in this repository. Thanks.
Disclaimer
You can use this banner for your website free of charge under the MIT-License.
The banner and framework was designed in cooperation with data protection officers and lawyers. However, we can not
guarantee whether the banner is correct for your website and assume no liability for its use.
Find more high quality modules from shaack.com
on our projects page.