Straight simple cookie consent popin using local storage
Simple and lightweight reusable cookie consent module for web dev
Here is the simplest way to init and use the cookie consent.
You can find more examples in the examples/ directory of this repo.
import Cooksent from 'cooksent';
const cooksent = Cooksent.factory();npm install cooksent
yarn add cooksent
Default values:
{
selector: 'js-cooksent',
btnSelector: 'js-cooksent__btn',
title: 'Cookie Consent',
description: 'By continuing your navigation without changing your cookie settings, you accept the use of cookies to analyse and measure audience, attendance, navigation and redirection from external websites.',
btnLabel: 'ok',
onConsent: () => {},
storageKey: 'COOKSENT',
}Main popin section class selector
Consent button class selector
Popin title
Popin description
Popin button label
Key used in local storage to memorise the user consent
onConsent expects a function that will be executed when the user clicks on the consent button.
cooksent/
├──src/ * our source files that will be compiled to javascript
| ├──app/ * Lib sources
│ │
| └──examples/ * examples sources
│ ├──index.pug * our index.html
│ │
│ ├──html/ * where you keep your pug templates
│ │ └──layout.pug * the main pug layout
│ │
│ └──app/ * JavaScript/ES2015 files
│
├──test/ * Jest test definitions
│
├──webpack/ * Webpack configuration files
│ ├──webpack.config.base.js * Base config
│ ├──webpack.config.js * Development overrides
│ └──webpack.config.prod.js * Production overrides
│
└──package.json * package.json
You need to install the following on you system
nodeandnpm- Ensure you running Node version >= 8.0.0
forkthe github repo https://github.com/gairal/cooksentcloneyour forknpm installto install all dependenciesmake startornpm startto start the dev server
After all dependencies are installed, just run make start to start a local server using webpack-dev-server which will watch your files and build them.
webpack-dev-server will display the address and port of your server (by default, http://0.0.0.0:3000).
# build files then launch the server and watch files
make start# build files in ./build/ (Webpack, Sass, Pug) and validate them
make build
# "compile" files in ./dist/
# minify and concatenate assets
make release# runs the validations eslint and jest tests
make test