All Projects → netgen → javascript-cookie-control

netgen / javascript-cookie-control

Licence: other
Javascript module for controling cookie consent on your website

Programming Languages

javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to javascript-cookie-control

open-pryv.io
open source version of Pryv.io
Stars: ✭ 106 (+488.89%)
Mutual labels:  consent, gdpr
Klaro
Klaro! A privacy and security tool for your website.
Stars: ✭ 640 (+3455.56%)
Mutual labels:  cookie, gdpr
gdpr-cookie
Php Cookie checker for Analytics and Tawk.To (GDPR Compliance)
Stars: ✭ 21 (+16.67%)
Mutual labels:  cookie, gdpr
Simple Cookie Choices
A simple cookie choices thought to the GDPR rules 🔒🍪
Stars: ✭ 12 (-33.33%)
Mutual labels:  cookie, gdpr
silverstripe-cookie-consent
GDPR compliant cookie popup and consent checker
Stars: ✭ 16 (-11.11%)
Mutual labels:  cookie, gdpr
PolishCookieConsent
Polish Cookie Consent is an extension, which automatically accepts privacy policy/GDPR on websites.
Stars: ✭ 17 (-5.56%)
Mutual labels:  cookie, gdpr
Cookies Eu Banner
1kb vanilla JS script which manages cookies consent banner display like asked by GDPR
Stars: ✭ 326 (+1711.11%)
Mutual labels:  cookie, gdpr
Cookiescanner
Cookie Scanner for GDPR compliance
Stars: ✭ 126 (+600%)
Mutual labels:  cookie, gdpr
privera
Use the tools you know. Respect users' privacy. Forget cookie consents. Comply with GDPR, ePrivacy, COPPA, CalOPPA, PECR, PIPEDA, CASL; you name it.
Stars: ✭ 23 (+27.78%)
Mutual labels:  cookie, gdpr
react-cookie-law
React Cookie Law is a cookie-info banner compliance with the GDPR and the EU cookie law. It allows the user to give consent in a granular way.
Stars: ✭ 103 (+472.22%)
Mutual labels:  cookie, gdpr
GDPRConsent
No description or website provided.
Stars: ✭ 80 (+344.44%)
Mutual labels:  consent, gdpr
summary1
个人总结 持续更新 欢迎提出各种issues
Stars: ✭ 13 (-27.78%)
Mutual labels:  cookie
enhanced-privacy
Magento 2 Enhanced Privacy extension for easier compliance with GDPR. Allows customers to delete, anonymize, or export their personal data.
Stars: ✭ 45 (+150%)
Mutual labels:  gdpr
c3
𝗖𝟯 provides compliant AWS CDK components to various security standards.
Stars: ✭ 24 (+33.33%)
Mutual labels:  gdpr
virgil-crypto
Virgil Crypto is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant. Crypto Library is written in C++, suitable for mobile and server platforms and supports bindings with: Swift, Obj-C, Java (Android), С#/.NET, …
Stars: ✭ 74 (+311.11%)
Mutual labels:  gdpr
next-fauna-auth
Implemented cookie-based user authentication in a Next.js, FaunaDB and GraphQL app
Stars: ✭ 29 (+61.11%)
Mutual labels:  cookie
http
Aplus Framework HTTP Library
Stars: ✭ 113 (+527.78%)
Mutual labels:  cookie
lookie
Store your data in localStorage with optional expiration time. Almost like a cookie.
Stars: ✭ 78 (+333.33%)
Mutual labels:  cookie
host-webfonts-locally
OMGF automagically caches the Google Fonts used by your theme/plugins locally. No configuration (or brains) required!
Stars: ✭ 13 (-27.78%)
Mutual labels:  gdpr
laravel-boolean-dates
Automatically convert Eloquent model boolean attributes to dates (and back).
Stars: ✭ 31 (+72.22%)
Mutual labels:  gdpr

Javascript cookie control

Javascript module for controling cookie consent on your website.

Install

Install the Node dependency:

yarn add @netgen/javascript-cookie-control

or

npm install --save @netgen/javascript-cookie-control

Load

To load the required ES2015 module:

import CookieControl from '@netgen/javascript-cookie-control';

Usage

HTML

HTML markup for cookie control window shoud be:

<div id="ng-cc">

    <!-- if you don't want to use the overlay, remove next div from the markup -->
    <div class="ng-cc-overlay"></div>

    <!-- button for opening the window. Leave out if you don't need it -->
    <a href="#" class="js-open-ng-cc">Cookie settings</a>

    <div class="ng-cc-modal">

        <!-- button for closing the window. Leave out if you don't need it -->
        <a href="#" class="ng-cc-close ng-cc-close-btn">close</a>

        <div class="ng-cc-content">
            <div class="wrapper">
                <h3>This site uses cookies.</h3>
                <p>Some text describing your cookie usage...</p>

                <div class="ng-cc-actions">
                    <a href="#" class="optional-list-toggle">
                        <span>Customize settings!</span>
                        <span class="cookie-angle-up"></span>
                    </a>

                    <!-- button for accepting selected cookies and closing the window -->
                    <button id="ng-cc-accept" class="btn btn-primary">I'm ok with this</button>
                </div>
            </div>
            <div class="ng-cc-optional-list">
                <ul>
                    <!-- markup for the single cookie group (should be the same as the ones generated with js) -->
                    <li>
                        <input type="checkbox" class="ng-cc-optional-checkbox" id="ng-cc-necessary" data-name="necessary" checked disabled />
                        <label for="ng-cc-necessary">
                            <i class="ng-cc-checkbox-icon">
                              <span class="on ng-cc-on">Accepted</span>
                              <span class="off ng-cc-off">Not accepted</span>
                            </i>
                            Necessary Cookies
                        </label>
                        <p>This website cannot function properly without these cookies.</p>
                    </li>

                    <!-- this is where optional cookie groups are rendered -->
                </ul>
                <div class="ng-cc-optional-actions clearfix">
                  <button id="ng-cc-optional-save" class="btn btn-outline-primary">
                    Save settings
                  </button>
                </div>
            </div>
        </div>
    </div>
</div>

JS

Create config object for cookie control plugin and initialize it:

const ccConfig = {
  options: {
    lifetime: 30,
  },
  optionalCookies: [
    {
      name: 'analytics',
      label: 'Analytical Cookies',
      description: 'Analytical cookies help us to improve our website by collecting and reporting information on its usage.',
      accepted: true,
      onRevoke() {
        window['ga-disable-XX-XXXXX-X'] = true;
      },
    },
    {
      name: 'marketing',
      label: 'Marketing Cookies',
      description: 'We use marketing cookies to help us improve the relevancy of advertising campaigns you receive.',
    },
    {
      name: 'socialsharing',
      label: 'Social Sharing Cookies',
      description: 'We use some social sharing plugins, to allow you to share certain pages of our website on social media',
      onAccept: () => {
        (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = 'https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v3.0';
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
      },
    },
  ],
};

// create new cookie control instance
const cookieControl = new CookieControl(ccConfig);
// initialize the plugin
cookieControl.init();

Second parameter for initializing new instance is optional string with the id of the plugin div. Default value is ng-cc. So if you need to change it, use it like this:

const cookieControl = new CookieControl(ccConfig, 'new-id');

Parameters for cookie control config:

Config object has two parameters.

Parameter Type Default value Description
options Object General options for the plugin
optionalCookies Array Array of objects for optional cookie groups

Parameters for the options object (all are optional):

Parameter Type Default value Description
open boolean true Open the window on page load (doesn't open once the user accepts the cookies)
lifetime number 365 Lifetime of the saved cookie settings (in days)
domain string Domain for the saved cookie (e.g., 'example.com' or 'subdomain.example.com'). If not specified, this defaults to the host portion of the current document location.
acceptValue string '1' Value saved for the accepted cookie group
revokeValue string '0' Value saved for the revoked cookie group
timeout number 200 Timeout for auto open on page load (in milliseconds)
optionCookieHtml(cookie) function Function returning template for single optional cookie group. Function takes one object as parameter which has values for name (string), label (string), description (string) and accepted (boolean) and should return string with html
onChange(event, instance) function Function that gets executed on cookie group checkbox change. Function has two arguments. First one is checkbox change event from which you can get cookie group name (e.target.dataset.name) and if it's accepted or not (e.target.checked), and the other is instance of the plugin
onAccept(instance) function Function that gets executed on cookie accept button. Function has one argument, instance of the plugin

Parameters for each optionalCookies object:

Parameter Type Default value Description
name string Name of the cookie group (used for storing the value)
label string Label for cookie group which is rendered in window next to the checkbox
description string Description for the cookie group rendered below checkbox and label
cookieName (optional) string ng-cc- + name Name for storing cookie group consent
accepted (optional) boolean false Set to true if you want that cookie group to be enabled by default
onAccept (optional) function Function that gets executed on plugin init if the cookie group is enabled
onRevoke (optional) function Function that gets executed on plugin init if the cookie group is disabled

You can modify options of the plugin after creating the instance with set('option', new_value) function. e.g.:

cookieControl.set('onChange', (e, instance) => {
  console.log(e, instance);
});

Behaviour

There is an event listener for the click on html elements containing css class js-open-ng-cc which opens the window. You can put it anywhere on your site if you need to.

On every cookie group checkbox change, plugin saves the cookie with that cookie name and accept or revoke value.

Window opens on every page load until user clicks the #ng-cc-accept button (if the open parameter isn't set to false). After that, the window doesn't open automatically for the duration of the cookie lifetime.

SCSS

Import styles to scss file:

@import "@netgen/javascript-cookie-control/scss/style";

You also need to configure sass-loader to understand imports from node_modules. Update your sass-loader config by changing { loader: 'sass-loader' } to:

{
  loader: 'sass-loader',
  options: {
    includePaths: ['node_modules']
  }
}

You can override scss variables for main div id, plugin window width and background:

$ngCcId: 'ng-cc';
$ngCcWidth: 28em;
$ngCcBg: hsl(0, 0, 15);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].