Consent Banner v2 (4.94 KB gzipped)
Consent Banner v2 ships a 4.94 KB gzipped loader (12.70 KB total), enforces DPDP s.6(4) equal-choice Accept/Reject prominence, bridges all 7 Google Consent Mode v2 signals, honours Global Privacy Control, and blocks third-party embeds until consent.
What Consent Banner v2 enforces by default
| Capability | Implementation |
|---|---|
| Bundle budget | 4.94 KB gzipped loader; 12.70 KB total with renderer |
| DPDP s.6(4) parity | Equal-weight Accept and Reject controls on layer 1; zero pre-ticked optional toggles; zero scroll lock |
| Google Consent Mode v2 | All 7 signals (ad_storage, analytics_storage, ad_user_data, ad_personalization, functionality_storage, personalization_storage, security_storage) |
| Returning visitors | Synchronous cookie/localStorage restore before tag initialization; expired or older material_version re-prompts cleanly |
| Global Privacy Control | Reads navigator.globalPrivacyControl; respects opt-out signals automatically |
| Iframe blocking | Shadow DOM click-to-load placeholders for YouTube, Google Maps, and Vimeo embeds until visitor opts in |
1. Register site, verify domain and publish config
bash
# 1. Verify domain ownership (DNS TXT or /.well-known/policygrain-verify.txt)
curl -X POST https://api.policygrain.com/v1/sites/site_01.../domains/example.in/verify \
-H "Authorization: Bearer $POLICYGRAIN_API_KEY"
# 2. Publish banner config version 1 to cdn.policygrain.com
# (publish takes a numeric version; read GET /v1/sites/{id}/configs/latest to find the newest n)
curl -X POST https://api.policygrain.com/v1/sites/site_01.../configs/1/publish \
-H "Authorization: Bearer $POLICYGRAIN_API_KEY" \
-H "Idempotency-Key: pub-banner-1"2. Add the script tag and gate optional scripts or iframes
<!-- Place in <head> before analytics or marketing tags -->
<script src="https://cdn.policygrain.com/b/v1/loader.js" data-pg-site="site_01..."></script>
<!-- Gate an optional script by purpose -->
<script type="text/plain" data-pg-purpose="analytics" src="https://analytics.example/script.js"></script>
<!-- Gate a YouTube iframe with Shadow DOM click-to-load -->
<iframe
data-pg-purpose="marketing"
data-pg-src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
title="Product overview video"
></iframe>3. Withdrawal control (DPDP s.6(4))
Visitors must be able to withdraw consent as easily as they gave it. Enable the built-in floating preference button in your banner config or give your own footer link a data-pg-open attribute (or call window.PolicyGrain?.open() from it). After a choice, open() shows the withdraw view.