Blocking scripts until consent
Tag a script, iframe or image with a category, and PrivacyQuick releases it only after the visitor allows that category.
Browsers skip any <script> whose type isn't JavaScript. PrivacyQuick relies on this. You mark a script as type="text/plain" so it doesn't run, and add a data-category. Once the visitor allows that category, the SDK swaps in a real script, and it runs as if it had been there all along.
You choose which category each tag belongs to:
| Category | Use it for |
|---|---|
analytics | Statistics and measurement: Google Analytics, Hotjar, Matomo, Microsoft Clarity. |
functional | Extra features: chat widgets, maps, embedded content, remembered preferences. |
marketing | Advertising and retargeting: Meta Pixel, Google Ads, LinkedIn Insight, TikTok Pixel. |
Leave strictly necessary scripts alone. Anything without the text/plain type runs as normal, unless the optional blocker below recognises it.
Automatic blocking (optional)
If you'd rather not tag every tracker, add our blocker. It recognises scripts from more than 200 known analytics and advertising domains, including Google Analytics, Meta Pixel, Hotjar, Microsoft Clarity, LinkedIn and TikTok. It holds them until the visitor allows that category. It's available on every plan.
Put it first in the <head>, directly above your PrivacyQuick snippet. Don't add async or defer, because it has to load before the scripts it holds.
<script src="https://cdn.privacyquick.com/v1/autoblock.js"></script>
<script src="https://cdn.privacyquick.com/v1/privacy.js" data-site-id="pq_xxxxxxxxxx" async></script>
The dashboard's Install card has this line ready to copy.
What it doesn't do
- Script tags written directly in your HTML can still be downloaded. Browsers fetch these early, before any script can step in. The blocker stops the file from running, but the request still reaches the tracker's server. Google's standard
gtag.jstag is one example. Tag those by hand if nothing should be requested before consent. Trackers that load through a snippet, such as Meta Pixel and Hotjar, aren't requested at all. - Iframes and images written in your HTML can still load. The browser fetches them early, the same way as scripts. The blocker holds the ones your own scripts add or change, such as an image created with JavaScript. Tag the others yourself, as shown in Iframes and images. This includes YouTube and Maps embeds, and tracking pixels in the page markup.
- It only knows the listed domains. Scripts from other domains, your own domain and inline code run as normal. So do chat widgets, payment forms, error monitoring and tag manager containers.
- Your banner must offer the category. If it has no Marketing category, advertising scripts stay held for every visitor. Run a scan so the banner picks up what your site uses.
onloadcallbacks aren't kept. If your code waits for a tracker'sonloadevent, tag that script by hand.
Change what it holds
Add domains to the blocker's tag, separated by spaces. Subdomains are included.
<script src="https://cdn.privacyquick.com/v1/autoblock.js"
data-allow="hotjar.com"
data-analytics="stats.example.com"
data-marketing="ads.example.net"></script>
data-allow means never hold that domain. The other attributes add a domain to that category. To keep Google tags loaded and let Consent Mode adjust them, use data-allow="googletagmanager.com".
Scripts you tag by hand keep the category you gave them. After you install the blocker, follow the checklist at the end of this page.
Scripts
For an external script, change the type and add a category. Keep src as it is. Browsers don't download scripts of an unknown type, so nothing is fetched before consent.
<!-- before -->
<script src="https://example-analytics.com/tag.js" async></script>
<!-- after -->
<script type="text/plain" data-category="analytics" src="https://example-analytics.com/tag.js" async></script>
Inline scripts work the same way:
<script type="text/plain" data-category="marketing">
console.log('Runs only after the visitor allows marketing');
</script>
When the script is released, every attribute except type is copied to the new script, including id, async, defer, crossorigin and any data-* attributes.
ES modules and other script types
If the original script wasn't plain JavaScript, put its real type in data-type. The SDK uses it when the script is released.
<script type="text/plain" data-type="module" data-category="analytics" src="/js/analytics.mjs"></script>
Execution order
Released external scripts without async run in the order they appear on the page. Inline scripts run the moment they're released, so they don't wait for an external script released just before them. Snippets like Google's gtag() queue their calls, so this doesn't matter for them. It does matter if your inline code calls a library straight away. In that case, move the code into an external file, or start it from the library's own load callback.
Iframes and images
For iframes and images, move the URL from src to data-src and add a category. You don't need to change the type. The SDK sets src when the category is allowed.
The automatic blocker also holds iframes and images from the listed domains when your own JavaScript creates them or sets their src. It can't stop the ones already in your HTML, so tag those by hand as shown here.
<iframe data-src="https://www.example.com/embed/123" data-category="functional" width="640" height="360" title="Embedded content"></iframe>
<img data-src="https://ads.example.com/pixel.gif" data-category="marketing" width="1" height="1" alt="">
Use data-src only on iframes and images. On a <script>, keep the URL in src. A script that only has data-src won't load.
More than one category
If a tag needs several categories, list them separated by spaces or commas. The tag is released only when the visitor has allowed all of them.
<script type="text/plain" data-category="analytics marketing" src="https://example.com/combined.js"></script>
When tags are released
The SDK looks for tagged elements:
- as soon as it loads, if the visitor already made a choice on an earlier visit,
- when the document finishes parsing (
DOMContentLoaded), - when your site settings arrive from our server, and
- after every choice the visitor makes.
Elements that your own JavaScript adds later aren't watched. If you inject consent-dependent code at runtime, check PrivacyQuick.has('analytics') first. See the JavaScript API.
Only categories your banner offers can be released. If a tag uses marketing but your banner has no Marketing category, that tag never runs. By default, the banner's categories come from your cookie scans, so a category appears once a scan finds something that belongs in it. If you tag a script before the next scan, run a scan or add the category by hand in the banner settings.
When consent is withdrawn
A script that has already run can't be stopped. So if a visitor switches off a category whose tags already ran on the current page, the SDK reloads the page. After the reload, those tags stay blocked.
The SDK doesn't delete cookies that third-party scripts already set. They expire on their own schedule, and they're no longer refreshed or read by scripts that no longer run. If you want to remove your own first-party analytics cookies right away, do it in a change listener. The listener runs before the reload:
<script>
document.addEventListener('pq:consent', function (e) {
if (e.detail.categories.indexOf('analytics') < 0) {
document.cookie.split(';').forEach(function (c) {
var name = c.split('=')[0].trim();
// set domain to the one your analytics cookies use
if (/^_ga/.test(name)) document.cookie = name + '=; Max-Age=0; path=/; domain=.example.com';
});
}
});
</script>
Google Tag Manager
We recommend that you don't block the GTM container itself. Load it normally and let Consent Mode control what fires:
- Google tags in GTM (GA4, Google Ads, Floodlight) read the Consent Mode signals that PrivacyQuick sends.
- For other tags in GTM, such as Meta, Hotjar or LinkedIn, set Additional consent checks in each tag's consent settings, for example
ad_storagefor advertising tags andanalytics_storagefor analytics tags.
The Google Consent Mode page has the full GTM setup. If you'd rather keep GTM off the page completely until consent, you can tag the container snippet as analytics or marketing. But then nothing in GTM runs before consent, including tags that don't need it.
Examples
Google Analytics 4 (gtag.js)
Before:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
After:
<script type="text/plain" data-category="analytics" async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script type="text/plain" data-category="analytics">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
With this setup, GA4 doesn't load at all until consent. If you'd rather keep GA4 loaded and let Google adjust its behaviour through Consent Mode, leave the snippet untagged. See Google Consent Mode v2.
Meta Pixel
Before:
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/></noscript>
After:
<script type="text/plain" data-category="marketing">
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
Remove the <noscript> image. It only fires when JavaScript is off, and in that case the banner can't ask for consent.
The script defines fbq only once it's released. If other code on your site calls fbq('track', …), check first that it exists: if (window.fbq) fbq('track', 'Purchase');
YouTube embed
Before:
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
title="YouTube video" allowfullscreen></iframe>
After:
<iframe width="560" height="315" data-src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
data-category="marketing" title="YouTube video" allowfullscreen></iframe>
<p>This video loads after you allow marketing cookies.
<a href="#" onclick="window.PrivacyQuick && PrivacyQuick.open(); return false;">Cookie settings</a></p>
Until consent, the iframe is empty, so a short note with a settings link helps visitors understand why. Some sites treat video embeds as functional instead. Pick the category your cookie policy describes.
Hotjar
Before:
<script>
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:YOUR_SITE_ID,hjsv:6};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
After:
<script type="text/plain" data-category="analytics">
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:YOUR_SITE_ID,hjsv:6};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
Checklist
- The PrivacyQuick snippet is in the
<head>of every page. - Every non-essential script has
type="text/plain"and adata-category, or is held by the automatic blocker. Every iframe and image hasdata-srcand adata-category. - Your banner offers each category you used.
- In a private window, the Network tab shows no tagged requests before you choose.
- Run a free scan to spot trackers you missed.