Skip to main content

Retrieving Consent Data Using getCkyConsent() API

Last updated on March 14, 2024

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()

Call getCkyConsent() to retrieve the consent data:

getCkyConsent();

It returns an object containing the consent data:

{
  "activeLaw": "gdpr",
  "categories": {
    "necessary": true,
    "functional": false,
    "analytics": false,
    "performance": false,
    "advertisement": false
  },
  "isUserActionCompleted": true,
  "consentID": "bFl2eFJBN05VS21WNWk5enpRNTNEZ3hxR0dDc3VmcFM",
  "languageCode": "en"
}

The key properties are:

PropertyTypeDescription
activeLawstringThe legal framework under which the consent is active.
categoriesobjectUser consent status for different categories.
isUserActionCompletedbooleanIndicates whether the user interacted with the banner.
consentIDstringUnique identifier for the user’s consent.
languageCodestringISO-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

Check if the user has accepted analytics cookies:

if (window.getCkyConsent) {
  const consent = getCkyConsent();

  if (consent.categories.analytics) {
    // Load analytics cookies
  } else {
    // User has not accepted analytics cookies
  }
}

Check if the user has completed an action on the banner:

if (getCkyConsent().isUserActionCompleted) {
  // User has made a choice
} else {
  // Show banner to get user consent
}

Have more questions?

Reach out to us and we'll answer them.

Contact us