Consent Manager

This is a simple, modern Consent Manager to handle cookies in the front- and backend.

The CM is capable of dealing with different languages and cookies.

Although there is no database or special backend for settings or statistics as this designed to be easily implemented for standard cases.

Settings

categories
legacy
baseLanguage
updateLink
langFetchLink
updateMethod
successEvent
failureEvent
eventTarget
template
errorTexts
excludedPages
startByEvent
eventName

categories

Type: Number


Number of categories to handle.

default: 0

legacy

Type: Boolean


If true, cookies will be stored with the selected user settings and sent with every request to the server (legacy cookie behavior).

Regardless of this setting, Easy CM will store all settings in localStorage and only send them once when the user has submitted the settings.

default: true

baseLanguage

Type: String (list, comma-separated)


Comma-separated list of supported languages in the format:

ISO 639 code / Language name (separated by commas).

default: 'en/English'


Example:

<div
	data-controller="easy-cm"
	data-easy-cm-supported-languages-value="en/English,de/German,es/Spanish"
></div>

updateMethod

Type: String (keyword)


The HTTP method to be used by Easy CM for update requests, usually 'POST' or 'GET'.

default: 'POST'

successEvent

Type: String


Event name dispatched on successful completion of cookie management action.

See the setting 'eventTarget' for an example.

default: 'easyCmSuccess'

failureEvent

Type: String


Event name dispatched on failure of cookie management action.

default: 'easyCmFailure'

eventTarget

Type: String


CSS selector or element identifier to which events will be dispatched.

default: 'body'


Example:

<div
	data-controller="easy-cm"
	data-easy-cm-success-event-value="mySuccessEvent"
	data-easy-cm-event-target-value="#targetId"
></div>

The example above will dispatch the event 'mySuccessEvent' on the element with the ID of 'targetId'.

document.getElementById('targetId').addEventListener('mySuccessEvent', (e) => {
	//Do some stuff
});

template

Type: String (dash-separated keywords)


Name of the template to use for rendering the consent manager.

Possible templates include predefined names like "light-blue".

default: 'blue-light'

Possible keywords are:

Schema: 'light', 'dark'

Colors: 'blue', 'red', 'green', 'yellow', 'pink', 'brown', 'bright' and 'shady'

errorTexts

Type: Object


Object defining error fallback texts, used if the manager crashes or fails.

default: {}


Example:

{
	en: 'Fallback text for English',
	de: 'Fehlertext auf Deutsch',
}
<div
	data-controller="easy-cm"
	data-easy-cm-error-texts-value="{en: 'Fallback text for English', de: 'Fehlertext auf Deutsch',}"
></div>

excludedPages

Type: String (comma-separated list)


Comma-separated list of page paths where the consent manager pop-up will NOT appear.

Note: subpages are not excluded by this setting.

Important: Do NOT include a trailing slash '/' at the end for exact comparison.

default: ''

startByEvent

Type: Boolean


If set to true, Easy CM will wait for a specific event before rendering the consent manager.

default: false

eventName

Type: String


The event name to listen to for triggering Easy CM rendering if 'startByEvent' is enabled.

default: 'easyCmStart'


Example:

<div
	id="easyCmElement"
	data-controller="easy-cm"
	data-easy-cm-start-by-event-value="true"
	data-easy-cm-event-name-value="myStartEvent"
></div>

Now you can start the rendering by dispatching the event 'myStartEvent' on the controller's element anytime.

const myEvent = new CustomEvent('myStartEvent');
setTimeout(() => {
    document.getElementById('easyCmElement').dispatchEvent(myEvent);
}, 3000);

Functions

reopenEasyCm

reopenEasyCm

Easy CM Manager helper function to trigger reopening the consent manager UI.

Dispatches the 'easyCmReopen' custom event on the first element with the 'easy-cm' controller.

Resets the submission status and prepares the manager again for display.

All previous settings are deleted.

Consent manager categories

The manager is designed to handle different categories.
A category can represent a group such as 'Essentials', 'Tracking', or even a single cookie.

There are two types of categories: required and optional.
Each category contains information about one or more cookies.

This information can be simple text or more advanced constructs, depending on the response needed.

Styling must be applied at the time of requesting the current language and can include raw HTML formatting.
A text entry can be plain or enriched content such as <b>Bold text</b> or more complex HTML elements:

 

<table>
	<thead>
		<tr>
			<th class="my-th-class-one">
				Cookie
			</th>
			<th class="my-th-class-two">
				Lifetime
			</th>
			<th class="my-th-class-three">
				Description
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th>Analytics-Cookie</th>
			<th>30 days</th>
			<th>Tracks the visited pages.</th>
		</tr>
		<tr>
			<th>Session</th>
			<th>1 year</th>
			<th>Stores current session information.</th>
		</tr>
	</tbody>
</table>

 

For examples and guidance on correctly defining categories, please refer to the demo page for the consent manager.

 

Every language response must contain specific content in JSON format for every category and the requested language.

First we need the text in the requested language of the main page of the manager.

 

{
	"header":"The header for the main content",
	"body":"The body of the main content",
	"accept":"The text for the accept button",
	"acceptAll":"The text for the accept all button",
	"acceptNecessary":"The text for the accept necessary button",
	"readMore":"The text for the read more button",
	"languageName":"The name of the requested language",
}

 

Next we can define one or more links at the bottom of the main page.

 

{
	"bottomLinks": {
		"key-of-the-link": {
			"name":"Text for the link",
			"link":"/the/link",
			"attributes": {
				"attribute":"Some attribute value",
				"style":"color: lightblue;"
			}
		}
	}
}

 

Finally we must define the content for the different categories.

 

{
	"categories": {
		"key/identifier": {
			"name":"Name of the category",
			"header":"Header for the category page",
			"body":"Body for the category page"
		},
		"Essential": {
			"name":"Essential",
			"header":"Essential cookies",
			"body":"Session data is stored to make the website work."
		},
		"Tracking": {
			"name":"Tracking",
			"header":"You can write HTML to style the content of the category page to your needs.",
			"body":'<span style="color: red;">Some red text</span><p class="greenText">Some green text</p>'
		}
	}
}

 

This is how the whole response should look like:

 

{
	"header":"The header for the main content",
	"body":"The body of the main content",
	"accept":"The text for the accept button",
	"acceptAll":"The text for the accept all button",
	"acceptNecessary":"The text for the accept necessary button",
	"readMore":"The text for the read more button",
	"languageName":"The name of the requested language",
	"bottomLinks": {
		"key-of-the-link": {
			"name":"Text for the link",
			"link":"/the/link",
			"attributes": {
				"attribute":"Some attribute value",
				"style":"color: lightblue;"
			}
		}
	},
	"categories": {
		"key/identifier": {
			"name":"Name of the category",
			"header":"Header for the category page",
			"body":"Body for the category page"
		},
		"Essential": {
			"name":"Essential",
			"header":"Essential cookies",
			"body":"Session data is stored to make the website work."
		},
		"Tracking": {
			"name":"Tracking",
			"header":"You can write HTML to style the content of the category page to your needs.",
			"body":'<span style="color: red;">Some red text</span><p class="greenText">Some green text</p>'
		}
	}
}

 

 

 

Categories settings

category
expires
domain
path
samesite
secure
partitioned
isEssential
values
strValues

category

Type: String


Category name, e.g. 'Essential', 'Analytics', etc.

default: 'Essential'

REQUIRED

expires

Type: Number


Expiration time in seconds for the category cookies.

Use -1 for session cookies.

default: -1

domain

Type: String


Cookie domain scope.

default: ''

More information:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

path

Type: String


Cookie path scope.

default: '/'

More information:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

samesite

Type: String


SameSite attribute for cookies ('lax', 'strict', 'none').

default: 'lax'

More information:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

secure

Type: Boolean


Flag indicating if cookies should be secure (HTTPS only).

default: true

More information:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

partitioned

Type: Boolean


Flag indicating if the cookie is partitioned.

default: false

More information:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

isEssential

Type: Boolean


Indicates if the category is essential (required by site).

default: true

values

Type: Object


Object holding additional key-value pairs for category settings.

default: {}

strValues

Type: String (semi-colon-separated list)


String representation of key-value pairs in the format:

'key1=value1;key2=value2;...'

Semi-colons and equal signs should be URI encoded if used within values.

default: ''