Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pioug/cookie-choice
Serve cookie consent banner to EU visitors with Cloudflare Workers 🌩
https://github.com/pioug/cookie-choice
cloudflare-workers cookie-banner cookie-consent serverless
Last synced: 28 days ago
JSON representation
Serve cookie consent banner to EU visitors with Cloudflare Workers 🌩
- Host: GitHub
- URL: https://github.com/pioug/cookie-choice
- Owner: pioug
- Created: 2018-12-29T19:04:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-09T13:42:30.000Z (over 4 years ago)
- Last Synced: 2024-08-03T03:03:47.649Z (3 months ago)
- Topics: cloudflare-workers, cookie-banner, cookie-consent, serverless
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 15
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**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
- Live demo: https://pioug.github.io/cookie-choice/example.html
- "Noop" fuction if not in Europe: https://cookie-choice.pioug.workers.dev/cookie-choice.js?privacy-policy-link=https://github.com/pioug/cookie-choice
- Function to render the banner: https://cookie-choice.pioug.workers.dev/cookie-choice.js?privacy-policy-link=https://github.com/pioug/cookie-choice&force=true## 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:
```bash
npm ci
npx rollup -c
```2. Deploy `cloudflare-worker.js` to Cloudflare Workers.
## Usage
```js
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
- https://developers.cloudflare.com/workers/
- https://blog.cloudflare.com/delivering-a-serverless-api-in-10-minutes-using-workers/
- http://ec.europa.eu/ipg/basics/legal/cookies/index_en.htm