1.1.0 • Published 3 years ago

cookierazzi v1.1.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 years ago

CookieRazzi : A Cookie Concent Management Plateform (CMP)

CookieRazzi

Support IE11 npm NPM

Features

  • Written in vanilla javascript, no dependencies needed
  • Clean UI with some customisable style (CSS custom properties)
  • Change the markup of RGPD-sensitive JavaScript script tags to run only if the user has given consent.
  • The expiration time of the cookie storing user consent preferences is configurable. By default it is one month.

How to use

<link rel="stylesheet" href="cookierazzi.css">
<script src="cookierazzi.js"></script>
<script type="text/javascript">
    var cmp = new cookieRazzi;

    cmp.setExpire(2);
    cmp.setSeed(2);
    cmp.setText({title : 'Cookie policy'});
    cmp.updateConsent('necessary', {title: "Lorem ipsum"});
    cmp.addConsent( 'tracking' : {
        disabled : false,
        value : true,
        icon : "https://www.google.com/s2/favicons?domain=analytics.google.com",
        title : "",
        text :  "Description",
        callback: function(consentValue){
            //...
        }
    });

    document.addEventListener("DOMContentLoaded", function() {
        cmp.init();
    });
</script>

<script type="text/plain" cookie-consent="tracking">
    console.log('Eval script text/plain if consent');
</script>

Customise sentences

Texts parameters

keyDefault Sentences (string)
title"Nous respectons votre vie privée"
intro"Nous utilisons des cookies pour améliorer et personnaliser votre expérience."
desc"Vous pouvez à tout moment revenir sur vos choix en utilisant le lien « paramétrer les cookies sur ce site » disponible dans notre politique de confidentialité"
reject_all"Tout refuser"
accept"Valider la sélection"
accept_all"J'accepte tout"

Methods

MethodTypeDescription
init()Initialize the CMP
debug()Log settings and CMP cookie
showPopup()Show CMP popup
hidePopup()Hide CMP Popup
setSeed()stringChange the seed if consents are added or modified to reset the cookie
setExpire()intSet the expiration time for the cookie that retains user consent preferences. By default it is one month.
setText()objectCustomise popup sentences
addConsent()(string,object)Add consent with a named key and object with its value
updateConsent()(string,object)Update consent with the named key of the consent to be updated and an object containing the new values

Consents

keyTypeDescription
disabledboolDisabled the checkbox of the consent
valueboolDefault value of the consent
iconurl, base64 image, falseFor better acceptance, accompany the consent with an icon. (16x16)
titlestringTitle of the consent
textstringDescription of the consent
callbackfunctionFunction used if consent is approved

Toggle popup

In order to open the popup again, add the class bashow-cmp on a link, button, or other. When clicked, the popup will appear.

<a href="#" class="show-cmp">Manage cookies</a>

Customise

the CMP can be customised using a few CSS variables. Here are the default values:

:root{
	--cmp-sun-color: #fff6a2;
	--cmp-btn-bg-hover: #fff6a2;
	--cmp-btn-color-hover: #333333;
	--cmp-radius: 8px;
}

Example : Gtag setup

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-X"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}

    gtag("consent", "default", {
        ad_storage: "denied",
        analytics_storage: "denied",
        wait_for_update: 1000 // ms
    });
    
    gtag("set", "ads_data_redaction", true);
    gtag('js', new Date());
    gtag('config', 'UA-XXXXX-X');
    
    function updateConsent(ad_storage, analytics_storage) {
        gtag("consent", "update", {
            analytics_storage: analytics_storage ? "granted" : "denied"
        });
    }
</script>
<link rel="stylesheet" type="text/css" href="cookierazzi.css"/>
<script src="cookierazzi.js" type=""></script>
<script>
    var cmp = new cookieRazzi;
    cmp.addConsent('tracking', {
        disabled : false,
        value : true,
        icon : "https://www.google.com/s2/favicons?domain=analytics.google.com",
        title : "Tracking",
        text :  "Description",
        callback: function(consentValue){
            updateConsent(consentValue, consentValue)
        }
    });
    document.addEventListener("DOMContentLoaded", function() {
        cmp.init();
    });
</script>

Legal information

Visuel de Cookie créé par freepik - fr.freepik.com

1.1.0

3 years ago

1.0.11

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.10

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago