Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

consent-banner-js

> DevOps
Open source

A zero-dependency, lightweight (~3kB), consent platform agnostic, cookie banner for any website (compatible with Google Consent Mode).

197 stars0 likes3 views
WebsiteGitHub

About

A zero-dependency, lightweight (~3kB), consent platform agnostic, cookie banner for any website (compatible with Google Consent Mode).

Consent Banner JS

A zero-dependency, lightweight (~3kB), consent platform agnostic, cookie banner for any website.

How does it work?

  1. It takes JSON configuration that controls display of the banner.
  2. It fires JS callback when user interacts with the banner
  3. It provides simple JS object with consent state

Get started

First, include simple CSS for the banner in the `` of the page:

xml

Then in the footer you can include the actual JS:

xml

Or if you want to load the library script asynchronously, you can use the following consent-banner.ready event listener, which will execute the function only when the library is loaded:

xml

To make that work you need to prepare three things:

  1. A function to load the consent state from somewhere, for instance localStorage (see examples)
  2. A function to do something when the user provides their consent, for instance save it in localStorage (see examples)
  3. A config object that contains complete configuration for the banner content (see examples)

Config Object

…

Consent State Object

Both JS callback functions provided needs to either accept (on save) or return (on load) Consent State Object:

javascript
{
    ad_storage: 'granted',
    analytics_storage: 'denied'
}

Callbacks

javascript
cookiesBannerJs(
    function loadConsentState() {
        const consentState = {}; // get it from somewhere (e.g. localStorage);
        return consentState;
    },
    function saveConsentState(consentState) {
        // do something with consentState, which is basic JS object:
        // {
        //   ad_storage: 'granted',
        //   analytics_storage: 'denied'
        // }
    },
    config
);

Simple Markdown

All description fields in config object support simplified Markdown-like syntax:

  • links
  • bold or bold
  • italic or italic

Styling

This banner comes with mininal set of CSS with all elements prefixed with consent-banner-. Main elements have their IDs:

  • #consent-banner-main - main wrapper element
  • #consent-banner-modal - first view, centered modal or bottom bar
  • #consent-banner-settings - shown when user clicks "settings" button

Buttons can be styles using following CSS selectors:

  • .consent-banner-button - for all buttons
  • .consent-banner-button[href="#accept"] - for approval buttons

Examples

See following examples for complete setups:

  • Bottom bar without "wall"
  • Central modal with "wall"
  • Single JS Bundle
  • Google Consent Mode

Integrations

Instead of doing direct installation in HTML you can use one of the following integrations:

Google Tag Manager

Use this Google Tag Manager Template to quickly configure and deploy the Consent Banner on any GTM enabled website. It obviously integrates with Google Consent Mode.

WordPress

Simple WordPress plugin that provides UI for configuration, injects required files and integrates with Google Consent Mode.

PrestaShop

Simple PrestaShop plugin that provides UI for configuration, injects required files and integrates with Google Consent Mode.

Cloudflare Worker

Example CF Worker code to inject Consent Banner and the configuration without touching HTML code.

Development

We like docker so that's how get local dev server:

docker-compose up -d dev

But first, we need to install dependencies:

docker-compose run dev npm i

And if we need node cli we get into the a shell like that:

docker-compose run --rm dev bash

Finally, to build minified JS file we run:

docker-compose run dev npm run build

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptconsentconsent-managementconsent-modeconsent-mode-v2

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理