Natural Pleistocene Monsters

    fever-cookies-plugin

    2.2.0 • Public • Published

    Fever Cookies Plugin

    Introduction

    This plugin allows you to setup a fully customizable cookie bar, so the user can control which cookies you can, following the best practices of GDPR compliance.

    Features

    • Custom labels
    • Custom layout
    • Add tabs (required|optional) as you go to match your cookie categories necessities
    • Add events to your tab optin/optout actions

    Setup

    1. Install the npm package

    npm install fever-cookies-plugin

    2. Include the package in your project

    The package contains two files inside dist folder which you need to include in your project.

    dist/css/cookie.min.css
    dist/js/cookie.min.js

    3. Initialization with default values

    const myCookieBar = new FeverCookieBar();

    This will create a default cookie bar, with the default values and no events for optin/optout actions.

    Image of default cookie bar

    3.1 Initialization with custom values

    To fully initialize the cookie plugin, you must pass your values/events as parameters. The code below shows setup to the default configuration, all the values that can be edited, plus the google analytics event inside analytics optional tab.

    const myCookieBarWithOptions = new FeverCookieBar({
        layout: {
            color: {
                overlay: false, //true or false --- block site from doing any action until user act on cookies
                primary: '#f60',
                secondary: '#000'
            },
            borderRadius: 10,
            bar: {
                position: 'bottom', //bottom or top
                text: 'By continuing to browse or by clicking "Accept All Cookies", you agree to the storing of first and third-party cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts',
                textColor: 'white', //white or black
                link: {
                    text: 'Cookie Privacy',
                    target: '_blank',
                    url: 'https://gdpr-info.eu/'
                },
                labels: {
                    acceptAll: 'Accept all cookies',
                    rejectAll: 'I do not accept',
                    settings: 'Cookie Settings'
                }
            }
        },
        modal: {
            title: 'Privacy Preference Center',
            logo: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI0LjAuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8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MC4yLDAuNGMwLjEsMC4xLDAuMywwLjEsMC41LDAKCQkJQzcwLjgsNDYuNSw3MC44LDQ2LjMsNzAuOCw0Ni4xeiIvPgoJPC9nPgo8L2c+Cjwvc3ZnPgo=', //size has to be 150x80
            labels: {
                acceptAll: 'Accept all',
                save: 'Save preferences'
            },
            required: {
                tabs: [{
                    id: 'your-privacy',
                    title: 'Your Privacy',
                    text: 'When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences, your device or used to make the site work as you expect it to. The information does not usually identify you directly, but it can give you a more personalized web experience. You can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, you should know that blocking some types of cookies may impact your experience on the site and the services we are able to offer.',
                    label: ''
                },
                {
                    id: 'strictly-necessary-cookies',
                    title: 'Strictly Necessary Cookies',
                    text: 'These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site may not work then.',
                    label: 'Always enabled'
                }]
            },
            optional: {
                labels: {
                    enabled: 'Enabled',
                    disabled: 'Disabled'
                },
                tabs: [{
                    id: 'analytics-cookies',
                    title: 'analytics cookies',
                    text: 'These cookies allow us to count visits and traffic sources, so we can measure and improve the performance of our site. They help us know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies, we will not know when you have visited our site.',
                    events: {
                        on() {
                            console.log('analytics on')
                        },
    
                        off() {
                            console.log('analytics off')
                            myFeverCookieBarWithOptions.expireCookie('_ga')
                            myFeverCookieBarWithOptions.expireCookie('_gid')
                            myFeverCookieBarWithOptions.expireCookie('_gat')
                        },
    
                        pageLoadOn() {
                            (function (i, s, o, g, r, a, m) {
                                i['GoogleAnalyticsObject'] = r
                                i[r] = i[r] || function () {
                                    (i[r].q = i[r].q || []).push(arguments)
                                }, i[r].l = 1 * new Date()
                                a = s.createElement(o)
                                m = s.getElementsByTagName(o)[0]
                                a.async = 1
                                a.src = g
                                m.parentNode.insertBefore(a, m)
                            })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
                             
                             //clientId generated using cyrb53
                            ga('create', 'UA-12345', {'clientId': clientIDHashed})
                            ga('set', 'anonymizeIp', true)
                            ga('set', 'forceSSL', true)
                            ga('send', 'pageview')
    
                            console.log('analytics pageLoadOn')
                        },
    
                        pageLoadOff() {
                            (function (i, s, o, g, r, a, m) {
                                i['GoogleAnalyticsObject'] = r
                                i[r] = i[r] || function () {
                                    (i[r].q = i[r].q || []).push(arguments)
                                }, i[r].l = 1 * new Date()
                                a = s.createElement(o)
                                m = s.getElementsByTagName(o)[0]
                                a.async = 1
                                a.src = g
                                m.parentNode.insertBefore(a, m)
                            })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
    
                            //clientId generated using cyrb53
                            ga('create', 'UA-12345', {'storage': 'none',  'clientId': clientIDHashed})
                            ga('set', 'anonymizeIp', true)
                            ga('set', 'forceSSL', true)
                            ga('send', 'pageview')
                            
                            console.log('analytics pageLoadOff')
                        }
                    }
                },
                {
                    id: 'functional-cookies',
                    title: 'functional cookies',
                    text: 'These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.',
                    events: {
                        on() {
                            console.log('functional on')
                        },
    
                        off() {
                            console.log('functional off')
                        },
    
                        pageLoadOn() {
                            console.log('functional pageLoadOn')
                        },
    
                        pageLoadOff() {
                            console.log('functional pageLoadOff')
                        }
                    }
                },
                {
                    id: 'targetting-cookies',
                    title: 'targetting cookies',
                    text: 'These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.',
                    events: {
                        on() {
                            console.log('targetting on')
                        },
    
                        off() {
                            console.log('targetting off')
                        },
                        
                        pageLoadOn() {
                            console.log('targetting pageLoadOn')
                        },
                        
                        pageLoadOff() {
                            console.log('targetting pageLoadOff')
                        }
                    }
                }]
            }
        }
    });

    4. Events

    Each tab you add to optional tabs, can be configured to react when the user enable/disable it. To achieve that, in each tab object, as in the example above, you must add a parameter called events, with four child events, on, off, pageLoadOn() & pageLoadOff() they will be invoked when the user push save/acceptsall/rejectsall buttons, and match the checked/uncheck state of the respective tab.

    {
        id: 'targetting-cookies',
        title: 'targetting cookies',
        text: 'These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.',
        events: {
            on() {
                console.log('run if user accept cookies');
            },
    
            off() {
                console.log('run if user reject cookies');
            },
    
            pageLoadOn() {
                console.log('always run if previously accepted cookies')
            },
            
            pageLoadOff() {
                console.log('alaways run if previously rejected cookies or yet not acceped by the user')
            }   
        }
    }

    For example, in google analytics, the on event must implement the _ga, _gid and _gat cookies, and the off event must destroy those cookies.

    It can have more cookie events for each tab (e.g.: hotjar, facebook), just insert the code to set up them inside each event and it will be called properly when needed.

    5. Methods

    5.1 Open Modal

    If you need to open the control panel in another place of your website, you can invoke openModal() method like the code below:

    document.querySelector('your-element').addEventListener('click', () => {
        myCookieBarWithOptions.openModal()
    })

    5.2 Expire Cookie

    To expire a cookie - this could help you in the off event - you can invoke expireCookie() method using the proper name of the cookie you want to expire as an argument.

    document.querySelector('your-element').addEventListener('click', () => {
        myCookieBarWithOptions.expireCookie('cookie-name-to-expire')
    })

    Install

    npm i fever-cookies-plugin

    Homepage

    fever.pt

    DownloadsWeekly Downloads

    101

    Version

    2.2.0

    License

    ISC

    Unpacked Size

    51.1 kB

    Total Files

    4

    Last publish

    Collaborators

    • fever_it