Skip to main content

Developer overview

The OptSens script exposes a client-side API on window.OptSens for reading consent state, reacting to consent changes and gating your own code on the visitor's choices. The script works without any extra code. Everything in this section is optional.

Installation

Add the script tag first in <head>, before any other scripts:

<script src="https://cdn.optsens.com/optsens.min.js/YOUR_DOMAIN_ID"></script>

See the install guides for platform-specific instructions.

What is available

AreaPage
Methods and properties on the global objectwindow.OptSens
Consent lifecycle eventsEvents
Gate inline scripts and iframes on consentManual script tagging
Load scripts conditionally from codeProgrammatic script loading
React, Vue, Next.js and other SPAsSPA support
Events pushed to the GTM dataLayerGTM dataLayer
How automatic blocking worksAuto-blocking

Cookies set by OptSens

CookiePurposeLifetimeContains
os_consentConsent state (cross-subdomain)Set per domain, 30 to 360 days (default 180)Category flags and language, about 60 bytes (no personal data)
os_sidSession tracking for billing15 minutes (sliding window)Random session ID (16 hex characters)
euconsent-v2IAB TCF consent stringConfigured per domainTC string (IAB standard)

localStorage keys

KeyPurpose
os_consentFull consent state (categories plus TC/AC strings)
os_visitor_idPersistent visitor ID for cross-domain sync
os_banner_langThe visitor's preferred banner language

Browser support

Chrome 60+, Firefox 63+, Safari 12+, Edge 79+, Opera 47+, Samsung Internet 8+. The script relies on Shadow DOM, MutationObserver and crypto.subtle, all standard in these versions. Older browsers are not supported.