Giter Site home page Giter Site logo

klarohq / klaro-js Goto Github PK

View Code? Open in Web Editor NEW
1.2K 31.0 243.0 14.1 MB

Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.

Home Page: https://klaro.org

License: Other

JavaScript 72.93% Makefile 0.26% Python 8.48% SCSS 18.33%
consent-management gdpr javascript consent cookie-consent eprivacy cookie react dsgvo cmp consent-management-platform ccpa klaro consent-manager user-consents trackers

klaro-js's Introduction

Klaro! A Simple Consent Manager

Klaro [klɛro] is a simple consent management platform (CMP) and privacy tool that helps you to be transparent about the third-party applications on your website. It is designed to be extremely simple, intuitive and easy to use while allowing you to be compliant with all relevant regulations (notably GDPR and ePrivacy).

Klaro supports multiple modes of asking for consent and can display third-party apps individually or grouped by purpose.

Advantages

  • Free and Open Source: No hidden fees, subscriptions or restrictions.
  • Easy to use: Simply add a small JS snippet and config to your site and you're ready to go!
  • Flexible and customizable: Manage consent for all possible types of third-party apps and easily customize the tool according to your needs.
  • Multilingual: Full internationalization support, with languages included out of the box. New translations can be added in just a few lines of code. Contributions welcome!
    Current languages: Catalan, Croatian, Dutch, English, Finnish, French, Galician, German, Greek, Hungarian, Italian, Norwegian, Romanian, Serbian (Latin and Cyrillic), Spanish, Swedish, Turkish
  • Small footprint: The minified+gzipped JS is only 37 kB and contains everything that is required, including style sheets and translations.
  • Intuitive and responsive: Klaro is designed to blend in with your existing design and optimized for modern desktop and mobile browsers.
  • Secure and reliable: Klaro ensures that no third-party apps or trackers are executed without the consent of the user, even when JavaScript is disabled or Klaro itself gets blocked.

Getting started

You can now find more extensive documentation on our website.

To use the widget on your website, simply embed Klaro as well as a valid config. You can have a look at the annotated config.js to see how it works. If you want to self-host Klaro you can download compiled JS files from the dist folder of this repository, or go to our website, where you can find a full list of past Klaro releases. Do not use the klaro.js file from the src folder, it will not work in the browser as it's an ES6 module and needs to be transpiled first (for most browsers at least). Follow the instructions below to adapt the config to your needs and then include the two files in your website like this:

<!-- make sure the config gets loaded before Klaro -->
<script defer type="text/javascript" src="config.js"></script>
<script defer type="text/javascript" src="https://cdn.kiprotect.com/klaro/[klaro-version]/klaro.js"></script>

You should replace [klaro-version] with a version number (e.g. v0.5.30) to download a specific version of Klaro. Important: We no longer update latest version tag in the CDN as loading Klaro from it might lead to breaking your installation when new major or minor versions are published. We will soon replace the tag with minor version tags (e.g. 0.7) that will receive automated security upgrades and bugfixes and can be safely used to embed Klaro without risking breaking changes.

Do not forget to change your existing apps/trackers as outlined in the next section as well, so that Klaro can manage them. By default, Klaro will automatically open once the page is fully loaded.

We also provide a version of Klaro without stylesheets included, which is useful in case you want to provide your own styles: klaro-no-css.js. If you use this, make sure to either include your own styles or to include klaro.min.css separetely, like this:

<link rel="stylesheet" href="https://cdn.kiprotect.com/klaro/[klaro-version]/klaro.min.css" />

We also provide a non-minified version of the stylesheet, which is great if you want to make your own version: klaro.css.

If you wish to open the consent manager manually on user interaction (for example through a link in the privacy policy), you can simply call klaro.show() via Javascript. Example:

<a class="button is-success" onclick="return klaro.show();">Change consent settings</a>

Calling klaro.show(undefined, true) will force the modal to open, even if the user hasn't made a consent choice yet (by default, the consent notice would open first).

Managing third-party apps/trackers

To manage third-party scripts and ensure they only run if the user consents with their use, you simply replace the src attribute with data-src, change the type attribute to text/plain and add a data-type attribute with the original type, and add a data-name field that matches the name of the app as given in your config file. Example:

<script type="text/plain"
    data-type="text/javascript"
    data-name="optimizely"
    data-src="https://cdn.optimizely.com/js/10196010078.js">
</script>

Klaro will then take care of executing the scripts if consent was given (you can chose to execute them before getting explicit consent as well).

The same method also works for images, stylesheets and other elements with a src or type attribute.

Managing third-party modules and libraries through Javascript API

Klaro offers a small but powerful Javascript API that allows you to control and monitor consent from your own apps. When loaded as an ordinary script, the API can be accessed via the global klaro project.

To manage third-party modules and libraries available within your app and ensure they only run if the user consents with their use, you can use the klaro ConsentManagerand native functions such as getConsent(name) replacing name with the name of the service you listed in your config.

Example:

let manager = klaro.getManager();
if (manager.getConsent('hotjar')) hotjar.initialize(HOTJAR_ID);

Configuration file

The consent manager is configured using a config dictionary, which you typically define in a separate JS file. To learn more, simply read the annotated example config, which contains descriptions of all valid config options and parameters.

Using Klaro via NPM

Klaro is also available as a Node.js module via npm:

npm install klaro

The npm distribution includes fully-fledged Klaro with CSS as well as the version without CSS (the CSS bundle is also included). In addition, it contains the consent management framework without the UI classes, which is handy in case you want to use your own UI classes:

// import Klaro with CSS
import * as klaro from 'klaro'

// import Klaro without CSS
import * as klaro from 'klaro/dist/klaro-no-css'

// import the accompanying CSS (requires style-loader)
import 'klaro/dist/klaro.css'

// import only the consent manager (no UI components)
import 'klaro/dist/cm'

This enables you to seamlessly integrate Klaro with your own JS projects, regardless if you use React, Vue, Angular, Mithril, Svelte or any other JS framework. Have a look at our webpack example to see a complete example.

Building Klaro from scratch

If you want to customize Klaro or extend it, you can build it from scratch using the following commands:

npm install
npm run-script make-dev #will run a development server
npm run-script make #will build the production version

If you have an environment where make is available, you can also run

make build 

Maintainers

To publish a new version of Klaro to NPM, simply run

make publish

To generate a new tagged release, simply run

make release [RT=patch|minor|major]

If no argument is given, a 'patch' release will be created. The release mechanism will not run if the working directory isn't clean. If it is, a Python script will increase the version number in the package.json file, rebuild the dist files, create a new commit and tag it with the version.

Contributing

Want to contribute? We'd love that!

If you have a feature request or bug to report, please fill out a GitHub Issue to begin the conversation.

If you want to help out, but don't know where to begin, check out the open issues tagged "help wanted".

If you are multilingual, consider contributing a translation we don't have yet.

License & third-party libraries

This project is licensed under a BSD-3 license. A list of third-party libraries can be found in the package.json file.

The accompanying website uses Bulma, Bootstrap and Prism and a surveillance camera image from Wikipedia.

Troubleshooting

Do you have problems using Klaro? If so, we want to know it! Just open an issue here and if possible provide the following information to us:

  • The website on which Klaro is installed (if possible)
  • The config file you're using (a link is sufficient)
  • The version of Klaro that you're using (you can get this by opening the developer tools of your browser, going to the "Console" tab and typing klaro.version() in the JS console.)

klaro-js's People

Contributors

abdullahceylan avatar adewes avatar amtee avatar anatolinicolae avatar axelchalon avatar bacanu avatar bhaveshsgupta avatar boldtrn avatar dependabot[bot] avatar dmnktoe avatar ensag-dev avatar ger4003 avatar giannisdag avatar hessius avatar jako avatar jaller94 avatar jmalarcon avatar josemmo avatar kazelot avatar kukac7 avatar leonexcc avatar manuhabitela avatar mrrfv avatar ribazoltan avatar rikharink avatar rmelchner avatar stefket avatar thmull avatar tooolbox avatar valstu 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

klaro-js's Issues

Change consent

Is there a way to open the klaro modal after accepting in the dialog? I would like this to have a button in the privacy policy to change consent at any time.

Language attribute

Hi seems that the app is checking language attribute like en or fr but in some case you need to use en-US - en-EN and fr-FR - fr-CA.

Would be nice if the function can split the lang attibute value and keep the first 2 chars to make it work with wordpress

Thanks

Custom stylePrefix

Hi

Where can we set the stylePrefix value for <div className={stylePrefix}>?

Thanks
Greg

Missing Translation

Hi

First thanks for this great job. I am running it locally without any issue. Unfortunately I have an issue in live on our own CMS. On notice I get [missing translation: ,purposes/[object Set],/,en,]

The rest works fine. Any idea what can be the cause?

Thanks
Greg

Does not work with requirejs

  • When loaded via script-tag klaro.js will not be executed at all when requirejs is in use
  • When loaded via requirejs, klaro.js does not work (document.currentscript is null).

Add sections to categorize cookies

As a user, I'd like to have all cookies organized in sections that I can open/collapse. E.g. Analytics, Communications, etc. If i click on the name of a section (e.g., Analytics), I can turn on/off all cookies in that section.

Updating to webpack 4

Hello,

I am thinking that we should update current version to weback 4? Do you support the idea.

klaro methods documentation?

Would be nice to have some documentation about the methods that klaro offers.

Looking around in the code is see methods that seem useful, but without documentation it's hard to see their use.

klaro.renderKlaro();
klaro.getManager().resetConsent();
klaro.show();
klaro.deleteCookie();

Opt-in script loaded on slider click

Hi

seems that opt-in scripts are loaded when enable apps (click the corresponding slider) and not when clicking on Save button from the cookies manager.

Step to reproduce:

  • Open https://klaro.kiprotect.com/
  • Open dev tools > application tab to see cookies
  • Click on Reset Consent (yellow button)
  • Disable all apps and save
  • Refresh page
  • Open manager (green button)
  • Enable all apps from Toggle all slider

This result by loading scripts and write cookies without the need to save!

Regards
Greg

Add "decline" button

It would be great to have a "decline" button on the consent notice, as this would allow users to opt out of all tracking with a single click.

Add a "disable all" button

It would be great to have a button that would allow users to opt out of all tracking without having to toggle each item separately.

App title translation

@adewes we can translate app description in config but it seems that we can't add app title translation. Am i wrong?

translations: {
    en: {
        security : {
            description: 'DDos attack protection',
            title: 'Website security' // Does not work
        }
    }
}

Separate css and js bundle

Helo,

Should we make css and js bundle into two files so that it becomes easy to configure/style whole app.

Grouped cookies (in modal)

In the cookie settings modal, is it possible to show the cookies in groups (by purpose) rather than a list of individual items?

Take a look at the Klaro demo...

1 - Visit https://klaro.kiprotect.com
2 - Click "Show Manager" (the green button)

There's many cookies (apps) listed, each with an individual control and lots of information.
However it's a flurry of data, with no high-level organization ie grouped categories. There's prominence given to brand labels, however users may or may not be familiar with the brands. Perhaps the most important information in the moment, "purpose", is a smaller font in dim grey and at the bottom of each item.

Do we expect users to sit and think about each individual app (or cookie)?

I think we're lucky that the user has decided to review their cookie settings. They are now actively engaged with the website experience. They should be rewarded with a pleasant experience, not a jarring storm of data.

So perhaps broad cookie groups and controls...

"Essential cookies" (greyed out, no choice)
"Analytics cookies"
"Advertising cookies"
"Miscellaneous cookies"
etc

And for more details, they simply look into each group where individual cookies could still be rendered with dense information and specific controls. Whether these child items are visible right away without having to open a group, I think it's determined case-by-case (how many cookies you have, etc).

Many major consent managers seem to do this UX already.

Some examples:
https://kinsta.com
https://www.onetrust.com

Disable Opt-in script behavior

Hi

When you add script with <script type="opt-in" data-type="text/javascript" data-name="any">, enable it from the modal will make it instantly active. But when you disable it, you need to refresh the page. Is it normal behavior?

Thx
Greg

Managing multiple analytics with single app

Hello,

We have multiple analytics for example Google Analytics, Hubspot and any other. We want to control all of these using single app. Such that single click would enable it and disable it.

Something like a single toggle for every analytical cookie.

Cookies not removed

Hi again

On this site all __utm cookies are not removed if you disable Web Analytics app

apps : [
        {
            name : 'analytics',
            default: true,
            onlyOnce: true,
            title : 'Web analytics',
            purposes : ['analytics'],
            cookies : ['__utma', '__utmb', '__utmc', '__utmt', '__utmz'],
            callback : function(consent, app){
                console.log("User consent for app "+app.name+": consent="+consent)
            },
            required : false,
            optOut : false,
        }
]

Do I miss something?
Thx
Greg

Understanding dist/configs/i18n.js better

Hello,

Currently we can update translations from main config file then what is use of this file dist/configs/i18n.js Can you please explain. Sorry I am trying to understand project better.

"Please enable cookies" Indicator

Hey guys, what do you think about an indicator, which will display a short text line like "please enable cookies", if the user has blocked cookies for this website. The indicator could be integrated into hidden iframes for example.

What do you think?

Multilanguage link - privacyPolicy

Hi!
First of all - thanks for great plugin!

I serach in examples, but with no luck, so my question is:
How to link a page with "Privacy settings" depending on language?

Example

     // Put a link to your privacy policy here (relative or absolute).
    privacyPolicy: 'https://domain.tld/privacy-policy/'

and for some other language should be:
privacyPolicy: 'https://domain.tld/hr/pravila-privatnosti/'

I tried something like this, but with no luck

translations: {
        hr: {
            privacyPolicy: 'https://domain.tld/hr/pravila-privatnosti/',
            consentModal: {
            ...

Thanks in advance for the answer!

Not understand config.js

Not sure what may come here (in place of klaro.kiprotect.com):
``// A list of regex expressions or strings giving the names of
// cookies set by this app. If the user withdraws consent for a
// given app, Klaro will then automatically delete all matching
// cookies.
cookies : [
// you can also explicitly provide a path and a domain for
// a given cookie. This is necessary if you have apps that
// set cookies for a path that is not "/" or a domain that
// is not the current domain. If you do not set these values
// properly, the cookie can't be deleted by Klaro
// (there is no way to access the path or domain of a cookie in JS)
[/^pk.$/, '/', 'klaro.kiprotect.com'], //for the production version
[/^pk.
$/, '/', 'localhost'], //for the local version
'piwik_ignore'],

Is place for the url of the site or the url of my matomo (e.g. www.mysite.com or e.g. analytics.my-matomo.com)

Also I don't understand clear how to deal with Google Analytics: it falls under inline tracker, external tracker or what? (anyway I found that the only cookies set by my site are related to Matomo, I found noting related to GA.

Thnx

Exclude default css (option)

Is there an option to exclude the default css? (style tag rendered in the document head).
Would be nice to do this by setting data-style-prefix on the script tag, or by setting an option in the config file?

How can I trigger "OK" button?

Hi,

Is it possible to trigger the event that runs when you click the OK button?

I tried with .click(); and simulate focus on button and then keypress/enter with no luck.
When I inspect the buttons there is no onClick attribute on the element.

Always display "X" icon in top-right, to close modal

An "X" icon appears in the top-right of the modal on mobile, however on desktop I don't see this icon as it has a hide class applied to it. Is there a configuration option for this?

I'm using the following CSS to override:

.klaro .cookie-modal .cm-modal .hide {
  display: block !important;
}

It works, however the original code already uses !important. So now there's !important overriding !important. Somehow this feels dirty?

Make Cookie-Domain and Path configurable

I would like to use the same consentmanager on several subdomains (www.foo, shop.foo) and share the settings. Would it be possible to make the cookie-domain of the klaro-cookie itself (cc-klaro) configurable?

klaroConfig = { elementID: 'cc-klaro', cookieName: 'cc-klaro', cookieExpiresAfterDays: 365, cookieDomain: '.foo', cookiePath: '/', ...

Cookies form iFrame

Hi

Is there a way to manage cookies set from an iFrame the ones set by YouTube when you embed a video?

Thanks
Greg

Inline HTML within descriptions

Is there a way to put inline HTML within descriptions?

For example:

        consentModal: {
                description:
                    'text <br /> text text text.'
            },

No custom styling possible?

I've applied the data attribute for a custom class but the required class is only applied to the little notice box at the bottom of the window, not the big modal. Which means it still has the old class, and also loads all the styles, which I can't overload without using !important which I'd really like to avoid... I can't give access to my dev environment but here's how I call the script:
<script defer type="application/javascript" src="/assets/js/klaro/klaro.js" data-config="klaroConfig" data-style-prefix="rs"></script>
Thanks for your help!

Privacy statements of the respective provider.

What about an option in the Klaro config to provide a link to the privacy policy of the respective provider, which are integrated next to the on/off toggles? Let's say you offer some YouTube & Font Awesome content - the user could see a link to the privacy policy of YouTube.

What do you think?

Domains for cookies on multilanguage website

Hi

Could you please show how we should handle Domains for cookies on multilanguage website
Should we add the cookie for each domain as following?

cookies : [
    ['__utma', '/', 'domain.fr'], ['__utma', '/', 'domain.com']
]

Thanks

Some suggestions

Hi,
thank you for that great Cookie-Script :-)
The last weeks I spent a lot of time with the DSGVO und Cookie-Boxes, like CookieConsent. I found your script, because I need a good solution for opt-in to implement in TYPO3.

Here are some suggestions from my side:
Link to PrivacyPolicy should be multilungual, because it could be in german '/de/datenschutz' and in english '/en/privacy-policy' and so on.

An option to disable the 'decline' button. At the moment it's working via CSS display. In some cases there are System-Cookies, that can't be disabled and some Tracking-Cookies, that can be disabled. When the user clicks on 'decline' or 'No Cookies' or something similar, only Tracking-Cookies are disabled, but the user thinks, that all cookies are disabled.

It would be good, if the link and text to privacy policy can be inserted in the text in the notice-box, like in the modal. So a user can go to the privacy policy without opening the model.

The option (target="_blank") to open the privacy policy link in a new window or tab would be good.

Many regards from Bavaria
Andi

How to use i18ns

Hi,

I found that exists translation for Romanian (in src/translations/ro.yml file), but I really don't understand how to use it.

How to - Newrelic?

How can I use Klaro with such a script? How should I load the script?

<script type="text/javascript"> window.NREUM||(NREUM={}),__nr_require=function(e,n,t){function r(t){if(!n[t]){var o=n[t]={exports:{}};e[t][0].call(o.exports,function(n){var o=e[t][1][n];return r(o||n)},o,o.exports)}return n[t].exports}if("function"==typeof __nr_require)return __nr_require;for(var o=0;o

I did try to use that code:

<script type="opt-in" data-type="application/javascript" data-name="newrelic"> //the script mentioned above </script>

But that doesn't work and the newrelic script do not load anymore.

It's also not clear how I should define the cookie which is JSSESSIONID on the domain bam.nr-data.net

It's this enough or should I had something for the domain?
{
name : 'newrelic',
title : 'Newrelic',
purposes : ['analytics', 'monitoring'],
cookies : ['JSESSIONID'],
},

Thanks

delete matomo cookies

Hi,
I am trying to delete matomo cookies but I cannot achieve that following the guide. I can only add the matomo cookies using the guide. I also tried the example with the inline tracker, and have the same results. I am also adding the config file. Also in https://klaro.kiprotect.com/ where you are using matomo, it also does not seem to work.

Idea: delete cookie on multiple common domains by default

Hi,

Sometimes it's a bit cumbersome to have to define cookie domain by hand for each app. Most scripts set their cookie on currentdomain.com or .currentdomain.com.

One idea would be:

  • if a domain is set in the cookies app config, do the same thing as before, ie try to delete the cookie with the given name and domain and that's it
  • if no domain is set in the cookies app config, to try to delete multiple cookies for the same cookie name, one for each domain.

The deleteCookie function could look like that:

export function deleteCookie(name, path, domain) {
    let cookieString = `${name}=; Max-Age=-99999999;${path !== undefined
        ? ` path=${path};`
        : ` path=/;`
    }`
    if (domain !== undefined) {
        document.cookie = `${cookieString} domain=${domain};`
        return;
    }
    // if domain is not defined, try to delete cookie on multiple default domains
    document.cookie = cookieString
    document.cookie = `${cookieString} domain=.${location.hostname};`
    // handle subdomains
    document.cookie = `${cookieString} domain=.${location.hostname.split('.').slice(-2).join('.')};`
}

Would you see any disadvantage of doing this? I know it's something tarteaucitron, a tool similar to Klaro, does and it works pretty well (see here).

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.