What the consent SDK does
The ConsentPlix SDK is a single script, cp.min.js, that you add to your site's head. It is about 13KB minified and about 5KB compressed, with no dependencies. On every page load it:
- Sets Google Consent Mode v2 defaults to "denied" so Google tags wait for a choice.
- Holds back known trackers, including Google Tag Manager and Analytics, Meta Pixel, Microsoft Clarity, Hotjar, TikTok, Mixpanel and Segment, until the visitor allows them.
- Loads your site's notice, languages and banner style from the ConsentPlix API.
- Shows the banner to new visitors, or applies the saved choice for returning visitors.
- Records each choice with the hash of the notice shown, signs it and stores it in the consent ledger.
Install
<script
src="https://cdn.consentplix.com/cp.min.js"
data-site-token="YOUR_SITE_TOKEN"
data-api-base="https://api.consentplix.com"
></script> Place it above other analytics and marketing scripts. Framework examples for Astro, Next.js, React and WordPress are in the quickstart.
Built-in banner or your own
In Standard mode the SDK draws a banner using your brand colours, position and languages from the console. In Headless Pro mode it draws nothing and wires up your own HTML instead, through attributes such as data-cp-banner, data-cp-accept="all", data-cp-reject="essential" and data-cp-toggle="analytics". This website's own consent banner runs on Headless Pro.
Categories and blocking
The SDK uses three categories: essential (always on), analytics and marketing. To hold back any script until consent, set type="text/plain" and data-cp-category. For iframes such as YouTube, use data-cp-src in place of src. See cookie and tracker blocking.
Privacy signals and re-consent
- If a visitor's browser sends Global Privacy Control or Do Not Track and they have not chosen before, the SDK applies essential-only consent.
- When you change your notice, its hash changes and returning visitors are asked again, so every record matches the notice the person actually saw.
- Withdrawing consent clears the saved choice, records the withdrawal and reloads the page without the blocked scripts.
Listen for changes
Each choice fires a cp_consent_updated browser event and a matching dataLayer event for Google Tag Manager, with the granted and denied categories.