Manual script tagging
For inline scripts that should wait for consent, set
type="text/plain" and add data-os-category:
<!-- This script will NOT execute until analytics is consented -->
<script type="text/plain" data-os-category="analytics">
gtag('config', 'GA-XXXXX');
console.log('Analytics initialized');
</script>
<!-- Multiple categories (OR logic: runs if ANY is consented) -->
<script type="text/plain" data-os-category="analytics,advertising">
trackConversion();
</script>
Supported categories
| Category | What it covers |
|---|---|
necessary | Always allowed: session, security, the CMP itself |
functional | Chat widgets, language preferences, user settings |
analytics | Google Analytics, Hotjar, Clarity, Matomo |
advertising | Facebook Pixel, Google Ads, TikTok, LinkedIn |
performance | Speed monitoring, A/B testing tools, CDN optimization |
Manual tagging for iframes
<!-- Blocked until advertising consent -->
<iframe data-os-category="advertising"
data-os-src="https://www.youtube.com/embed/VIDEO_ID"
width="560" height="315"></iframe>
For iframes, use data-os-src instead of src. The browser then cannot load the iframe before the CMP blocks it.
Exempt a script from auto-blocking
OptSens also auto-blocks third-party scripts that match known tracker
patterns, with no tagging required. To exempt one specific script from that
automatic blocking, add data-os-ignore:
<script src="/js/first-party-widget.js" data-os-ignore></script>
The script then loads normally, even if its URL matches a known pattern.
Put data-os-ignore directly on the script tag in your markup, as shown
above. It needs to be present before the script starts loading. Adding it
from JavaScript after the src is set can be too late.
Data attributes reference
| Attribute | On | Description |
|---|---|---|
data-os-category="analytics" | script, iframe, img, video, audio, embed, object, source | Block until this category is consented |
type="text/plain" | script | Required together with data-os-category to prevent execution |
data-os-src="URL" | iframe, img, video and other media elements | Stores the original source. Use instead of src for manual tagging |
data-os-ignore | script | Tell OptSens not to auto-block this script, even if its URL matches a known tracker pattern |