Add compliance tools to a custom-coded site
One script tag, first in your <head>. Framework notes, consent-held tags, CSP (with data-nonce), tracker alerts and the JavaScript API are below.
Installation steps
Grab your snippet
From Install in your dashboard, with your site ID already in it.
Add it first in <head>
Before analytics or Tag Manager, without async or defer, so auto-block can hold trackers.
Deploy
The banner and accessibility button start on load and show as live after the first visit.
Change settings in the dashboard
Colors, text, categories and region rules reach your site within minutes, no redeploy.
Copy your snippet from Install in your dashboard (Home, or a site's Widget tab) and put it first in the <head>, before any analytics tag.
Next.js (App Router)
Use next/script with beforeInteractive in app/layout.tsx. Next.js loads it before your other scripts without blocking first paint. On the Pages Router, put the same tag in pages/_document.tsx.
Don't load Google Analytics or the Meta Pixel with next/script (or @next/third-parties): it adds a preload for their files on every page, before consent and after a visitor says no, whatever type you give the tag. Write them as raw <script type="text/plain"> tags after the ComplyMo <Script>, as below; nothing is fetched until its category is allowed.
Don't leave them as plain async <script> tags either: React moves an async <script src> above the ComplyMo snippet in the page HTML, so the browser starts Google Analytics or the Meta Pixel before the widget runs, and auto-block can't stop it. The widget sets Google Consent Mode to denied as early as it runs, which keeps Google's tag cookieless only if your gtag('config') comes after the snippet; it does nothing for Meta. Hold them with text/plain. Or render them from a client component after consent, with onChange or the cw:consent event (JavaScript API, below).
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<Script src="https://www.complymo.com/embed/v1.js" data-project="cw_your_id"
data-autoblock="1" strategy="beforeInteractive" />
{/* Raw tags on purpose: next/script preloads its src even with type="text/plain". */}
<script type="text/plain" data-cookieconsent="analytics" async
src="https://www.googletagmanager.com/gtag/js?id=G-XXXX" />
<script type="text/plain" data-cookieconsent="analytics"
dangerouslySetInnerHTML={{ __html: `window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-XXXX');` }} />
<script type="text/plain" data-cookieconsent="marketing"
dangerouslySetInnerHTML={{ __html: `/* your Meta Pixel base code */` }} />
</head>
<body>{children}</body>
</html>
);
}Vite, React, Astro and other frameworks
Paste the plain script tag first in the <head> of your HTML shell (index.html or your base layout), without async or defer.
Only run on your domains
Sites added to ComplyMo now start with "Only run on my domains" on (Widget › Domains). The widget then runs on the site's own address, its subdomains (www, staging.…) and localhost. Anywhere else it stays hidden and logs one line in the browser console, so someone who copies your snippet can't use your plan or fill your consent log.
A preview or staging copy on another address (a vercel.app or netlify.app preview, a webflow.io staging site) shows no banner until you add that address under Widget › Domains. For preview addresses that change on every push, add a pattern with a name only you use, like myapp-*-myteam.vercel.app. A whole platform (vercel.app, webflow.io, co.uk) can't be added: anyone there could run your banner.
ComplyMo notes where it turned the widget away, and the Domains tab offers to allow those addresses in one click.
Content-Security-Policy
With an allowlist policy, add ComplyMo's origin to script-src and connect-src, plus style-src 'unsafe-inline' and img-src data:.
With a nonce policy (script-src 'nonce-…' 'strict-dynamic'), give the ComplyMo script tag your page's nonce; the widget puts the same nonce on the styles it adds. Keep connect-src for ComplyMo's origin. Browsers ignore 'unsafe-inline' when a nonce is present.
data-nonce: the widget reads the nonce from its own script tag, first the nonce attribute, then data-nonce. Use data-nonce="…" when a loader doesn't pass the nonce through to the final <script>.
On Next.js: Next.js puts the nonce on its preload and loader, but not on the <script> it finally creates for a beforeInteractive src. The widget then takes the nonce from the page's other nonced scripts; passing it as both nonce and data-nonce (read from the x-nonce header your proxy.ts set) names it outright. The layout must render dynamically for a per-request nonce.
# allowlist
script-src https://www.complymo.com; connect-src https://www.complymo.com;
style-src 'unsafe-inline'; img-src data:;
# nonce
script-src 'nonce-{NONCE}' 'strict-dynamic'; style-src 'nonce-{NONCE}';
connect-src https://www.complymo.com; img-src data:;
// Next.js app/layout.tsx, with proxy.ts setting the CSP header and x-nonce
import { headers } from "next/headers";
import Script from "next/script";
export default async function RootLayout({ children }: { children: React.ReactNode }) {
const nonce = (await headers()).get("x-nonce") ?? undefined;
return (
<html lang="en">
<head>
<Script src="https://www.complymo.com/embed/v1.js" data-project="cw_your_id"
data-autoblock="1" strategy="beforeInteractive" nonce={nonce} data-nonce={nonce} />
</head>
<body>{children}</body>
</html>
);
}Tracker alerts in your dashboard
A tracker file requested before the visitor chose shows under "Stop trackers firing early", with its source:
"<link> in <head>": preloaded, usually by next/script or @next/third-parties. The script didn't run, but the request still sent the visitor's IP to Google or Meta. Replace it with a raw <script type="text/plain" data-cookieconsent> tag; <Script type="text/plain"> doesn't help, since it's still preloaded.
"<script> in <head>": written into the page HTML. Rewrite it as type="text/plain".
"Injected at runtime": added by another script or Tag Manager. Set it to wait for consent there.
JavaScript API
window.CookieConsent has show(), acceptAll(), rejectAll(), getConsent() (null before a choice) and onChange(fn). Consent is an object of category to true or false.
Call acceptAll() and rejectAll() only from the visitor's own action: they record a choice.
The cw:consent event fires on document whenever consent is applied, including page load (in opt-out regions the default allows analytics). Read event.detail.
There is no server API: settings live in the dashboard.
window.CookieConsent?.show();
window.CookieConsent?.onChange((consent) => {
if (consent.analytics) loadAnalytics();
});
document.addEventListener("cw:consent", (e) => {
console.log((e as CustomEvent<Record<string, boolean>>).detail);
});
// TypeScript: declare it once, e.g. in types/complymo.d.ts
declare global {
interface Window {
CookieConsent?: {
show(): void;
acceptAll(): void;
rejectAll(): void;
getConsent(): Record<string, boolean> | null;
onChange(fn: (consent: Record<string, boolean>) => void): void;
};
}
}
export {};
