Customizable GDPR Cookie Consent Popup In JavaScript – Cookify

Category: Javascript , Recommended | September 26, 2022
Views Total:1,490 views
Official Page:Go to website
Last Update:September 26, 2022


Customizable GDPR Cookie Consent Popup In JavaScript – Cookify


Cookify is a highly customizable GDPR cookie consent popup library to make your site or app compliant with GDPR and EU Cookie Law.

The GDPR cookie consent popup enables visitors to manage (enable and disable) cookies allowed to use, and toggle scripts on/off accordingly.


$ npm i cookify

How to use it:

1. The library requires Bootstrap’s stylesheet loaded in the document.

<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />

2. Import the Cookify as an ES module.

import Cookify from './src/index.js';

3. Initialize the Cookify library and pass the following parameters:

var cookify = new Cookify(
    dataName = 'cookify', 
    actionCallback = () => {}, 
    trackingCallback = () => {}, 
    saveWithChange = false, 
    saveByDefault = false, 
    cookieDefault = 'necessary',
    initCallback = () => {}, 

4. Create checkboxes to manage your cookies:

<div class="m-3 fixed-bottom">
  <div id="manage" class="mx-md-5 p-3 bg-white shadow-lg rounded d-none" data-c-view="manage">
    <h2>Manage Cookies</h2>
    <p>We use cookies to provide and secure our websites, as well as to analyze the usage of our websites, in order to offer you a great user experience. To learn more about our use of cookies see our <a href="#" target="_blank">Privacy Policy</a>.</p>
    <div class="my-3">
      <div class="form-check">
        <input data-c-check="necessary" class="form-check-input" type="checkbox" value="" id="necessary">
        <label class="form-check-label" for="necessary">
      <div class="form-check">
        <input data-c-check="marketing" data-c-check-default="true" class="form-check-input" type="checkbox" value="" id="marketing">
        <label class="form-check-label" for="marketing">
      <div class="form-check">
        <input data-c-check="performance" class="form-check-input" type="checkbox" value="" id="performance">
        <label class="form-check-label" for="performance">
    <div class="d-flex">
      <div data-c-action="accept" class="btn btn-secondary flex-fill me-1">
      <div data-c-action="all" class="btn btn-primary flex-fill">
      <div data-c-action="necessary" class="btn btn-primary flex-fill ms-1">

5. Toggle on/off scripts, images, and iframes based on user selection.

// scripts
<script type="text/plain" src="example.js" data-c-script="necessary"></script>
<script type="text/plain" data-c-script="necessary">
// images
<img data-c-script="necessary" src="/path/to/fallback.jpg" data-c-fallback="/path/to/fallback.jpg" data-c-src="/example.jpg"/>
// iframes
<iframe data-c-script="necessary" src="about:blank" data-c-fallback="about:blank" data-c-src=""></iframe>

6. Get data state.



v3.1.0 (09/28/2021)

  • Support to manage consent for img and iframes
  • Async self initialization to prevent false loading

v3.0.2 (07/19/2021)

  • Fixed Bug in changeScriptType() where scripts are not loaded in Firefox
  • Fixed Bug in initCheckboxes() where scripts loaded multiple times
  • Fixed Bug in test file where src is imported
  • Fixed Bug in event onCheckboxClick where script type changes directly to ‘plain’ without selected saveWithChange
  • Changed inline script in test file to ‘performance’

v3.0.1 (07/16/2021)

  • Refactor

v3.0.0 (05/16/2021)

  • Added different Events for actions
  • Added a new socialcard
  • Added a file bootstrap.html for testing

v2.1.1 (05/06/2021)

  • Fixed the script for reloading eighter the src or the inner script
  • Fixed “SameSite=lax” with removing it from cookie initialisation
  • Fixed init() funktion where case support called the wrong funktion

You Might Be Interested In:

Leave a Reply