Browser runtime options
Every script-tag attribute, configuration option and markup attribute the browser runtime reads, with its type and default.
The browser runtime takes its options from the script tag, from window.PiedapConsentConfig or from createConsent(). Each option is listed here with its type and default.
Requirements#
- A publishable key,
pk_…. See Keys and where to use them. - For the script tag: a page where the tag can be the first script in
<head>. - For the npm package: Node.js 18 or later to build. The package ships TypeScript types.
Install#
Add the script tag to every page. loader.js always serves the current runtime, version 1.0.7.
<script src="https://console.dpconsent.com/consent/sdk/v1/loader.js"
data-piedap-key="pk_…"></script>An application that bundles its own JavaScript installs the package from your deployment instead.
npm install https://console.dpconsent.com/consent/sdk/v1/packages/piedap-consent-1.0.7.tgzInstall on a website explains where the tag goes. The versioned files and their integrity hashes are in Runtime files.
Load the runtime#
Script tag#
The tag starts the runtime and creates window.PiedapConsent.
- Do not add
async,deferortype="module". - The runtime takes the API address from the script's own address.
- Without a key, or with a key that does not start with
pk_, nothing starts. The console shows why. - A second tag on the same page is ignored.
createConsent()#
Starts the runtime from a bundle and returns its controller.
| Parameter | Type | Required or default | Description |
|---|---|---|---|
options |
ConsentOptions |
Required | The configuration options. apiUrl and publicKey are required. |
options.autoInit |
boolean |
true |
Start at once. With false, call consent.init() yourself. |
Returns a ConsentController with the browser runtime methods.
Errors Throws Error when publicKey or apiUrl is missing, and when publicKey does not start with pk_.
import { createConsent } from '@piedap/consent';
export const consent = createConsent({
apiUrl: 'https://console.dpconsent.com/consent',
publicKey: 'pk_…',
cookieDomain: '.example.in',
});
const state = await consent.ready;
console.log(state.law, consent.hasConsent('analytics'));The package is the same runtime without the global. It differs from the script tag in three ways:
- It does not read options from a script tag or from
window.PiedapConsentConfig. - It starts when your bundle runs, so scripts earlier in the page are not held automatically.
- It does not install the IAB stubs early.
Script tag attributes#
| Attribute | Type | Required or default | Description |
|---|---|---|---|
data-piedap-key |
Publishable key | Required | The key the page calls the API with. |
data-piedap-api |
URL | The address the script was loaded from | The API address. Needed when the script comes from a CDN. |
data-piedap-form |
Form key | Chosen by region rules | Serves one form instead of resolving by region. A form that region rules target is still shown only where those rules match. A key that does not exist shows no banner and allows nothing new. |
data-piedap-locale |
Language tag, such as hi |
The language the visitor last chose, then the browser's, then en |
The language to ask for. |
data-piedap-country |
Two-letter country code | Detected from the request | Uses this country instead of the detected one. |
data-piedap-subdivision |
Region code, such as KA |
Detected from the request | Uses this state or province. |
data-piedap-cookie-domain |
Domain, such as .example.in |
The page's own host | Shares the consent cookies across subdomains. |
data-piedap-auto-show |
Boolean | true |
Shows the banner when a choice is needed. |
data-piedap-auto-block |
Boolean | true |
Holds scripts and frames from known tracker hosts. |
data-piedap-allow-hosts |
Host names separated by spaces or commas | None | Hosts never held by automatic blocking. Subdomains are included. |
data-piedap-google-consent-mode |
true, false or update |
true |
Sends Google Consent Mode signals. update sends updates only and leaves the defaults to a Tag Manager template. |
data-piedap-reopen-button |
Boolean | true |
Shows the floating privacy button after a choice. |
data-piedap-metadata |
JSON object | None | Your own fields, stored with every record this page writes. Up to 6,144 bytes. |
data-piedap-tcf |
Boolean | false |
Installs the IAB __tcfapi stub at once. |
data-piedap-gpp |
Boolean | false |
Installs the IAB __gpp stub at once. |
data-piedap-debug |
Boolean | false |
Asks the API for the full region trace on the /sdk/v1/form response. |
A boolean attribute is off when its value is false, 0 or off. It is on when the value is true, 1, on or empty. Any other value keeps the default.
<script src="https://console.dpconsent.com/consent/sdk/v1/loader.js"
data-piedap-key="pk_…"
data-piedap-cookie-domain=".example.in"
data-piedap-allow-hosts="cdn.example.in, pay.example.in"
data-piedap-metadata='{"storeRegion":"south-india"}'></script>The floating privacy button also follows the form's Privacy button setting. Where a DPDP region rule applies, the button stays unless the page has its own data-piedap-open element.
Configuration options#
Set window.PiedapConsentConfig before the tag, or pass the same options to createConsent().
| Option | Type | Required or default | Description |
|---|---|---|---|
publicKey |
string |
From data-piedap-key |
The publishable key. |
apiUrl |
string |
From data-piedap-api, then the script's address |
The API address. |
formKey |
string |
None | Same as data-piedap-form. |
locale |
string |
Same as data-piedap-locale |
The language to ask for. |
country |
string |
Detected | Same as data-piedap-country. |
subdivision |
string |
Detected | Same as data-piedap-subdivision. |
cookieDomain |
string |
The page's host | Same as data-piedap-cookie-domain. |
autoShow |
boolean |
true |
Shows the banner when a choice is needed. With false, call show() yourself. |
autoBlock |
boolean |
true |
Holds known trackers. |
blockedHosts |
Record<string, PurposeCategory> |
{} |
Extra hosts to hold, each with the category that releases it. |
allowedHosts |
string[] |
[] |
Hosts never held. |
googleConsentMode |
boolean | 'update' |
true |
Sends Google Consent Mode signals. |
reopenButton |
boolean |
true |
Shows the floating privacy button. |
container |
HTMLElement | null |
null |
The element a form with the placement INLINE is drawn in. Your page's styles apply to it. |
subjectId |
string |
A random id kept in local storage | Records under this pseudonymous id. At most 255 characters. |
identity |
{ subjectType, subjectId, proof } |
None | Records under a signed-in person. subjectType is EMAIL, USER_ID or PHONE. proof comes from your server. |
identifiers |
LinkedIdentifier[] |
[] |
Up to five further identifiers the record can be found by. |
metadata |
object |
{} |
Your own fields, stored with every record this page writes. Up to 6,144 bytes of JSON. |
debug |
boolean |
false |
Asks the API for the full region trace. |
fetch |
typeof fetch |
The browser's fetch |
Replaces fetch for the runtime's API calls. Meant for tests. |
<script>
window.PiedapConsentConfig = {
cookieDomain: '.example.in',
blockedHosts: { 'tracker.example.com': 'MARKETING' },
allowedHosts: ['cdn.example.in'],
metadata: { storeRegion: 'south-india' },
};
</script>
<script src="https://console.dpconsent.com/consent/sdk/v1/loader.js"
data-piedap-key="pk_…"></script>The IAB stubs are never installed from this object. Use data-piedap-tcf and data-piedap-gpp, or the script URL. Signed-in visitors explains identity, and Identifiers explains identifiers.
Script URL parameters#
Use these when an installer can load a script but cannot set attributes on it.
| Parameter | Type | Required or default | Description |
|---|---|---|---|
key |
Publishable key | Required without data-piedap-key |
Same as data-piedap-key. |
form |
Form key | None | Same as data-piedap-form. |
locale |
Language tag | None | Same as data-piedap-locale. |
gcm |
true, false or update |
true |
Same as data-piedap-google-consent-mode. |
tcf |
Boolean | false |
Same as data-piedap-tcf. |
gpp |
Boolean | false |
Same as data-piedap-gpp. |
cookieDomain |
Domain | None | Same as data-piedap-cookie-domain. |
<script
src="https://console.dpconsent.com/consent/sdk/v1/loader.js?key=pk_…&locale=hi">
</script>When one option is set in several places, window.PiedapConsentConfig wins, then the data attribute, then the URL.
Markup attributes#
The runtime reads these attributes on other elements of the page.
| Attribute | Element | Value | Description |
|---|---|---|---|
data-consent |
<script type="text/plain"> or <iframe> |
A purpose key, or a category in any case | Holds the tag until the purpose or category is allowed. A purpose key wins when both match. |
data-partner |
The same elements | A partner key of that purpose | Also waits for that partner. data-consent must then be a purpose key. |
data-type |
<script type="text/plain"> |
A script type, such as module |
The type the released script gets. |
data-src |
<iframe> |
The frame's address | Becomes src when the frame is released. |
data-piedap-open |
Any element | None | A click opens the preferences dialog. |
data-piedap-do-not-sell |
Any element | None | A click opens the opt-out dialog. |
data-piedap-cookie-declaration |
Any element | None | Filled with your project's cookie declaration, as tables with the class piedap-cookie-declaration. |
<script type="text/plain" data-consent="analytics" data-partner="matomo"
src="https://matomo.example.in/matomo.js"></script>
<a href="#" data-piedap-open>Privacy settings</a>Hold tags until consent explains when marked tags are checked and released.
Hosts held by default#
With autoBlock on, a script or frame from one of these hosts waits until its category is allowed.
| Category | Hosts |
|---|---|
ANALYTICS |
hotjar.com, hotjar.io, clarity.ms, mixpanel.com, mxpnl.com, amplitude.com, heapanalytics.com, heap-api.com, fullstory.com, segment.com, segment.io, posthog.com, plausible.io, matomo.cloud, omtrdc.net, 2o7.net, nr-data.net, mouseflow.com, luckyorange.com, smartlook.com, logrocket.com, lr-ingest.io, contentsquare.net, quantummetric.com, player.vimeo.com |
MARKETING |
connect.facebook.net, facebook.com, snap.licdn.com, ads.linkedin.com, analytics.tiktok.com, bat.bing.com, pinimg.com, ct.pinterest.com, ads-twitter.com, analytics.twitter.com, sc-static.net, tr.snapchat.com, redditstatic.com, alb.reddit.com, criteo.com, criteo.net, taboola.com, outbrain.com, adsrvr.org, amazon-adsystem.com, quantserve.com, quantcount.com, demdex.net, adnxs.com, rubiconproject.com, pubmatic.com, casalemedia.com, hs-scripts.com, hs-analytics.net, hsadspixel.net, hubspot.com, munchkin.marketo.net, pardot.com, klaviyo.com, chimpstatic.com, youtube.com, youtube-nocookie.com |
PERSONALISATION |
optimizely.com, visualwebsiteoptimizer.com, abtasty.com, dynamicyield.com |
FUNCTIONAL |
intercom.io, intercomcdn.com, zdassets.com, driftt.com, livechatinc.com, crisp.chat, tawk.to |
- A host covers its subdomains. The most specific rule wins.
- The page's own host is never held.
- Payment, fraud-prevention and bot-protection services are not on the list.
- Google's tag hosts are not on the list. They follow Google Consent Mode instead.
- Add hosts with
blockedHosts. Exempt hosts withallowedHostsordata-piedap-allow-hosts.
A category your form does not ask about is never allowed
A host is released when its category is allowed. If the form has no purpose in that category, the host stays held. Add a purpose in the category, or exempt the host with allowedHosts.