Script tag integration
The script tag is the universal way to add 1Consent. It works on any website regardless of stack — no build step, no package install. Paste one <script> into your <head> and the CMP (consent banner + preference center) loads on every page.
IAB TCF: Dashboard preview only
You can publish and install GDPR or US Privacy banners on any plan. Starter and Pro let you configure IAB TCF, save drafts and test them in the signed-in Dashboard. Website installation, public Preview URLs, and publication to Live or Staging are unavailable for IAB TCF.
Choose a setup
Decide how third-party scripts get gated behind consent:
| Automatic Setup | Performance Setup | |
|---|---|---|
| Best for | Quick start | Core Web Vitals |
| Effort | Just add the script | Mark third-party scripts with <template> |
| Trade-off | Checks script domains at runtime | Minimal runtime overhead |
- Automatic Setup — 1Consent holds scripts that match catalogue domains for the services in your published banner that require consent. In Services & cookies, look for services marked “Not blocked automatically”. Gate their scripts with a template (Performance Setup).
- Performance Setup — the
/manual/id/loader omits the autoblocker. Wrap optional third-party scripts and their initializers in<template>tags so those scripts load only after consent. Scripts you do not wrap are not held.
In Install & verify, Automatic Setup is the choice Load synchronously. Performance Setup is Load async; on a stage that serves an IAB TCF banner it reads Service-gated, synchronous, because IAB TCF banners load synchronously for now.
Installation
Add the script
After publishing a release to Live, copy the Live snippet from Install & verify in the Dashboard. Put it in the <head> of your website before the third-party scripts it governs:
<script src="https://web.cmp.1consent.app/id/YOUR_APP_ID.js"></script>Replace YOUR_APP_ID with the site ID from your Dashboard. The loader serves your published banner. With Automatic Setup, it also checks scripts for services it can block automatically.
With Automatic Setup, load 1Consent synchronously before any third-party scripts it needs to intercept.
Gate third-party scripts (Performance Setup)
For the performance-optimized path, replace each third-party <script> with a <template> carrying the service's tag name:
Before
<script src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"></script>After
<template data-1c-service-tag="google-analytics-4">
<script src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"></script>
</template>This example uses the catalogue key for Google Analytics 4. The data-1c-service-tag value must identify the service you actually configured: its catalogue key, exact service name, or runtime service ID. Do not use a provider name shared by several services as a service-specific gate. Keep any initialization script inside the same template as its loader; wrapping only the external script does not gate separate inline initialization. The wrapped scripts stay inert until the visitor consents to that service.
Async loading
With the Performance Setup, load 1Consent with async so it never blocks HTML parsing, and so a slow network can never hold up your page. Add fetchpriority="high" too: browsers such as Chrome otherwise download async scripts at low priority, behind images and fonts. Install & verify in the Dashboard generates the exact code for your published banners.
GDPR banners only: the loader is all you need.
<script src="https://web.cmp.1consent.app/manual/id/YOUR_APP_ID.js" async fetchpriority="high"></script>With a US Privacy banner: put the small API stub first in <head>, before any vendor script, then the async loader. Vendors can then call __gpp and __uspapi as soon as the page starts. The stub queues their calls until the banner answers them. Visitors routed to another banner get an immediate "does not apply" answer.
<script src="https://web.cmp.1consent.app/stub/v1/standard.js"></script>
<script src="https://web.cmp.1consent.app/manual/id/YOUR_APP_ID.js" async fetchpriority="high"></script>The stub file is about 3 KB and is cached by browsers, so most page views load it without a request. For the fastest start, choose Inline stub in the Dashboard and paste the stub into the page instead. The Dashboard also shows:
- the stub URL, so your build can download the current stub and inline it on every deploy;
- the
sha256hash to add toscript-srcif your Content Security Policy blocks inline scripts.
Add the stub only while a US Privacy banner is published. On a GDPR-only site nothing answers it, so vendors would wait for an answer until they time out. When you publish US routing for a GDPR-only site, Install & verify adds the stub to the install code: update your pages then. If you later remove the US banner from your routing, remove the stub too.
Keep the loader synchronous for Automatic Setup, so it can hold scripts before they run, and for IAB TCF.
Preview before going Live
For GDPR and US Privacy, both the host and file suffix matter:
| Stage | Script URL | What it serves |
|---|---|---|
| Preview | https://cmp.1consent.app/id/YOUR_APP_ID.preview.js | Your latest unpublished edits, for testing |
| Live | https://web.cmp.1consent.app/id/YOUR_APP_ID.js | What your visitors see (your published config) |
Use the Preview URL on your test site to check unpublished GDPR or US Privacy changes:
<script src="https://cmp.1consent.app/id/YOUR_APP_ID.preview.js"></script>When you're happy, publish in the dashboard and copy the Live URL for your chosen setup. Performance Setup uses the /manual/id/ path for Preview, Staging and Live.
Before the site has a selected framework for its published routing, inspect the intended draft explicitly with the framework's public short ID:
<script src="https://cmp.1consent.app/id/YOUR_APP_ID.preview.js?frameworkId=YOUR_FRAMEWORK_ID"></script>Framework overrides are a Preview-only inspection control. They are rejected on Live and Staging; they never select a visitor's published legal framework.
The Install & verify page in your Dashboard has a Preview / Live switch that generates the exact URL for each stage — copy it from there. Pro plans also get a Staging stage (…/id/YOUR_APP_ID.staging.js) for an extra promotion step before Live.
Content Security Policy with Trusted Types
If your site enforces Trusted Types (require-trusted-types-for 'script'), 1Consent inserts its scripts through a policy named 1consent. Each 1Consent script creates its own copy of that policy, so allow the name with 'allow-duplicates' in the same header:
Content-Security-Policy: require-trusted-types-for 'script'; trusted-types 1consent 'allow-duplicates'Keep your own policy names in the same trusted-types list. 'allow-duplicates' applies to every name in that list, not only to 1consent: any script running on the page can then create another policy under an allowed name, including one of yours. Weigh that against your Trusted Types setup.
The 1consent policy covers the scripts 1Consent loads itself, and the scripts and markup on your page that it holds until the visitor consents and then inserts unchanged: templates, scripts the Autoblocker holds, and <OneConsent> children in React. Raw HTML your code hands over as a plain string, such as a document.write call the Autoblocker rewrites or a dangerouslySetInnerHTML string inside <OneConsent>, does not become trusted: it stays subject to your own policies. Markup you pass as TrustedHTML stays trusted after 1Consent wraps it.
If the header does not allow 1consent, a console warning names the line to add. On a page that enforces Trusted Types, the banner then does not load, held scripts stay held, and a client render of <OneConsent> throws.
Match the website's theme
The loaded CMP exposes a browser API for appearance changes:
window.__1consent.setThemeMode('dark');
window.__1consent.setThemeMode('light');
window.__1consent.setThemeMode('auto'); // Resolve from the device preferencePublish a Light & Dark theme in the dashboard so both palettes are available. Call
setThemeMode whenever your site's resolved appearance changes. It updates an open
banner or preference center and also applies to views opened later, without changing
the visitor's consent choices.
The website owns its saved preference. Reapply it on every page load after
window.__1consent becomes available; the bootstrap loads the runtime in a separate
script, so the bootstrap's own load event alone does not guarantee API readiness.
For a website with a System option, forward its resolved 'light' or 'dark'
value again whenever the device preference changes. This also keeps the page and CMP
aligned when another tab changes the saved website preference.
Next steps
- WordPress integration — the official plugin injects the script for you
- React integration — typed service names and parse-time gating for React, Next.js, Vite, Remix, and Astro