Launching soon
The managed service is not open yet: https://app.cleardp.in does not accept requests and accounts cannot be created. These pages describe the API as it ships. Join the waitlist to hear when it opens.
Install
Paste the tag into every page, just before </head>. The console's setup guide prints it with your script address and key filled in, plus React, Next.js and WordPress versions.
<script src="https://app.cleardp.in/sdk/cleardp.js" data-property-key="pk_live_…" data-api-base="https://app.cleardp.in" defer ></script>
| Attribute | What it does |
|---|---|
data-property-key | Required. The property's publishable key (pk_live_… or pk_test_…). |
data-api-base | The API origin: https://app.cleardp.in for the managed service, or your own host when self-hosted. |
data-language | Optional preferred notice language (ISO 639). Falls back to the notice's own default language. |
data-is-child | Optional. Only the exact value "true" marks the visitor as under 18; anything else is ignored. |
data-guardian-url | Optional. Where a guardian goes to be verified, shown to a child whose consent is waiting on one. |
Or start it yourself; the same settings become options:
ClearDP.init({
propertyKey: 'pk_live_…',
apiBase: 'https://app.cleardp.in',
language: 'hi', // optional: preferred notice language
});| Option | What it does |
|---|---|
propertyKey | Required. Publishable key. |
apiBase | API origin. A trailing slash is trimmed. |
language | Preferred notice language. |
principal | { externalId, portalToken } for a page that already knows its signed-in user: later choices are recorded against that user, and the browser's earlier anonymous choices are linked to them on load (as identify does). Needs a token minted by your server (see Signed-in users). Ignored without portalToken. |
headless | true renders no UI at all; you drive everything through the methods below. |
target | The element the banner mounts into. Default document.body. |
isChild | true marks the visitor as under 18. There is no false: the SDK never asserts that a visitor is an adult. |
guardianUrl | As data-guardian-url. |
Once loaded, the SDK is window.ClearDP. A visitor who has not chosen yet sees the banner; one who has does not, on any page, until a purpose changes or their consent lapses and needs their review again.
Keys and browser-safe routes
A secret key (sk_live_… or sk_test_…) belongs on your server. A publishable key (pk_…) is safe in page source because the API accepts it on the routes below and refuses it everywhere else with 403. That boundary is enforced server-side, not by convention.
| Route | Used for |
|---|---|
GET /v1/notice | The active notice the banner renders, in the visitor's language. |
GET /v1/notices/{noticeVersionId}/body | The full notice HTML behind "View full notice". |
GET /v1/purposes | The current purpose catalogue, including allowedForChildren. |
GET /v1/theme | White-label tokens. Every token passes a closed-allowlist validator, so nothing here can carry script into your page. |
GET /v1/principals/{ref}/consents | Only for an anon: reference with a publishable key (anything else is refused with 403). Answers 204 when nothing has been recorded for the visitor yet. |
POST /v1/consents | Records banner choices. Naming an externalId needs principal.portalToken. |
POST /v1/consents/withdraw | Records a withdrawal. Same portalToken rule. |
POST /v1/principals/link | identify(): links the browser's anonymous id to a signed-in user. Needs portalToken. |
POST /v1/impressions | Notice-impression beacons, 1 to 100 per batch. Answers 202 and stores no principal identifier. |
That list is complete. Everything else, including POST /v1/portal-links, artifact reads and chain verification, needs a secret key. Exact shapes are in the API reference.
Signed-in users
Until you say otherwise, the banner knows a visitor only by an anonymous id it keeps in the browser. To record choices against your own user instead, start the SDK with principal: { externalId, portalToken }. The browser must never be able to name a user on its own, or the publishable key would be an impersonation tool, so your server proves who is signed in: it mints a short-lived token with its secret key, and the page passes it in.
// Your server, after sign-in. SECRET key: it never goes to the browser. app.get('/api/cleardp-token', requireLogin, async (req, res) => { const r = await fetch('https://app.cleardp.in/v1/portal-links', { method: 'POST', headers: { Authorization: 'Bearer ' + process.env.CLEARDP_SECRET_KEY, 'Content-Type': 'application/json', }, body: JSON.stringify({ externalId: req.user.id, ttlSec: 900 }), }); const { token } = await r.json(); res.json({ token }); });
The page then starts the SDK itself rather than from the script tag, because the token has to come from your server first:
// Your page, once the user has signed in. const { token } = await fetch('/api/cleardp-token').then((r) => r.json()); ClearDP.init({ propertyKey: 'pk_live_…', apiBase: 'https://app.cleardp.in', principal: { externalId: currentUser.id, portalToken: token }, });
Your server then reads their choices as ext:<your user id>. The token lives 30 to 900 seconds (default 900), so mint a fresh one for each page load. Once the SDK has linked the browser to the user, it sends later choices without the token.
Without a token, a publishable key naming an externalId gets 403 portal_token_required. An expired token, or one minted for another user or property, gets 403 portal_token_invalid. The SDK omits externalId when no token is given, so a mistake here leaves the visitor anonymous rather than failing.
Choices the visitor made before signing in are carried over. On load, an SDK started with a principal links this browser's anonymous id to the user, so your server reads those earlier choices under ext:<your user id> too. Nothing is consented again: the link changes who the existing records belong to, and the time of the link is kept as evidence (externalLinkedAt, shown on the principal in the console).
A page that learns who the user is only after it has loaded calls identify() instead, with the same token:
// A page that learns who the user is after it has loaded (a sign-in form, an SPA). const { token } = await fetch('/api/cleardp-token').then((r) => r.json()); ClearDP.ready(async () => { try { const { outcome } = await ClearDP.identify({ externalId: currentUser.id, portalToken: token }); // 'LINKED' choices made before sign-in now belong to this user // 'ALREADY_LINKED' they already did // 'NOTHING_TO_LINK' this browser had not chosen anything yet } catch (err) { // Not linked: err.result.status is the HTTP status (0 for a network failure), // for example 409 principal-conflict (see below). console.warn('not linked', err.result?.status, err.result?.body); } });
Withdrawal on your site
Withdrawing must be as easy as agreeing (DPDP s.6(4)). Once a visitor has chosen, the banner leaves a small Privacy settings button in the corner of the page that reopens their choices (its label follows the notice language). The property's banner theme places it left (the default) or right, or turns it off (reopenButton). If you turn it off, or want the link in your own footer too, call openPreferences():
<a href="#" onclick="ClearDP.openPreferences(); return false;">Privacy settings</a>
The panel lists each consent purpose with a switch showing the visitor's current choice; saving records what they set. Switching off a purpose they had agreed to is recorded as a withdrawal, so your webhooks receive consent.withdrawn and the erasure.requested that follows; leaving off a purpose that is not currently agreed to, one they never agreed to or one waiting for their review, is a refusal (consent.denied).
For a withdrawal your own control makes on the visitor's behalf, such as an unsubscribe button, call withdraw(). That records a withdrawal and sends consent.withdrawn and erasure.requested:
// For example, an unsubscribe button on your own account page. await ClearDP.withdraw(['marketing_email']);
Signed-in users can also withdraw from the hosted privacy portal; your server sends them there with a link from POST /v1/portal-links.
Waiting for consent
A third-party tag waits for its purpose when you mark it up like this. The banner runs it as soon as the visitor agrees; after a withdrawal it stays off from the next page.
<script type="text/plain" data-cleardp-purpose="analytics" data-src="https://example.com/analytics.js" ></script>
| Attribute | What it does |
|---|---|
type="text/plain" | Keeps the browser from running the tag. Required on the stub. |
data-cleardp-purpose | The purpose key that must be granted before the tag runs. |
data-src | The real script address. Leave it off and the stub's own contents run instead. |
data-cleardp-async | Optional. Loads the script with async. Without it, scripts keep document order. |
data-cleardp-type | Optional. A script type to use instead of text/javascript, for example module. |
Features in your own code read the state and listen for changes:
ClearDP.ready(() => {
const sync = () => {
const analytics = ClearDP.getState()['analytics'];
const allowed = analytics?.status === 'GRANTED' && !analytics.stale;
if (allowed) startAnalytics();
else stopAnalytics();
};
sync(); // a choice made on an earlier visit
ClearDP.on('change', sync); // a choice made, changed or withdrawn now
});For anything decided on your server, such as a marketing send, read the authoritative state with a secret key from GET /v1/principals/ext:<id>/consents rather than trusting what a browser reports.
Children
The SDK never asks a visitor's age: a self-declaration in a browser proves nothing, and DPDP puts the duty on you, who usually know it (a date of birth at sign-up, an account type). Tell the SDK with data-is-child="true", isChild: true, or setChild() once you learn it.
For a child, a purpose with allowedForChildren: false is shown but cannot be switched on, and no guardian can change that. Any other purpose waits until a guardian is verified; guardianVerified on the principal tells the two cases apart. Set data-guardian-url to send a guardian to your own verification page.
Method reference
Every method below is on window.ClearDP. All except init and instance throw if the SDK has not started yet, so call them from ready().
| Method | What it does |
|---|---|
init(options) | Starts the SDK and returns the instance. Not needed with the script tag, which starts itself from its data- attributes. |
ready(callback) | Runs callback once the notice and the visitor's earlier choices are loaded (immediately if they already are). Call the other methods from inside it. |
getState() | The visitor's current consent by purpose key: { status, stale, purposeVersion, grantedAt, expiresAt, updatedAt }. status is GRANTED, DENIED, WITHDRAWN or EXPIRED. Treat stale: true as not granted. |
on('change' | 'error', callback) | Subscribes to an event (below). Returns an unsubscribe function. |
grant(purposeKeys) | Records a GRANT for each consent purpose, as if the visitor switched it on. Returns a promise. |
withdraw(purposeKeys) | Records a WITHDRAW for each purpose. Returns a promise. |
identify({ externalId, portalToken }) | Names the signed-in user and links this browser's earlier anonymous choices to them. Resolves to { outcome, principalId, externalLinkedAt }, outcome being LINKED, ALREADY_LINKED or NOTHING_TO_LINK; rejects with an Error whose result.status is the HTTP status (0 for a network failure) and result.body the problem, for example 409 principal-conflict, after which the SDK stays anonymous, and straight away if externalId or portalToken is missing. |
openPreferences() | Opens the visitor's choices panel, for a link or button of your own. Does nothing in headless mode or before the notice has loaded, so call it from ready() or a click. |
setLanguage(lang) | Switches the banner to another published notice language. Returns a promise that resolves when the new notice has loaded. |
setChild() | Marks the visitor as under 18 from now on, for when you learn it after load (at sign-in). One-way: there is no way to undo it. |
instance() | The running instance, or null before it starts. |
instance().destroy() | Removes the banner and stops its timers. Only on the instance, not on the global; for single-page apps that tear a page down, and for tests. |
Events
change fires with the full state (the same shape as getState()) whenever a choice is made, changed or withdrawn, or the server confirms one. error fires when the API refuses a decision the SDK had queued; decisions that fail on the network are retried, not reported.
ClearDP.on('error', (problem) => { // An RFC 9457 problem the API returned for a queued decision, // e.g. a type ending in 'guardian-verification-required'. console.warn('consent not recorded', problem.type, problem.queueItemId); });
ClearDP is a Data Processor under the DPDP Act. The banner collects and evidences consent; obtaining valid consent remains the Data Fiduciary's obligation.