jizy-cooky
v2.1.5
Published
A lightweight and extensible GDPR management library
Readme
Cooky
Cooky is a simple and extensible GDPR Cookie consent management tool.
How it works
The consent manager displays an alert if user consent is needed for non-technical (third-party) cookies. If only technical cookies are present, the alert is not shown. However, the consent manager interface can always be accessed by the user for informational purposes, even if no consent is required.
The Cooky object is added to the global window object when the script is loaded. You can also import the classes individually if you are using a module bundler.
Installation
npm install jizy-cookyUsage
See example files in example/ for practical usage.
Useful methods
It is easy to interact with the Cooky manager programmatically. Here are some useful methods:
Cooky.init(options): Initialize the Cooky manager with optional configurationCooky.config(config): Update the Cooky configurationCooky.show(): Show the Cooky manager interfaceCooky.hide(): Hide the Cooky manager interface
When using the devmode Plugin you can also use:
Cooky.addCategory(category): Add a new CategoryCooky.addLanguage(language): Add a new LanguageCooky.addService(service): Add a new ServiceCooky.addPlugin(plugin): Add a new PluginCooky.addTranslations(code, translations): Add new translations for a language codeCooky.appendTranslations(translations): Append translations for multiple languagesCooky.appendServiceData(serviceId, data): Append data to an existing ServiceCooky.appendServiceCookies(serviceId, cookies): Append cookies to an existing Service
Events
The following custom events are dispatched on the document object:
cooky.show: Show the consent manager interfacecooky.hide: Hide the consent manager interfacecooky.translate: Translate the consent manager interface. The event detail contains thecodeof the new language.cooky.respond.all: Triggered when the user responds to all services (accept or reject). The event detail containsaccept(boolean) and optionaltimeout(ms before reload).cooky.respond.one: Triggered when the user responds to a single service (accept or reject). The event detail containsaccept(boolean),serviceId(string), and optionaltimeout(ms before reload).
An Observer checks for DOM changes.
For example adding class="cooky-needs-consent" to the body, triggers the consent manager.
