In some cases, you might need to be able to control your Cookie Banner behavior programmatically or read the current state of the user consent. CookieScript provides a set of functions that can be utilized to customize cookie controls programmatically.
These functions are accessible via
CookieScript.instance once it is initialized.
List of CookieScript functions and their description
||None||forces the Cookie Banner to appear.|
||None||forces the Cookie Banner to close|
returns the current state of the user's consent as an object with two properties:
action: 'accept' | 'reject' ;
categories: ['strict', 'performance', 'targeting', 'functionality', 'unclassified'].
returns an array of the available cookie categories as an array of the following cookie types:
['strict', 'performance', 'targeting', 'functionality', 'unclassified'].
||None||manually accepts all cookies.|
||None||manually rejects all cookies except for the strictly necessary.|
||string array categories||
manually accepts some of the cookie categories passed as its parameter:
Show / Hide Cookie Banner
CookieScript banner can be shown or hidden with the following functions:
This would be equivalent to making the banner to popup by clicking on the cookie badge or closing the banner by clicking on the close button.
Get the current consent state
The current cookie choice of the user can be read by calling this function:
The function returns an object with 2 properties:
categories:['strict', 'performance', 'targeting', 'functionality', 'unclassified']
action property can be either
categories property is an array of what the user has agreed to and may contain any of the following categories: [
||means that the user has agreed to one or more cookie categories. List of accepted categories can be found in the
||means the user rejected all cookies. In this case
Get available categories
Some websites do not require nor do they use all the cookie categories mentioned above. The cookie types that are currently available for the user to choose from can be seen using the following function:
The function returns an array of available category keys:
let categories = CookieScript.instance.categories()
// the variable categories is going to look
// somewhat like this:
// ['performance', 'targeting', 'functionality']
Accept all cookies
All cookies can be accepted with the following function:
This is the same as clicking Accept all button.
Reject all cookies
All cookies (except strictly necessary) can be rejected with this function:
This is the same as clicking Reject all button.
Accept some cookies
In case cookie categories are enabled, they can be accepted programmatically using this function:
The function requires a parameter with a list of the categories to be accepted, like in this example:
var categories = ['performance', 'targeting', 'functionality', 'unclassified'] CookieScript.instance.acceptAction(categories)
A link that makes the Cookie Banner to appear:
This is equivalent to clicking the CookieScript badge.
A link that lets the user to accept all cookies:
accepting all cookies.</a>
A link that lets the user to accept some categories
CookieScript also provides a variety of events to listen to Cookie Banner's actions. We have created a detailed explanation of how custom events work.