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)
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. | {} |
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()) {<br> console.log('User has answered');<br>}
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")) {<br> console.log('Analytics category is allowed');<br>}
openDialog()
Open the CookieHub dialog usually only shown on first load.
Parameters
This method doesn't allow any parameters
Sample
if (!window.cookiehub.hasAnswered()) {<br> window.cookiehub.openDialog();<br>}
closeDialog()
Open the CookieHub dialog if it's still open.
Parameters
This method doesn't allow any parameters
Sample
setTimeout(function() {<br> window.cookiehub.closeDialog();<br>}, 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();