Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Open source AVG solution for websites. More info:

ConsentCookie on your website

Download the script here or build your own (custom) ConsentCookie

Include the script on your website:

<script src="/path/to/consentcookie.min.js"></script>

Initialize ConsentCookie:

// An example of ConsentCookie initialized with a custom config
    'connections': {
      'cc': {
        'initstate': 'disabled'
      'iq': {
        'initstate': 'optout'
      'ga': {
        'initstate': 'disabled'
      'gtm': {
        'initstate': 'disabled'
    'moreinfolink': ''

To load a tracker based on the ConsentCookie preference of the user you can do the following:

// Check if the user accepted the consent for the given connection by its id
if(ConsentCookie.get("id").flag === 1){
  // Do stuff

Google Analytics example

// Check if the user accepted the Google Analytics consent
if(ConsentCookie.get("ga").flag === 1){
  // If so, load the Google Analytics integration script,

  // The script provided by Google Anayltics
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-XXXXX-Y', 'auto');
  ga('send', 'pageview');


Basic Usage


Method Params Description Docs
ConsentCookie.init config Initialize ConsentCookie with the given config link
ConsentCookie.on event, callback Listen for the event with the given callback link event, callback Remove event listener(s) for the given event link
ConsentCookie.get id Get the consent for the given id link
ConsentCookie.registerPlugin plugin Register a ConsentCookie plugin link

To enabled ConsentCookie you need to initialize it with a config object. The config object should have the following properties:

Name Description
moreinfolink The link that is shown on the bottom of the connections view
connections The connections that ConsentCookie manages given as an object where each property key is the id of the connection and the property value the config of the connection
    'connections': {
      // connection 1
      'id 2':{
        //connection config
      // connection 2
      'id 1':{
        //connection config
    'moreinfolink': ''

A connection represents a consent integration with your website. Each connection has a specific id that should correspond with an id of a connection listed in ConsentCookie tracker list. The connection config should have the following properties

Name Options Description
initstate optin, optout, disabled
  • optin: the user can change the consentsetting. Initially the consent by default is disabled
  • optout: the user can change the consentsetting. Initially the consent by default is enabled
  • disabled: the user can not change the consentsetting. Initially the consent by default is enabled


You can listen for an event with a given callback:

  // Do stuff

The following events are emitted:

Name Description
consent All events related to consent changes
profile All events related to changes of a consent profile

The callback function will receive a single payload object as argument with the following default properties:

Name Description
id The id of the consent connection
state The update state related to the event

Depending on the event type additional properties can be available in the payload object.

You can remove all event listeners of an event by giving the name of the specific event:"consent");

You can also remove a single listener:

var specificListener = function($payload){
  // Do stuff

// Register the specific listener

// Unregister the specific listener"consent",specificListener);


You can get the current state of a consent by giving the id of the consent:


The return is a consent object with the following properties:

Name Description
id The id of the consent connection
flag The flag related to the state of the consent. 0=disabled 1=enabled


To add addition functionality to ConsentCookie, you can register a plugin for each unique connection.


ConsentCookie plugins provide the option to extend ConsentCookie functionality for specific connections. Each connection can load a (custom) plugin. Default plugins are provided by the default ConsentCookie tracker list.

Plugins are Javascript files following a spefic convention and should be publicly availbled by a url. They are initially loaded when opening the Connections view, for each connection if configured for that specific connection.

(function ($global) {

function Plugin() {}

Plugin.prototype.register = function ($context) {
this.context = $context;

Plugin.prototype.getId = function () {};

Plugin.prototype.getProfileId = function () {};

Plugin.prototype.getProfileIds = function () {};

Plugin.prototype.getProfile = function () {};

Plugin.prototype.getProfileInfo = function () {};

Plugin.prototype.deleteProfile = function () {};

if (!$global || !$global.ConsentCookie || typeof $global.ConsentCookie.registerPlugin !== 'function') {
throw new Error('ConsentCookie not available. Unable to register plugin: ' + DEFAULT_ID);

$global.ConsentCookie.registerPlugin(new Plugin());


Registering a plugin in the ConsentCookie client

To make the plugin available in ConsentCookie it needs to register itself by calling ConsentCookie.registerPlugin. Calling this function, will load the plugin and call Plugin.register providing a context object that can be used within the plugin.

$global.ConsentCookie.registerPlugin(new Plugin());

Called by ConsentCookie when registerPlugin is executed:

Plugin.prototype.register = function ($context) {
  this.context = $context;
Plugin Context

The plugin context is a Javascript object with the following API:

Method Params Description Example
getLib $name Returns the available library by its name context.getLib("http")

The following libraries are available:

Name Description API info
http library for making http requests within the plugin. Currently vue-resources is referenced.
cookie library for handling browser cookies. Currently js-cookie is referenced
_ library for different Javascript helpers. Currently underscore is referenced
Plugin default interface

ConsentCookie will call the following functions of the plugin when implemented.

Method Description Return type
getId Should return the id of the connection of the plugin String
getProfileId Should return the id of the profile the connection manages String
getProfileIds Should return an array of all profile id`s the connection manages Array
getProfile Should return the profile managed by the connection as a Javascript object Promise
getProfileInfo Should return an object that represents the profile and is shown within ConsentCookie Promise
deleteProfile Should delete the profile managed by the connection Promise

This function is used by ConsentCookie to show a summary of the profile the connection is managing. ConsentCookie uses a default template for showing this info. The template consists of a header and content panel.

When ConsentCookie calls getProfileInfo it expects a promise that resolves in an object with the following properties:

Name Description
header a String with valid HTML that is shown as the header
content a String with valid HTML that is shown as content
	"header": "<div>I am a header</div>",
	"content": "<div>I am content</div>"
Plugin listening for events

A plugin can also listen for changes by using the ConsentCookie event framework.

// Plugin code that runs when loading the plugin
(function ($global) {

	// Register event listener when plugin is loaded
	$global.ConsentCookie.on('connection', function ($payload) {

		// Listen for connection changes

		// Do stuff

Custom plugin

By default all used plugins are defined in the ConsentCookie tracker list. When you want to use a custom plugin for a specific connection your can override the default url with a custom one.

To override the default url, add the property plugin to the connection config of which you want to load the custom plugin.

    'connections': {
      // Google Analytics with custom plugin
      'ga': {
        'initstate': 'disabled',
    'moreinfolink': ''

Build your own ConsentCookie


  1. Node.js => 4.0.0
  2. NPM => 3.0.0


Clone a copy of the main ConsentCookie git repo by running:

git clone git://

Install the project dependencies:

cd consentcookie && npm install


To run the development server with the demo page:

npm run dev

A browser window will automatically open with the demo page visible.


To build ConsentCookie for deployment:

npm run build -- -r

Using the -r option will create a singlefile minified version of ConsentCookie that is optimized for use on websites.

Building single file

To build ConsentCookie in 1 file consentcookie.min.js for release.

npm run release

Built With

  • VueJS - The application framework used
  • Webpack - Module bundler for building the application


See also the list of contributors


This project is licensed under the Apache License 2.0 - see the LICENSE file for details


  • OOGT - for creating the intial design of ConsentCookie
  • Eveline Druncks - for helping with improving the initial design of ConsentCookie
You can’t perform that action at this time.