In some cases, you might need to be able to control cookie popup behavior programmatically or read the current state of the user consent. This is what Cookie-Script custom functions are designed for.
Get current user state
The function returns an object with 2 properties:
categories:['strict', 'performance', 'targeting', 'functionality', 'unclassified']
action : can be either
acceptmeans the user accepted to either one or many categories, list of accepted categories can be found in
rejectmeans the user rejected all cookies. In this case
categoriesproperty still stores
strictcookie category since it cannot be rejected.
categories : array with selected categories: [
Get available categories
Some websites do not use all the cookie categories. You can see what cookie categories are currently available for user to choose from using the following function:
The function returns an array of available category keys:
categories = ['performance', 'targeting', 'functionality', 'unclassified']
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 your popup has cookie categories, you can accept only some of them using this function:
You should also pass a list of accepted categories as an array. Following categories are allowed:
var categories = ['performance', 'targeting', 'functionality', 'unclassified']
Show / Hide cookie banner
You can show or hide cookie popup with the following functions:
This is the same as closing cookie popup with a close button or opening it by clicking on a cookie badge.
Cookie-Script also provides a variety of events to listen to Cookie Consent popup actions. We have created a detailed explanation of how custom event work.
A link that shows a popup
A link that asks the user to accept all cookies
Accept some categories