1.1.6 • Published 3 years ago

simple-cookie-banner v1.1.6

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

Simple cookie banner

If you need a simple way to add customizeable cookie banner which is GDPR friendly, then use this plugin. There is a lot of different tools which can generate it into your site by adding a <script>, but this will add thirdparty scripts into your site, and can therefor be hard to customize and listen to.

Here is an example of how it looks like out of the box: Cookie banner example

And here is the cookie corner which will be visible when the user has saved the settings they need. Cookie banner saved example

Installation

Run the code below into the root of the project:

npm install simple-cookie-banner

// or

yarn add simple-cookie-banner

When its installed then add it to a index.js or main.js file, so its executed when loading the app: main.js

import CookieSettings from "simple-cookie-banner";

...
const cookieSettings = CookieSettings({
    // Insert settings here
});

If you want some default css, then add the following @import into your css file:

@import "~simple-cookie-banner/cookie-settings.css";

Then build the script with npm run dev or yarn dev or what ever you use, and then you should see the cookie banner.

Settings

There is a number of different settings for the cookie banner. Here is a list of them:

KeyDescriptionDefault
typeChoose basic if you don't want to show the points or else choose simple if you want to show it.basic
structureObject which contains namings of classNames and id's
structure.appIdid of the wrapper element.cookie-settings
structure.innerWrapperClassClassname of inner div of the wrapper.cookie-settings__inner
content.*Object which contains all text related strings.
content.titleTitle in the cookie bannerThis website uses cookies
content.descriptionThe description right below the title in the cookie bannerWe use cookies to personalize our content and ads, to show you social media features and to analyze our traffic. We also share information about your use of our website with our social media, advertising and analytics partners. Our partners may combine this data with other information that you have provided to them or that they have collected from your use of their services.
content.showDetailShow button textShow details
content.readmoreAboutPolicyInsert read more about policy text.Read more about our cookie policy here:
content.readmoreAboutPolicyTextPolicy link text.Cookie policy
content.closeDetailClose button textClose details
content.cornerSVG or HTML which renders the corner right corner for users already saved cookie settingsSVG of cookie
pointsArray of different cookie categories.
points.*.labelLabel shown beside the checkbox
points.*.keyKey saved in the cookie if the checkbox is checked
points.*.valueDefault value for the given point
points.*.contentDescription about the given cookie category shown in the detail area.
eventsAll the event hooks. Every key should have a function as value
events.onSubmitThis function will be executed on submittion of the cookie banner. As first argument you will get the selected pointsnull
events.onCheckedThis function will be executed when checking a point in the cookie banner. Argument 0 is the point object, argument 1 is a checked booleannull
events.onDetailToggleThis function will be executed when show/hide the detail area in the cookie banner. Argument 0 is boolean open.null
events.onDetailItemThis function will be executed when switching around the detail sidebar. Argument 0 is index of the point active.null
events.onCornerClickedThis function will be executed when clicking the corner button.null
events.onCornerLoadThis function will be executed when the corner button is loaded.null
events.onLoadThis function will be executed when the cookie banner is loaded.null
policyLinkInsert the link to the policy pagefalse
delayms. to wait until showing the cookie banner300
cookieDaysHow many days should the cookie be saved with the settings?365
cookieNameThe name of the cookie banner settings cookie.cookie-settings
cookieDomainThe domain of the cookie with the settings.false
useCornerIf we need a way to open the modal again, then you can use the corner icon.false
buttonsIs the array of CTA's in the banner, you can also add custom buttons.array

Cookie settings change

If you want to change the settings yourself, then you can change it by using the object functions returned when initiating the CookieSettings() method. It will return the following functions:

{   
    // Open the cookie banner
    open: function(){},
    
    // Close the cookie banner
    close: function(){},

    // Get the current settings (false: not chosen yet, 1: if basic then accepted, 0: if basic then declined, array: if simple then array of the selected options)
    getSettings: function(){},
    
    // Save settings by selected point keys in array.
    saveSettings: function (selectedPointKeys = []),

    // Save setting by key and isChecked value.
    saveSetting: function(pointKey, isChecked = false)
}

You can use the cookieSettings.saveSettings(selectedPointKeys) function to update all the user cookie settings. You can also update only 1 setting with the cookieSettings.saveSetting(pointKey, isChecked = false).

Cookie buttons

Here is an example of how you can use the buttons array:

[
    {type: 'decline', label: 'No thanks'},
    {type: 'submit', label: 'Ok'},
]

Here is the types of buttons:

  • decline will decline all the points.
  • submit will accept only the selected points.
  • accept-all will accept all points
  • custom will need a new parameter onClick which is the function it will execute on click.
1.1.6

3 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.11

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago