philippG777 / cookieyesno

Easy to use GDPR-compliant cookie-banner
Other
4 stars 1 forks source link
banner consent cookie-banner cookie-banner-javascript cookie-banners cookie-consent cookie-law gdpr gdpr-compliant gdpr-consent gdpr-cookie gdpr-cookies hacktoberfest

CookieYesNo

An easy to use GDPR-compliant cookie-banner

Cookiebanner Screenshot

✅ GDPR-complient

✅ Easy to Use

✅ Mobile friendly

✅ Small memory footprint

✅ Highly customizable

Usage

The banner on the screenshot above has been created using only the 14 lines you can see below.

var cyn = new CookieYesNo({
  categories: {
    required: {
      name: 'Required cookies',
      description: 'These cookies are necessary for the website to function properly',
      accepted: true,
      changeable: false
    },
    analytics: {
      name: 'Web analytics',
      description: 'These cookies are used to analyze the user\'s behavior.'
    }
  }
});

Documentation

Configuration

The configuration is the only argument of new CookieYesNo(config) and is a map, The following things can / have to be configured:

Category configuration

Each cookie category is an item in the categories-Map. Here a short example:

categories: {
  required: {
    name: 'Required cookies',
    accepted: true,          // preselected
    description: 'These cookies are necessary for the website to function properly.',
    changeable: false       // user can not change this option
  },
  analytics: {
    name: 'Web Analytics',
    description: 'These cookies are used to analyze the user\'s behavior.'
  }
}

Configuration possibilities of a category

Script blocking

Blocking external scripts

You have to replace src with data-cyn-src and have to set the type to text/plain. The data-cyn-require attribute specifies which cookie category has to be allowed to run the script. So analytics has to be the key of the Web Analytics category in the categories map.

<script type="text/plain" data-cyn-src="https://github.com/philippG777/cookieyesno/raw/master/analytics.js" data-cyn-require="analytics"></script>

Blocking inline scripts

Caution: May not block the execution of the script in older Firefox versions! External script blocking (above) is safe to use as well as Events (below). Use these medthods instead. The type attribute has to be set to text/plain. The script will be executed when the category with the key analytics is allowed.

<script type="text/plain" data-cyn-require="analytics">
  // YOUR CODE HERE
</script>

Events

Note: the category argument in the methods below is the key of the specific category in the categories map in the configuration map.

onAccept(category, callback)

Callback function gets executed when the specified category gets acceped.

onReject(category, callback)

Callback function gets executed when the specified category gets rejected. Explicitly return false if you don't want to reload the site. This can also be done by the config. If you like to reload the page either return nothing or return true.

onChange(category, callback)

Callback function gets executed when the specified category gets changed. The first argument of the callback function is a Boolean that states if the category has been accepted (true) or rejected (false).

First the onChange callbacks are executed, then the scripts are activated if necessary and then onAccept and onReject callbacks are executed.

Other methods

getSettings()

Get the current cookie settings as a map.

reviewSettings()

Let the user review his consent.

show()

Show the cookie banner.

hide()

Hide the cookie banner.

Link placeholders

Link placeholders can be used in the text.above and text.below. Simply put PRIVACY_POLICY, COOKIE_POLICY, or IMPRINT in the String. These will be replaced with the matching links. Note: In order to use this feature you have to specify the links in the configuration.

Modify the banner

It's pretty simple: just use CSS-rules. The following classes are available:


Based on https://github.com/rollup/rollup-starter-app and https://github.com/rollup/rollup-starter-lib (both MIT License) Take a look at LICENSE_ROLLUP_STARTER_APP and LICENSE_ROLLUP_STARTER_LIB.