Methods / Functions

once initialized, CookieHub is always available in the window object and can be used anywhere on your website. CookieHub exposes a few public methods that can be used to extend the functionality as listed below.

load(options, complete, error)

Used to initialize CookieHub. This is a part of the default provided code and should only be called once on each page load. If CookieHub has been initialized previously, any attempt to initialize it again will be ignored.

Parameters

Parameter Type Description Default value
options object Object containing a list of options and events. {}
complete function You can pass a callback function that will be fired when CookieHub has finished loading.
error function You can pass a callback function that will be fired if any error occurs preventing CookieHub from loading.

hasAnswered()

Used to check if the user has already made cookie choices by allowing all cookies or saving settings.Parameters

This method doesn't allow any parameters

Return value

Returns boolean value, either true if user has made any choices or false if not.

Sample

if (window.cookiehub.hasAnswered()) {
console.log('User has answered');
}

hasConsented(category)

Used to check if the user has allowed the cookie category specified in the category parameter.

Parameters

Parameter Type Description Default value
category string The name or id of the cookie category that should be checked

Return value

Returns boolean value, either true if user has allowed/consented the category or false if not.

Sample

if (window.cookiehub.hasConsented("analytics")) {
console.log('Analytics category is allowed');
}

openDialog()

Open the CookieHub dialog usually only shown on first load.

Parameters

This method doesn't allow any parameters

Sample

if (!window.cookiehub.hasAnswered()) {
window.cookiehub.openDialog();
}

closeDialog()

Open the CookieHub dialog if it's still open.

Parameters

This method doesn't allow any parameters

Sample

setTimeout(function() {
window.cookiehub.closeDialog();
}, 60000);

openSettings()

Open the CookieHub settings dialog. This may be useful if you choose to hide the settings icon which is usually used to open the CookieHub settings dialog and want to create a custom link or button to open the dialog instead.

Parameters

This method doesn't allow any parameters

Sample

window.cookiehub.openSettings();

closeSettings()

Close the CookieHub settings dialog.

Parameters

This method doesn't allow any parameters

Sample

window.cookiehub.closeSettings();

allowAll()

Allows all cookie categories. This method can be used to offer alternative way of consenting to all cookie categories.

Parameters

This method doesn't allow any parameters

Sample

window.cookiehub.allowAll();

denyAll()

Denys all cookie categories. This method can be used to offer alternative way of revoking consent to all cookie categories.

Parameters

This method doesn't allow any parameters

Sample

window.cookiehub.denyAll();

Still need help? Contact Us Contact Us