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
| Area | Page |
|---|---|
| Methods and properties on the global object | window.OptSens |
| Consent lifecycle events | Events |
| Gate inline scripts and iframes on consent | Manual script tagging |
| Load scripts conditionally from code | Programmatic script loading |
| React, Vue, Next.js and other SPAs | SPA support |
| Events pushed to the GTM dataLayer | GTM dataLayer |
| How automatic blocking works | Auto-blocking |
Cookies set by OptSens
| Cookie | Purpose | Lifetime | Contains |
|---|---|---|---|
os_consent | Consent state (cross-subdomain) | Set per domain, 30 to 360 days (default 180) | Category flags and language, about 60 bytes (no personal data) |
os_sid | Session tracking for billing | 15 minutes (sliding window) | Random session ID (16 hex characters) |
euconsent-v2 | IAB TCF consent string | Configured per domain | TC string (IAB standard) |
localStorage keys
| Key | Purpose |
|---|---|
os_consent | Full consent state (categories plus TC/AC strings) |
os_visitor_id | Persistent visitor ID for cross-domain sync |
os_banner_lang | The 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.