Orejime 🍪
Let your users choose the cookies they eat on your website.
Orejime 🍪 is an easy to use consent manager that focuses on accessibility.
Introduction
Orejime 🍪 is an open-source JavaScript library you can use on your website to let users choose what third-party cookies they allow. It's specifically made to comply with the GDPR.
Orejime 🍪 is a fork of Klaro! that focuses on accessibility. It follows Web Content Accessibility Guidelines (WCAG) via the French RGAA.
Getting started
Using Orejime 🍪 requires a few steps:
- Installation
- Third-party script tags change
- Configuration
- Initialization
Installation
Via CDN
The easiest way to use the lib is to include the built files directly in the browser.
<link rel="stylesheet" href="https://unpkg.com/orejime@1.2.4/dist/orejime.css" />
<script src="https://unpkg.com/orejime@1.2.4/dist/orejime.js"></script>
Via npm
Orejime 🍪 is a React lib. Make sure you already installed react and react-dom, then:
npm install orejime
The CSS is located in node_modules/orejime/dist/orejime.css
. Import it directly in your JS thanks to webpack, or install it any way you are used to in your project.
You can also directly consume the Sass file if you prefer, located in the same folder.
Note: if you don't have a React environment but still want to use npm in order to easily get the latest version of Orejime, the already-built JS file is located in node_modules/orejime/dist/orejime.js
.
Old browser support
For IE11, you'll need to have ES6 polyfills loaded on your page. One easy and efficient way to add such polyfills is to use polyfill.io.
Third-party script tags change
For each third-party script you want Orejime to manage, you must modify its <script>
tag so that the browser doesn't load it directly anymore. Orejime will take care of loading it if the user accepts.
For inline scripts, set the type
attribute to opt-in
to keep the browser from executing the script. Also add a data-name
attribute with a short, unique, spaceless name for this script:
- <script>
+ <script
+ type="opt-in"
+ data-type="application/javascript"
+ data-name="google-tag-manager">
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push [...]
</script>
For external scripts or img tags (for tracking pixels), do the same, and rename the src
attribute to data-src
:
- <script
- src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
+ <script
+ type="opt-in"
+ data-type="application/javascript"
+ data-name="google-maps"
+ data-src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
Configuration
You need to pass Orejime 🍪 a configuration object with, at the very least, apps
and privacyPolicy
properties. Each app listed in apps
must itself have at least name
, title
and cookies
.
Here is a fully-detailed annotated example of a configuration object:
var orejimeConfig = {
elementID: "orejime",
appElement: "#app",
cookieName: "orejime",
cookieExpiresAfterDays: 365,
cookieDomain: 'mydomain.com',
stringifyCookie: (contents) => JSON.stringify(contents),
parseCookie: (cookie) => JSON.parse(cookie),
privacyPolicy: "",
default: true,
mustConsent: false,
mustNotice: false,
lang: "en",
logo: false,
debug: false,
translations: {
en: {
consentModal: {
description: "This is an example of how to override an existing translation already used by Orejime",
},
inlineTracker: {
description: "Example of an inline tracking script",
},
externalTracker: {
description: "Example of an external tracking script",
},
purposes: {
analytics: "Analytics",
security: "Security"
}
},
},
apps: [
{
name: "google-tag-manager",
title: "Google Tag Manager",
cookies: [
"_ga",
"_gat",
"_gid",
"__utma",
"__utmb",
"__utmc",
"__utmt",
"__utmz",
"_gat_gtag_" + GTM_UA,
"_gat_" + GTM_UA
],
purposes: ["analytics"],
callback: function(consent, app){
console.log("User consent for app " + app.name + ": consent=" + consent)
},
required: false,
optOut: false,
default: true,
onlyOnce: true,
},
{
name: "inline-tracker",
title: "Inline Tracker",
purposes: ["analytics"],
cookies: [
"inline-tracker"
["cookieName", "/blog", "." + location.hostname],
["cookieName", "/", "test.mydomain.com"],
]
},
{
name: "external-tracker",
title: "External Tracker",
purposes: ["analytics", "security"],
cookies: ["external-tracker"],
required: true
}
],
categories: {
[
title: "Analytics",
description: "A long form description of the category.",
apps: [
"google-tag-manager",
"external-tracker"
]
]
}
}
Initialization
Now that you included the JS, the CSS, configured existing third-party scripts and defined your configuration, you can initialize an instance. This can be done automatically or manually.
Automatically
When including the script, the lib checks if the window.orejimeConfig
variable exists. If it does, a new Orejime instance is created in window.orejime
.
:warning: Note : Orejime doesn't have this behavior when using it as a module.
Manually
Orejime.init(orejimeConfig);
API
Orejime.init(config)
: creates a new Orejime instance with the given config objectOrejime.defaultConfig
: object containing all the default properties of an instance
Orejime instance
show()
: show the consent modalinternals.react
: the React app used internally. See src/components/main.js
internals.manager
: the ConsentManager instance used. See src/consent-manager.js
internals.config
: the complete config object used
Development
If you want to contribute to Orejime, or make a special build for yourself, clone the project then:
npm install
npm start
You can then open the demo page on http://localhost:3000
- it will be reloaded automatically when the JS or CSS changes.
License & credits
This project is licensed under a BSD-3 license.
Orejime started as a fork of Klaro!. A lot of stuff changed since. A few were integrated in the original project, but eventually some big bricks changed and it became difficult, or sometimes not even necessary, to push those changes in.
Orejime is maintained by Empreinte Digitale (French).
What does "Orejime" mean?
"Orejime" is a play-on-word. You can pronounce it like "Au régime" in French, which means "on a diet". 🍪