GithubHelp home page GithubHelp logo

aoepeople / cookie-notice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from micc83/cookie-notice-js

74.0 7.0 23.0 323 KB

CookieNotice — a very simple and small (2kb gzipped) vanilla JavaScript cookie notice for GDPR/DSGVO‎ information purposes. Multi language support and detection buillt in.

License: MIT License

JavaScript 92.70% HTML 7.30%
gdpr dsgvo customizable language-detection cookie disclaimer javascript notice notifications cookie-notice cookie-notification

cookie-notice's Introduction

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

cookie-notice's People

Contributors

andreacomplus avatar bernhardbehrendt avatar micc83 avatar nfreear avatar schroedermatthias avatar vjandrea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookie-notice's Issues

Move styles to separate stylesheet, included via Javascript

Hi @BernhardBehrendt,

As I said previously (#4), I think it would be beneficial to move the CSS styles from style HTML attributes, to a separate stylesheet.

The stylesheet would be injected/ included via Javascript.

Benefits:

  1. Easier to override styles;
  2. Possible to style on-focus and on-hover;
  3. (Possible to lint/ validate the CSS).

This involves changes to the API ... the following configuration options would no longer work:

  • buttonBgColor
  • buttonTextColor
  • noticeBgColor
  • noticeTextColor
  • linkColor

So, it will probably require a major version increment (semver).

I'll do a pull request shortly, and you can see what you think!

Yours,

Nick

Remove link to demo

Hello @AOEpeople,

Unfortunately the demo at codeb.it is not there anymore as I dismissed it.
You can update the demo url in the readme file.

'data-cookie-notice' HTML attribute, other suggestions / wishlist

Hi,

I've got some suggestions for improvements that I hope will benefit most users ... I'll create pull requests as I work through some of these.


Proposed changes / "wishlist"

  1. DONE. Allow configuration options to be set via JSON in a data-cookie-notice HTML attribute on a <script> element, pull #5;
  2. DONE. Add Travis-CI build and test (qunit etc.), pull #1, #2;
  3. — Add semistandard / ESLint-type tests — Flet/semistandard;
  4. — Accessibility testing and fixes, using e.g. pa11y-ci or grunt-rsids-pa11y;
  5. — Move CSS from style attribute to <style> element, or separate stylesheet — create <style> or <link> via the Javascript — make it easier to override styles;
  6. — Document use of a CDN, e.g. https://unpkg.com in the README;
  7. — Improve the language used in the English translation ;);
  8. … ?

Aims

While working on the proposed fixes, the aim is to:

  1. Maintain the current small size of the Javascript — as near as possible (currently 3.36 kB minified; 9.1 kB un-minified);
  2. Keep the existing straightforward Javascript-based API;
  3. New easy-to-use non-Javascript API (data attribute);

See notes on Google Docs.


Example HTML

Here is an example of using the proposed data-cookie-notice attribute:

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

Link to the fork on the main repo and some advise about GDPR compliance.

Hi,
Sorry if I didn't show up before. I've linked your fork on CookieNoticeJS readme file.

Also, about GDPR compliance, In order for the script to be an all-in-one solution for handling Cookies acceptance it should have some way to block cookie injecting scripts on page first load (or at least the most common ones: analytics, facebook, tripadvisor, gmaps, etc... with some way to add custom ones) and eventually load them when the policy is accepted (by clicking on the ACCEPT button or, as long as permitted by GDPR, by scrolling the page). Hope that helps.

Cheers

Suggestion - Add pt language

Hi there, sorry, I do not know how to contribute to open source projects, but if you wish to add Portuguese language here is the translation you need:

Line 25 of cookie.notice.js:

pt: 'Utilizamos cookies para garantir que você tenha a melhor experiência em nosso site. Se você continuar a usar este site, assumimos que você aceita isso.'

Line 39 of cookie.notice.js:
pt: 'Saber mais'

Congratulations for the excellent code!

Make font configurable

Hi,

wouldn't it make sense to have the font configurable as well?

Best regards
Norbert

Build workflow, tags, changelog, Travis-CI deploy ..

Hi @BernhardBehrendt,

(Duplicated from ~ micc83#3)

I've got some suggestions, to help make the most of your work:

  1. It's fairly standard to do a git tag -a (annotated) at the same time as npm publish — it becomes easier to track what commits are in each npm release ;);
  2. Better still, add a changelog either at AOEpeople/cookie-notice/releases, or even as a CHANGELOG.md document (I'm happy to help with the document — easier to collaborate?);
  3. I think that three of the deploy steps have silently failed (see Travis-ci: AOEpeople/cookie-notice job # 38...934 ~ ".. npm ERR! You cannot publish over the previously published versions: 1.1.10. : cookie-notice" (I don't know enough about deploy to suggest a fix, sorry!)
  4. You may not want/need to test against 4 Node versions (would help with point '3'!), as cookie-notice is for the browser ~ perhaps just "8" and stable? (You could use the engines field in package.json to specify.) Node.js versions are moving quickly now!
  5. Is there a danger with running grunt test (not grunt [default]) on Travis-CI that you/we forget to build the latest version before deploying?
  6. You may want to review this CDN ~ https://unpkg.com/cookie-notice/, to see what is included in an npm release (filter with the files field in package.json).

Note, I'll create an issue / pull requests for them ... but here is my wishlist.

I hope this all helps!

Best wishes,

Nick

(For review before #2.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.