Script Blocking
Stop tracking scripts from running until the visitor agrees to them.
A consent banner on its own does not make a site compliant. If Google Analytics loads before the visitor clicks anything, consent was never asked for. Script blocking is what makes the banner mean something.
How to block a script
Take any tracking script and change two things: set type="text/plain" so the
browser will not run it, and add data-consentify naming the category it needs.
<script
type="text/plain"
data-consentify="analytics"
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"
></script>That is the whole change. When the visitor grants analytics, Consentify swaps the placeholder for a real script tag and the browser runs it. If they decline, it never runs.
Inline scripts work the same way:
<script type="text/plain" data-consentify="marketing">
fbq('init', '123456789');
</script>Choosing the category
Use one of the category keys configured for your site. The defaults are:
| Category | Use it for |
|---|---|
necessary | Runs always - session, security, load balancing |
analytics | Google Analytics, Plausible, PostHog, Hotjar |
marketing | Meta Pixel, Google Ads, LinkedIn Insight, TikTok |
Scripts in a category your site marks required - necessary by default -
run as soon as the widget loads, whether or not a choice has been made. Anything
else waits. If you renamed your required category, use that name; the rule
follows the site's configuration, not the literal word "necessary".
The category must match a key on your site exactly. A typo means the script is never unblocked, because no category by that name is ever granted.
Verifying it works
- Open your site in a private window.
- In DevTools, Network tab, confirm the tracking request is absent.
- Accept the category in the banner.
- The request appears without a page reload.
Then reload: it should fire immediately, because the choice is remembered.
Notes
- Order does not matter for where you put the tags: blocked scripts can appear before or after the Consentify script. Execution order between blocked scripts is preserved, so a loader and the inline call that depends on it still run in the order you wrote them.
- Changing your mind works. Revoking consent stops future page loads from running the script. Scripts already running stay until the page reloads - that is a browser limitation, not a Consentify one.
- Returning visitors get their scripts released as soon as the widget loads, with no banner shown.
- Scripts added after page load are not picked up automatically. Call
window.Consentify.getConsent()and insert them yourself.