# adconsent JavaScript SDK
This guide covers embedding adconsent (`/cmp/v1/cmp.js`), blocking scripts and iframes until consent, Google Consent Mode v2, the IAB interfaces `__tcfapi` / `__gpp`, and the JavaScript API `window.cmp`.
## Installation (snippet)
**The snippet must be the first thing in `<head>`.** Tags that appear in the HTML before the CMP are loaded immediately by the browser and can no longer be blocked automatically.
```html
<script src="https://YOUR-CMP-DOMAIN/cmp/v1/stub.js"></script>
<script>
window.cmp = window.cmp || { q: [] };
window.__CMP_BASE__ = {
apiBase: "https://YOUR-CMP-DOMAIN",
propertyKey: "PROPERTY_PUBLIC_KEY"
};
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag("consent", "default", {
ad_storage: "denied", ad_user_data: "denied", ad_personalization: "denied",
analytics_storage: "denied", functionality_storage: "denied",
personalization_storage: "denied", security_storage: "granted",
wait_for_update: 500
});
</script>
<script src="https://YOUR-CMP-DOMAIN/cmp/v1/cmp.js" async></script>
```
Calls made before `cmp.js` has loaded are queued in `cmp.q`, for example `cmp.q.push(["show"])`.
The visitor country is resolved on the server. To test another country: `window.__CMP_BASE__.country = "US"` (tests only).
## Manual blocking
```html
<script type="text/plain" data-cmp-vendor="755" src="https://example.com/tag.js"></script>
<iframe data-cmp-src="https://www.youtube.com/embed/…" data-cmp-custom="youtube"></iframe>
```
- `data-cmp-vendor`: IAB vendor id from the Global Vendor List.
- `data-cmp-custom`: key of a custom vendor from the admin.
- `data-cmp-purposes`: IAB purpose ids; all of them must be consented.
## API (`window.cmp`)
| Method | Description |
| --- | --- |
| `consentAll()` | Accept all purposes and vendors |
| `declineAll()` | Decline all / opt out |
| `show()` / `open()` | Open the banner or settings again |
| `getConsent()` | Current state |
| `hasConsent(vendorIdOrCustomKey)` | `cmp.hasConsent(755)` or `cmp.hasConsent("hotjar")` |
| `on(event, cb)` / `off(event, cb)` | Events: `ready`, `consent`, `shown`, `hidden` |
| `setLanguage(lang)` | Switch language (for example `"fr"`) |
| `console()` / `console(false)` | Open / close the debug console |
Re-open control required by the TCF policy: put a link on every page, for example `<a href="#" data-adconsent-open>Cookie settings</a>`.
## Debug console (cmpconsole)
Open a page with `?cmpconsole` or `#cmpconsole`, or call `cmp.console()`. Close with ✕, `cmp.console(false)` or `?cmpconsole=0`.
Full guide: /docs/cmpconsole
## `__tcfapi` / `__gpp`
- EU/EEA, UK and Switzerland: `__tcfapi` according to the IAB TCF v2.3 CMP API. The synchronous stub provides `__tcfapi` and `iframe[name=__tcfapiLocator]` immediately.
- Test environment: until registration with IAB Europe, adconsent uses the test CMP ID `999`. It is not yet a CMP registered with IAB Europe.
- USA (`gpp_us`): `__gpp` with the US national section (opt-out). A set Global Privacy Control is treated as an opt-out.
## Google Consent Mode v2
Default `denied` (with `wait_for_update`) in the snippet. After the decision adconsent sends `gtag('consent','update',…)` according to the property mapping.
## Regimes
| Regime | Countries | Model |
| --- | --- | --- |
| `tcf_eu` | EU/EEA | Opt-in (IAB TCF) |
| `tcf_uk` | United Kingdom | Opt-in (IAB TCF) |
| `ch` | Switzerland | Opt-in (IAB TCF) |
| `gpp_us` | United States | Opt-out (GPP) |
| `notice_only` / `none` | other countries | configurable per property |
## Cookie declaration
Public cookie list: `https://YOUR-CMP-DOMAIN/c/PROPERTY_KEY/cookie-declaration`
## Troubleshooting
1. No banner → is a configuration published? Does `config.json` return 200? The debug console (`?cmpconsole`) shows errors in the log.
2. Scripts run before consent → is the snippet first in `<head>`?
3. Queue does not run → is `window.cmp = window.cmp || { q: [] }` before `cmp.js`?
4. Google Consent Mode stays `denied` → are `gtag` / `dataLayer` defined before the CMP?
5. Test another country → property demo page with `?country=US`.
SDK documentation
More guides: Debug console (cmpconsole)