Events

You can extend the functionality of CookieHub using javascript events as described below. Events are fired any time cookie choices are made and when CookieHub has finished loading.

Here is a complete list of events available:

Event Parameters Description
onInitialise status Fired when CookieHub has finished loading.
onAllow category Fired any time a cookie category is allowed that was previously disallowed.
onRevoke category Fired any time a cookie category consent is revoked for a category that was previously allowed.
onStatusChange status, previousState Fired any time users make changes to cookie choices and click the Save Settings or if the Allow All Cookies button is clicked.

The default provided CookieHub javascript code should looks like this:

<script type="text/javascript">
var cpm = {};
(function(h,u,b){
var d=h.getElementsByTagName("script")[0],e=h.createElement("script");
e.async=true;e.src='https://cookiehub.net/c2/8ee797f1.js';
e.onload=function(){u.cookiehub.load(b);}
d.parentNode.insertBefore(e,d);
})(document,window,cpm);
</script>

Any options and events should be placed in the cpm object which is passed to the CookieHub load method which initializes CookieHub.

Below is a sample code showing how all events are used.

<script type="text/javascript">
var cpm = {
onInitialise: function(status) {
if (this.hasConsented('analytics')) {
console.log('The analytics category is allowed');
}
},
onStatusChange: function(status, previousStatus)
{
if (this.hasConsented("analytics"))
{
console.log('The analytics category is allowed');
}
},
onAllow: function(category) {
if (category == 'analytics') {
console.log('The analytics category was just allowed');
}
},
onRevoke: function(category) {
if (category == 'analytics') {
console.log('The analytics category was just revoked');
}
},
};
(function(h,u,b){
var d=h.getElementsByTagName("script")[0],e=h.createElement("script");
e.async=true;e.src='https://cookiehub.net/c2/8ee797f1.js';
e.onload=function(){u.cookiehub.load(b);}
d.parentNode.insertBefore(e,d);
})(document,window,cpm);
</script>

Still need help? Contact Us Contact Us