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()Clear consent, remove iframe placeholders, emit consent_update and show the banner again
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
}
});