API Reference
Complete API reference for Zest cookie consent toolkit
Global Object
All Zest methods are available on the global Zest object.
Initialization
Zest.init(config)
Manually initialize Zest with a configuration object. Only needed if autoInit is set to false.
Zest.init({
position: 'bottom-right',
theme: 'dark'
});UI Control
Zest.show()
Show the consent banner.
Zest.show(); Zest.hide()
Hide the consent banner.
Zest.hide(); Zest.showSettings()
Open the settings modal where users can customize their preferences.
Zest.showSettings(); Zest.hideSettings()
Close the settings modal.
Zest.hideSettings(); Zest.reset()
Clear all consent data and show the banner again. Useful for "reset preferences" buttons.
Zest.reset();Consent Management
Zest.getConsent()
Get the current consent state for all categories.
const consent = Zest.getConsent();
// Returns: { essential: true, functional: false, analytics: false, marketing: false } Zest.hasConsent(category)
Check if a specific category has consent.
if (Zest.hasConsent('analytics')) {
// Initialize analytics tracking
initAnalytics();
} Zest.hasConsentDecision()
Check if the user has made any consent decision (accept or reject).
if (!Zest.hasConsentDecision()) {
// User hasn't decided yet
console.log('Waiting for consent...');
} Zest.acceptAll()
Programmatically accept all consent categories.
Zest.acceptAll(); Zest.rejectAll()
Programmatically reject all non-essential categories.
Zest.rejectAll(); Zest.getConsentProof()
Get consent proof data for compliance records.
const proof = Zest.getConsentProof();
// Returns: {
// version: "1.0",
// timestamp: 1234567890,
// categories: { essential: true, ... }
// }Privacy Detection
Zest.isDoNotTrackEnabled()
Check if Do Not Track (DNT) or Global Privacy Control (GPC) is enabled.
if (Zest.isDoNotTrackEnabled()) {
console.log('User has privacy signals enabled');
} Zest.getDNTDetails()
Get details about which privacy signal is enabled.
const dnt = Zest.getDNTDetails();
// Returns: { enabled: true, source: 'gpc' }
// source can be: 'dnt', 'gpc', or nullConfiguration
Zest.getConfig()
Get the current Zest configuration.
const config = Zest.getConfig();
console.log(config.position); // 'bottom-right'Events
Zest.EVENTS
Object containing all event names for reference.
console.log(Zest.EVENTS);
// {
// READY: 'zest:ready',
// CONSENT: 'zest:consent',
// REJECT: 'zest:reject',
// CHANGE: 'zest:change',
// SHOW: 'zest:show',
// HIDE: 'zest:hide'
// }Practical Examples
Conditional Script Loading
document.addEventListener('zest:consent', (e) => {
if (e.detail.consent.analytics) {
// Load Google Analytics
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=GA-XXXXX';
document.head.appendChild(script);
}
});Cookie Preferences Button
<button onclick="Zest.showSettings()">Cookie Preferences</button>Reset Consent Link
<a href="#" onclick="Zest.reset(); return false;">Reset Cookie Settings</a>Check Before Tracking
function trackEvent(name, data) {
if (Zest.hasConsent('analytics')) {
gtag('event', name, data);
}
}Wait for Consent
async function waitForAnalyticsConsent() {
return new Promise((resolve) => {
if (Zest.hasConsent('analytics')) {
resolve(true);
return;
}
document.addEventListener('zest:consent', (e) => {
if (e.detail.consent.analytics) {
resolve(true);
}
});
document.addEventListener('zest:reject', () => {
resolve(false);
});
});
}
// Usage
const hasAnalytics = await waitForAnalyticsConsent();
if (hasAnalytics) {
initAnalytics();
} 