Skip to content

Serve cookie consent banner to EU visitors with Cloudflare Workers 🌩

Notifications You must be signed in to change notification settings

pioug/cookie-choice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cookie Choice is a endpoint that serves a JS library for rendering a cookie consent banner. Endpoint is a Cloudflare Worker to take advantage of the geolocation.

Demo

Why?

  • Low latency thanks to Cloudflare CDN
  • Visitor's location provided by Cloudflare (neither IP geolocation service nor browser geolocation API are needed)
  • Library served only when cookie consent law applies to visitor's country
  • Small overhead when cookie consent is not required

Installation

  1. Build the library:
npm ci
npx rollup -c
  1. Deploy cloudflare-worker.js to Cloudflare Workers.

Usage

const privacyPolicyLink = "https://my.privacy.policy/";
const force = true;
const {
  renderCookieChoice
} = await import(`https://my.cloudflare.worker/cookie-choice.js?privacy-policy-link=${privacyPolicyLink}&force=${force}`);
renderCookieChoice();
document.body.addEventListener(
  "cookieChoice:accept",
  {
    once: true
  },
  () => {
    console.log("Thanks for the cookies!");
  }
);

Documentation

About

Serve cookie consent banner to EU visitors with Cloudflare Workers 🌩

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published