Skip to main content

window.OptSens

window.OptSens is available after the script loads. All methods are safe to call. If your code can run before the script loads, queue calls behind the ready event.

Core methods​

MethodDescription
OptSens.acceptAll()Accept all consent categories
OptSens.rejectAll()Reject all (necessary stays on)
OptSens.showBanner()Show the consent banner (layer 1)
OptSens.showPreferences()Open the preference center (layer 2)
OptSens.withdrawConsent()Withdraw an earlier choice: send "denied" to Google Consent Mode, Microsoft UET and Amazon, remove cookies when automatic cookie removal is on, log the withdrawal, emit consent_update, clear the stored consent and reload the page, which shows the banner again. Without an earlier choice it only clears consent and shows the banner
OptSens.renew()Lighter variant that clears consent and shows the banner again, without emitting consent_update

State checks​

MethodReturnsDescription
OptSens.hasConsent('analytics')booleanWhether a specific category is consented
OptSens.isConsentGiven()booleanWhether the visitor made any consent choice
OptSens.getActiveCategories()string[]Consented categories, for example ['necessary', 'analytics']
OptSens.consentobjectFull consent state object
OptSens.configobjectBanner configuration
OptSens.versionstringScript version
OptSens.debug()-Print debug information to the console

Language​

MethodDescription
OptSens.changeLanguage('de')Switch the banner language. The language must be in the domain's available languages.
OptSens.on('ready', function () {
if (OptSens.hasConsent('analytics')) {
// initialize analytics
}
});