Retrieving Consent Data Using getCkyConsent() API
Last updated on July 8, 2025
On this page
Overview
CookieYes has introduced a new API function, getCkyConsent() allowing you to access consent data sorted by consent types easily. This function returns an object containing details about:
- Your consent choices for different cookie categories (necessary, functional, analytics, advertisement, etc.)
- Whether you have interacted with a cookie consent banner.
- Your unique consent ID.
- The active consent law (like GDPR) applicable to the website.
- The language code of the displayed banner
Using getCkyConsent()
The getCkyConsent() function is available only after the CookieYes banner has fully loaded. To ensure the API is accessible, use the cookieyes_banner_loaded event. See CookieYes Events on Cookie Banner Load for more details.
{
"activeLaw": "gdpr",
"categories": {
"necessary": true,
"functional": false,
"analytics": false,
"performance": false,
"advertisement": false
},
"isUserActionCompleted": true,
"consentID": "bFl2eFJBN05VS21WNWk5enpRNTNEZ3hxR0dDc3VmcFM",
"languageCode": "en"
}| Property | Type | Description |
|---|---|---|
| activeLaw | string | The legal framework under which the consent is active. |
| categories | object | User consent status for different categories. |
| isUserActionCompleted | boolean | Indicates whether the user interacted with the banner. |
| consentID | string | Unique identifier for the user’s consent. |
| languageCode | string | ISO-639-1 code of the displayed banner language. |
The getCkyConsent() function will not retrieve consent data if the CookieYes banner is disabled or the website is suspended. In such cases, the API will not be available.
Usage Example
if (window.getCkyConsent) {
const consent = getCkyConsent();
if (consent.categories.analytics) {
// Load analytics cookies
} else {
// User has not accepted analytics cookies
}
}if (getCkyConsent().isUserActionCompleted) {
// User has made a choice
} else {
// Show banner to get user consent
}