Skip to main content

CookieYes Consent Banner Action API

Last updated on June 10, 2024

The CookieYes Banner Action API allows you to control the actions available on the CookieYes consent banner. This API  provides a simple way to accept all cookies, reject all cookies or save custom cookie preferences.

Function

performBannerAction(action)

Performs the specified action on the CookieYes consent banner.

Parameters

action (string): The action to be performed on the banner. Possible values are:

  • accept_all“: Accepts all cookies, equivalent to clicking “Accept All” on the banner.
  • accept_partial“: Saves custom cookie preferences. Before calling this action, you must set the checkbox status for each cookie category using JavaScript.
  • reject“: Rejects all cookies, equivalent to clicking “Reject” on the banner.

Usage

Accept All Cookies

To accept all cookies, trigger the API with the action “accept_all”.

performBannerAction("accept_all");

Reject All Cookies

To reject all cookies, trigger the API with the action “reject”.

performBannerAction("reject");

Custom Preferences

To set custom cookie preferences, set the checkbox statuses using JavaScript and call the API to save the custom preferences.

// Update preferences in the UI using JavaScript
document.getElementById("<id of the checkbox>").checked = true;
document.getElementById("<id of the checkbox>").checked = false;
// Save the updated preferences
performBannerAction("accept_partial");
// This will save the preferences as set by the checkboxes.

Example

This example demonstrates how to update cookie preferences in the UI using JavaScript and then save those preferences using the performBannerAction function.





// Update preferences in the UI using JavaScript 
// analytics
document.getElementById("ckySwitchanalytics").checked = true;
// advertisement
document.getElementById("ckySwitchadvertisement").checked =  false;
// functional
document.getElementById("ckySwitchfunctional").checked = true;
// performance
document.getElementById("ckySwitchperformance").checked = false;
// other
document.getElementById("ckySwitchother").checked = false;
// Save the updated preferences
performBannerAction("accept_partial");
// This will save the preferences as set by the checkboxes.

Have more questions?

Reach out to us and we'll answer them.

Contact us