Skip to main content

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

CategoryWhat it covers
necessaryAlways allowed: session, security, the CMP itself
functionalChat widgets, language preferences, user settings
analyticsGoogle Analytics, Hotjar, Clarity, Matomo
advertisingFacebook Pixel, Google Ads, TikTok, LinkedIn
performanceSpeed 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

AttributeOnDescription
data-os-category="analytics"script, iframe, img, video, audio, embed, object, sourceBlock until this category is consented
type="text/plain"scriptRequired together with data-os-category to prevent execution
data-os-src="URL"iframe, img, video and other media elementsStores the original source. Use instead of src for manual tagging
data-os-ignorescriptTell OptSens not to auto-block this script, even if its URL matches a known tracker pattern