You can add ConsentPlix to any website with one script tag. This guide covers plain HTML and the most common frameworks.
Before you start
You need a site token. Log in to the ConsentPlix Console, go to Sites, choose your site and open Overview. Live tokens start with dpdp_live_. The token is safe to put in your page source; it only identifies your site.
1. Add the script
Paste this inside the <head> of every page. Place it before any analytics, ad pixel or tag manager script, so ConsentPlix can hold those back until the visitor opts in.
<!-- ConsentPlix DPDP consent engine -->
<script
src="https://cdn.consentplix.com/cp.min.js"
data-site-token="YOUR_SITE_TOKEN"
data-api-base="https://api.consentplix.com"
></script>
2. Framework examples
Astro
Add the script to your base layout, for example src/layouts/BaseLayout.astro. The is:inline directive stops Astro from bundling it.
---
const siteToken = import.meta.env.PUBLIC_CONSENTPLIX_TOKEN;
---
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
is:inline
src="https://cdn.consentplix.com/cp.min.js"
data-site-token={siteToken}
data-api-base="https://api.consentplix.com"
></script>
</head>
<body>
<slot />
</body>
</html>
Next.js (App Router)
Use next/script with beforeInteractive in app/layout.tsx so the script loads before your own code runs.
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<Script
src="https://cdn.consentplix.com/cp.min.js"
data-site-token={process.env.NEXT_PUBLIC_CONSENTPLIX_TOKEN}
data-api-base="https://api.consentplix.com"
strategy="beforeInteractive"
/>
{children}
</body>
</html>
);
}
React with Vite
Add the script to index.html. Vite replaces %VITE_CONSENTPLIX_TOKEN% with the value from your .env file at build time.
<head>
<meta charset="UTF-8" />
<script
src="https://cdn.consentplix.com/cp.min.js"
data-site-token="%VITE_CONSENTPLIX_TOKEN%"
data-api-base="https://api.consentplix.com"
></script>
</head>
WordPress & WooCommerce
Add the script tag to your theme’s header.php just after <head>, or use the free WPCode plugin. Make sure it sits above any analytics plugin output. For step-by-step instructions, script blocking, and WooCommerce settings, see our detailed WordPress DPDP Compliance Guide.
Shopify & E-Commerce
In your Shopify Admin, navigate to Online Store > Themes > Edit Code, open layout/theme.liquid, and paste the script snippet inside <head> before any marketing pixels or Google Tag Manager containers. For complete instructions on preserving Google Ads attribution and Meta Pixel conversion modeling, see our Shopify DPDP Compliance Guide.
3. Script attributes
| Attribute | Required | Description |
|---|---|---|
data-site-token |
Yes | Your site token from the Console. data-cp-site-token also works. |
data-api-base |
Recommended | The ConsentPlix API address, https://api.consentplix.com. If left out, the SDK uses the origin the script was loaded from. |
data-lang |
No | Force a notice language such as hi or ta. If left out, the SDK uses the browser language when it is enabled for your site, otherwise your first configured language. |
Banner style, position, languages and whether to use the built-in banner or your own are set per site in the Console, not on the script tag.
Use your own banner (Headless Pro)
Set your site to Headless Pro in the Console. The SDK then draws nothing and instead wires up your own HTML through data-cp-* attributes:
| Attribute | What it does |
|---|---|
data-cp-banner |
The element the SDK shows to new visitors and hides after a choice |
data-cp-accept="all" |
Button: allow essential, analytics and marketing |
data-cp-reject="essential" |
Button: allow essential only |
data-cp-toggle="analytics" / "marketing" |
Checkbox for each optional category |
data-cp-accept="selected" |
Button: save whatever the checkboxes say |
data-cp-open / data-cp-close |
Reopen the banner with the current choices ticked, or hide it |
data-cp-withdraw |
Button: withdraw recorded consent |
data-cp-officer |
Filled with your grievance officer’s contact details |
data-cp-notice |
Filled with the notice for users under 18 |
data-cp-lang-select |
A <select> that switches notice language |
<div data-cp-banner>
<p>We use analytics and marketing cookies with your permission.</p>
<label><input type="checkbox" data-cp-toggle="analytics" /> Analytics</label>
<label><input type="checkbox" data-cp-toggle="marketing" /> Marketing</label>
<button data-cp-accept="all">Accept all</button>
<button data-cp-reject="essential">Essential only</button>
<button data-cp-accept="selected">Save choices</button>
<p>Grievance officer: <span data-cp-officer></span></p>
</div>
<button data-cp-open>Privacy settings</button>
To react to a choice in your own code, listen for the cp_consent_updated event. It is also pushed to dataLayer for Google Tag Manager.
window.addEventListener("cp_consent_updated", (e) => {
console.log(e.detail.granted, e.detail.denied);
});
4. Google Consent Mode v2
ConsentPlix sets Google Consent Mode v2 defaults to denied as soon as it loads, and sends an update when the visitor chooses. If your Google tag can load before the ConsentPlix script, add this default yourself above it:
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag("consent", "default", {
ad_storage: "denied",
analytics_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
wait_for_update: 500,
});
5. Check it works
- Open your site in a private browser window. The notice should appear.
- Open the browser’s developer tools and check that analytics and marketing scripts have not loaded.
- Accept one purpose and confirm only the matching scripts load.
- Reopen preferences from the consent button and withdraw. The scripts should stop on the next page load.
Next steps
- Mark your scripts so they wait for consent: cookie and tracker blocking.
- Set up notices in your users’ languages: consent notices and languages.
- Send consent changes to your backend: webhooks and API.