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
| Method | Description |
|---|---|
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
| Method | Returns | Description |
|---|---|---|
OptSens.hasConsent('analytics') | boolean | Whether a specific category is consented |
OptSens.isConsentGiven() | boolean | Whether the visitor made any consent choice |
OptSens.getActiveCategories() | string[] | Consented categories, for example ['necessary', 'analytics'] |
OptSens.consent | object | Full consent state object |
OptSens.config | object | Banner configuration |
OptSens.version | string | Script version |
OptSens.debug() | - | Print debug information to the console |
Language
| Method | Description |
|---|---|
OptSens.changeLanguage('de') | Switch the banner language. The language must be in the domain's available languages. |
Example: check consent before initializing
OptSens.on('ready', function () {
if (OptSens.hasConsent('analytics')) {
// initialize analytics
}
});