Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cookie-notice

AOEpeople1.9kMIT1.3.9

A very simple configurable and small (4.5kb / 2kB gzipped) vanilla JS lib with out of the box multi language support [it, en, fr, pt, es, nl, de, pl] for GDPR/DSGVO and notification purposes

GDPR, DSGVO, customize, cookie, banner, cookiebanner, cookie-banner, cookienotice, cookie-notice, notice, vanilla, js, javascript

readme

Build status — Travis-CI cookie-notice on Npmjs License Total downloads ~ Npmjs Size of Javascript

CookieNotice

CookieNoticeJS is a very simple, extendable and small (→ 2 kB gzip) vanilla JS script with multi language support for GDPR/DSGVO‎ transparency and notification purposes that provides an easy way to show a cookie notice on your website.

Cookie notice at the bottom of the page cookie notice working example

Cookie notice at the top of the page cookie notice working example

Available via npm

npm install cookie-notice
npm test

To use in your project There are plenty ways for integration:

When installed via npm, include in any project by using path below:


<script src="node-modules/cookie-notice/dist/cookie.notice.min.js"></script>

For usage with Angular2+ add line below in "scripts" section in angular-cli.json:

{
    "scripts": [
        "../node_modules/cookie-notice/dist/cookie.notice.js",
        "../optional/path/to/custom/cookie-notice-config.js"
    ]
}

When cloned directly from gitHub use path below:


<script src="cookie-notice/dist/cookie.notice.min.js"></script>

Behavior

You will get a dismissable banner on the bottom of your pages showing a default cookie audit like the following:

We use cookies to make sure you can have the best experience on our website. If you continue to use this site we assume that you will be happy with it.

You can check out an example integration at Deutsche Telekom.

Depending on the visitor browser language one of the preloaded translations will be shown. At the moment ** CookieNoticeJS** supports following languages out of the box:

  • IT (Italiano)
  • EN (English) default
  • FR (Français)
  • PT (Português)
  • ES (Español)
  • NL (Nederlands)
  • DE (Deutsch)
  • PL (Polski)

You can also add any other language code

If you want to contribute with an extra language or find translation issues do not hesitate to open an issue or a PR.

CookieNoticeJS has been successfully tested on IE9+, Chrome, Firefox and Safari.

Customize CookieNoticeJS

For the most of you including the script should be enough but CookieNoticeJS comes with many customization options. Let's see an example:


<script src="js/cookie.notice.min.js"></script>
<script>
    new cookieNoticeJS({

        // Localizations of the notice message
        'messageLocales': {
            'it': 'Custom localized message'
        },

        // Localizations of the dismiss button text
        'buttonLocales': {
            'it': 'Chiudi'
        },

        // Position for the cookie-notifier (default=bottom)
        'cookieNoticePosition': 'top',

        // Shows the "learn more button (default=false)
        'learnMoreLinkEnabled': false,

        // The href of the learn more link must be applied if (learnMoreLinkEnabled=true)
        'learnMoreLinkHref': '/learn/more/index.html',

        // Text for optional learn more button
        'learnMoreLinkText': {
            'en': 'learn more'
        },

        // The message will be shown again in X days
        'expiresIn': 30,

        // Specify a custom font family and size in pixels
        'fontFamily': 'inherit',
        'fontSize': '12px',

        // Dismiss button background color
        'buttonBgColor': '#d35400',

        // Dismiss button text color
        'buttonTextColor': '#fff',

        // Notice background color
        'noticeBgColor': '#000',

        // Notice text color
        'noticeTextColor': '#fff',

        // the learnMoreLink color (default='#009fdd')
        'linkColor': '#f00',

        // The target of the learn more link (default='', or '_blank')
        'linkTarget': '',

        // Print debug output to the console (default=false)
        'debug': false
    });
</script>

Configuration via data- attribute

Configuration options can be put in a data-cookie-notice HTML attribute in JSON format. Note, you can include the Javascript from the unpkg CDN (browse). For example:


<script
    data-cookie-notice='{ "learnMoreLinkEnabled": true, "learnMoreLinkHref": "/privacy.html" }'
    src="https://unpkg.com/cookie-notice@^1/dist/cookie.notice.min.js"
></script>

Author

Alessandro Benoit

Contributors

License

License: MIT

changelog

CookieNotice changelog

README

Version History

Version 1.3.4

  • Date: 24 November 2020
  • Changed default font size handling
  • New demo page
  • new languages (pl, es, nl)
  • configuration examples (images)

Version 1.1.19

  • Date: 09 July 2020
  • Added fontSize customization, with fallback to 12px if unset

Version 1.1.18

  • Date: 01 January 2019;
  • Step back to px based font sizes due to negative side effects

    Version 1.1.17

  • Date: 15 December 2018;
  • Accessibility (a11y) improvements - fixed all WCAG2AA errors and warnings

Version 1.1.16

  • Date: 12 December 2018;
  • Initial font size too small

    Version 1.1.14/15

  • Date: 6 December 2018;
  • Typo in German translation -> contrib. by @chroedermatthias (Matthias Schröder)
  • Dependency upgrade
  • Fixed unit tests

Version 1.1.12

  • Date: approx. 4-6 June 2018;
  • Add accessibility testing via grunt-rsids-pa11y and pa11y, WCAG 2.0 AA, pull #6;
  • Accessibility fixes — colour contrast, button role, link target, link underline;
  • Accessibility fixes — express CSS font-size in em or rem, not px;
  • Add configuration option — linkTarget (default: '');
  • Edit the language used in the English translation;
  • Fix browser and repository fields in package.json;
  • Add files and bugs fields to package.json;
  • Add engines and contributors fields to package.json;
  • Add live-server to peerDependencies in package.json;
  • Remove Nick's email address from README & bower.json (!)

Version 1.1.11

  • Date: 30 May 2018;
  • Add support for data-cookie-notice attribute on <script>, pull #5, issue #4;
  • Document data- attribute in README;
  • Document unpkg CDN in README;

Version 1.1.10

  • Date: 29 May 2018;
  • Move jQuery to devDependencies for clarity, pull #2;
  • Point tests/index.html to local copies of jQuery and QUnit (was CDN);

Version 1.1.9

  • Date: 25 May 2018;
  • Add Travis-CI testing to the project, pull #1;
  • Update test dependencies — jQuery from 2.x → 3.x; QUnit from 1.x → 2.x;
  • Add SVG badges for Travis-CI, NPMJS.com, etc. to README.md;

Version 1.1.8

  • Date: 25 May 2018;

Version 1.1.7

  • Date: 25 April 2018;

...

Version 1.1.0

  • Date: 24 April 2018;
  • First release on npm;

Version 1.0.0

  • Date: 20 May 2015;
  • Release by: @micc83;
  • (Not on npm)

README