Orejime 🍪
Let your users choose the cookies they eat on your website.
Orejime is a lightweight consent manager that focuses on accessibility.
Explore its features
Getting started
- Installation
- Configuration
- Third-party scripts configuration
- Initialization
Installation
Orejime comes with many styles and languages. It is distributed as individual
modules that follow a common convention, namely orejime-[THEME]-[LANGUAGE]
.
For example:
orejime-standard-en.js
uses the standard theme with english textsorejime-standard-fr.js
uses the standard theme with french textsorejime-dsfr-fr.js
uses the DSFR theme with french texts
(Learn more about themes & languages)
Content Delivery Network
The easiest way to use Orejime is to import a distribution via a CDN such as
jsDelivr:
<script src="https://cdn.jsdelivr.net/npm/orejime@latest/dist/orejime-standard-en.js"></script>
<link
href="https://cdn.jsdelivr.net/npm/orejime@latest/dist/orejime-standard.css"
rel="stylesheet"
/>
[!TIP] If you're using this method, please avoid using the @latest
version.
Prefer a fixed one like https://cdn.jsdelivr.net/npm/orejime@3.0.0/…
. That
way you can ensure you will not be impacted by a change of API or a potential
bug that could land in the latest version.
npm
Orejime only distributes built files via npm
(learn why).
npm install orejime
You'll find the required JS and CSS files in the dist
folder.
Configuration
You need to pass Orejime some configuration for it to function. This is
typically done by assigning configuration options to window.orejimeConfig
:
<script>
window.orejimeConfig = {
};
</script>
You'll find all the available configuration options below.
[!NOTE] Very few of the following options are actually required (only
purposes
and privacyPolicyUrl
are). Optional options are explicitly
flagged as such.
Annotated example of configuration
var orejimeConfig = {
privacyPolicyUrl: '',
purposes: [
{
id: 'google-tag-manager',
title: 'Google Tag Manager',
description: 'This is used for analytics.',
cookies: [
'_ga',
'_gat',
'_gid',
'__utma',
'__utmb',
'__utmc',
'__utmt',
'__utmz',
'_gat_gtag_' + GTM_UA,
'_gat_' + GTM_UA
],
isMandatory: false,
isExempt: false,
default: false,
runsOnce: true
},
{
id: 'inline-tracker',
title: 'Inline Tracker',
description: 'Example of an inline tracking script',
cookies: [
'inline-tracker'[
('cookieName', '/blog', '.' + location.hostname)
],
['cookieName', '/', 'test.mydomain.com']
]
},
{
id: 'external-tracker',
title: 'External Tracker',
description: 'Example of an external tracking script',
cookies: ['external-tracker'],
isMandatory: true
},
{
id: 'advertising',
title: 'Advertising',
description: '…',
purposes: [
{
id: 'foo',
title: 'Foo',
cookies: []
},
{
id: 'bar',
title: 'Bar',
cookies: []
}
]
}
],
forceModal: false,
forceBanner: false,
translations: {
modal: {
description:
'This is an example of how to override an existing translation already used by Orejime'
}
},
logo: '/img/logo.png',
orejimeElement: '#orejime',
cookie: {
name: 'orejime',
duration: 365,
domain: 'mydomain.com',
sameSite: 'strict',
stringify: (contents) => JSON.stringify(contents),
parse: (cookie) => JSON.parse(cookie)
}
};
[!IMPORTANT] If every purpose is either isMandatory
or isExempt
, Orejime
will not show at startup (it will still be possible to open it
programmatically). However, you should consider this use case carefully, and
ensure that :
isMandatory
trackers are truly required for your app to function properlyisExempt
trackers are exempt from consent (i.e.
as defined by the CNIL)
Third-party scripts configuration
Scripts that require user consent must not be executed when the page load.
Orejime will take care of loading them when the user has consented.
Those scripts must be tagged with their related purpose from the configuration.
This is done by wrapping them with a template tag and a data-purpose
attribute:
+ <template data-purpose="google-tag-manager">
<script>
(function(w,d,s,l,i){/* … */})(window,document,'script','dataLayer','GTM-XXXX')
</script>
+ </template>
This way, the original script is left untouched, and any piece of HTML can be
controlled by Orejime in the same way.
You can wrap many elements at once or use several templates with the same
purpose:
<template data-purpose="ads">
<script src="https://annoying-ads.net"></script>
<script src="https://intrusive-advertising.io"></script>
</template>
<template data-purpose="ads">
<iframe src="https://streaming.ads-24-7.com/orejime"></iframe>
</template>
[!NOTE] There is more you can do with templates! Learn about
contextual consent.
Integration tips
WordPress
Should you use Orejime in a WordPress website, you could alter the rendering of
the script tags it should handle:
wp_enqueue_script('matomo', 'matomo.js');
function orejimeScriptLoader($tag, $handle, $src) {
if ($handle === 'matomo') {
return '<template data-purpose="analytics">' + $tag + '</template>';
}
return $tag;
}
add_filter('script_loader_tag', 'orejimeScriptLoader', 10, 3);
Initialization
Now that you installed and configured Orejime, you should see it greet you!
Anytime the window.orejimeConfig
variable is set with a valid configuration,
Orejime will pick it up and start.
In case you don't set this variable, Orejime can still be launched
programatically by passing it a configuration:
Orejime.init(orejimeConfig);
[!NOTE] Previously, Orejime could be imported as any other module and bundled
into application code. With version 3, we're abandonning this functionality to
provide standalone builds only
(learn why).
Theming
Standard theme
This is a custom theme meant to be simple but elegant enough to be used as-is on
any website. It is easily customizable by tweaking some CSS properties.
You can either replace the original CSS entirely, or add your custom stylesheet
to overwrite only some of the rules.
<link rel="stylesheet" href="orejime.css" />
<style>
.orejime-Env {
--orejime-font-family: monospace;
--orejime-background: black;
--orejime-color: yellow;
}
</style>
You'll find the available CSS properties in
the theme's stylesheet.
DSFR theme
This theme is meant to be used on websites using the official design system of
the french government. As those sites already include the DSFR styles, this
theme does not provide any styles of its own but only makes use of the correct
markup and class names.
See the
consent manager component
on the DSFR docs for an overview.
Internationalization
Orejime is available in most european languages: Catalan, Dutch, English,
Estonian, Finnish, French, German, Hungarian, Italian, Norwegian, Occitan,
Romanian, Spanish, Swedish.
[!NOTE] Each and every translated text is overridable via
the configuration.
Contextual consent
Content embedded from other websites might be restricted by user consent (i.e. a
YouTube video).
In that case, using templates would work just like with scripts:
<template data-purpose="youtube">
<iframe src="https://www.youtube.com/embed/toto"></iframe>
</template>
However, this won't show anything until the user consents to the related
purpose.
To be a little more user friendly, adding the data-contextual
attribute will
display a fallback notice until consent is given, detailing the reason and
offering a way to consent in place.
- <template data-purpose="youtube">
+ <template data-purpose="youtube" data-contextual>
<iframe src="https://www.youtube.com/embed/toto"></iframe>
</template>
Integration tips
WordPress
Should you use Orejime in a WordPress website, you could alter the rendering of
embeds so they use contextual consent:
function orejimeWrapEmbeds($content, $block) {
if ($block['blockName'] === 'core/embed') {
return '<template data-purpose="embeds" data-contextual>' . $content . '</template>';
}
return $content;
}
add_filter('render_block', 'orejimeWrapEmbeds', 10, 2);
API
Functions and references are made available on the global scope:
loadOrejime(config)
: creates a new Orejime instance with the given config
object
Orejime instance
orejime.prompt()
: opens the consent modalorejime.manager
: the core consent managerorejime.config
: the complete config object used
Manager
The manager handles the core functionality of Orejime.
orejime.manager.getConsent(purposeId)
: tells if the user has given consent
to a given purposeorejime.manager.setConsent(purposeId, consent)
: sets consent to a given
purposeorejime.manager.clearConsents()
: resets consents as if the user never
interacted with Orejime (this will reopen the banner)orejime.manager.acceptAll()
: gives consent to all purposesorejime.manager.declineAll()
: revokes consent to all purposes
Events
The manager emits events to which you might subscribe to implement side effects:
orejime.manager.on('update', function (updatedConsents, allConsents) {
});
orejime.manager.on('clear', function () {
});
orejime.manager.on('dirty', function (isDirty) {
});
(See src/core/Manager.ts
for a complete overview)
Migrating
Version 3
A major overhaul of the configuration took place in this version, as to clarify
naming and align more with the GDPR vocabulary.
Configuration
If you were already using version 2, a tool to migrate your current
configuration is available here : https://orejime.boscop.fr/#migration.
Third-party scripts
Previous versions of Orejime required you to alter third party script tags. This
behavior has changed, and you should now leave scripts untouched and wrap them
in a template, as documented in
scripts configuration
(learn why).
As you can see from the following example, this is simpler and less intrusive:
- <script
- type="opt-in"
- data-type="application/javascript"
- data-name="google-maps"
- data-src="https://maps.googleapis.com/maps/api/js"
- ></script>
+ <template data-purpose="google-maps">
+ <script src="https://maps.googleapis.com/maps/api/js"></script>
+ </template>
Development
If you want to contribute to Orejime, or make a custom build for yourself, clone
the project and run these commands:
npm install
npm start
You can then open the demo page at http://localhost:3000
, which will be
reloaded automatically whenever 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 Boscop (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".
🍪🍪🍪