npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bootstrap-cookie-consent-settings

v4.1.5

Published

Settings dialog in Bootstrap 5 and framework to handle the EU law (may 2020) about cookies in a website

Downloads

35

Readme

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.

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, // the URL of your privacy policy page
    legalNoticeUrl: undefined, // the URL of you legal notice page (Impressum)
    contentURL: "/cookie-consent-content", // this folder must contain the language-files in the needed languages (`[lang].js`)
    buttonAgreeClass: "btn btn-primary", // the "Agree to all" buttons class
    buttonDontAgreeClass: "btn btn-link text-decoration-none", // the "I do not agree" buttons class
    buttonSaveClass: "btn btn-secondary", // the "Save selection" buttons class
    autoShowModal: true, // disable autoShowModal on the privacy policy and legal notice pages, to make these pages readable
    alsoUseLocalStorage: true, // if true, the settings are stored in localStorage, too
    postSelectionCallback: undefined, // callback function, called after the user has saved the settings
    lang: navigator.language, // the language, in which the modal is shown
    defaultLang: "en", // default language, if `lang` is not available as translation in `cookie-consent-content`
    categories: ["necessary", "statistics", "marketing", "personalization"], // the categories for selection, must be contained in the language files
    cookieName: "cookie-consent-settings",  // the name of the cookie in which the configuration is stored as JSON
    cookieStorageDays: 365, // the duration the cookie configuration is stored on the client
    modalId: "bootstrapCookieConsentSettingsModal" // the id of the modal dialog element
}

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();
// read all settings
$allSettings = $cookieSettings->getSettings();
// read a specific setting
$statisticsAllowed = $cookieSettings->getSetting("statistics");
// write a specific setting
$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.

bootstrap-cookie-consent-settings is a project of shaack.com.