Skip to content

Block trackers before they load

By OptinStack Team - Jun 28, 2026 - 2 min read

OptinStack blocks known third-party scripts and iframes from your published tracker inventory, plus resources you manually tag with consent categories, before they load. For known trackers it also intercepts writes to localStorage, sessionStorage, and document.cookie so storage is not written before consent. Unknown untagged resources are not universally blocked until they are scanned, classified, manually added, or tagged.

How blocking works

When the runtime loads, it wraps known tracker scripts and iframes so they do not execute until consent is granted. Each tracked resource is tagged with one of the four consent categories. When the visitor accepts a category, resources tagged to it are released.

Tag every tracker you add with the most relevant category. A script tagged marketing will not run until the visitor accepts marketing, even if they accepted analytics.

Use the data-optinstack-categories attribute on both script and iframe elements. If you assign more than one category, the resource stays blocked until every listed category is granted.

Allowlisting a tracker

Some trackers are essential to how your site works and should run without waiting for consent. Add them to the necessary allowlist so they bypass blocking. Reserve this for scripts your site genuinely cannot function without, such as a load balancer or fraud signal.

Tagging an existing script with its consent category
HTML
<!-- Tag any existing script with its consent category -->
<script src="https://example-analytics.com/lib.js" data-optinstack-categories="analytics"></script>

Storage and cookies are covered too

Blocking is not limited to scripts and iframes. The runtime also patches Storage.prototype.setItem (covering both localStorage and sessionStorage) and the document.cookie setter, so a known tracker that tries to write storage or cookies before consent is recorded as blocked instead. When consent is later withdrawn, previously written blocked keys are purged. This is DOM and storage enforcement only; it does not intercept beacons, fetch, image pixels, or network-layer requests.

Related articles

Getting started

Install OptinStack on your site

Add the OptinStack script tag, load it without slowing your page, and confirm the consent banner renders.

OptinStack Team · 3 min read

Consent management

The four consent categories explained

The four fixed consent categories: necessary, analytics, marketing, and preferences, and how their defaults behave.

OptinStack Team · 2 min read

Implementation

Integrate OptinStack with Google Tag Manager

Configure OptinStack with Google Tag Manager from start to finish, including the GTM template, Consent Mode v2 signals, defaults, triggers, consent settings, and testing.

OptinStack Team · 7 min read

How helpful was this article?