window.ExpressConsent

The script attaches a single global. Everything the SDK offers hangs off it.

Loading the script

html
<script
  src="https://sdk.expressconsent.com/sdk/v1/sdk.js"
  data-ec-cid="YOUR_CID"
  async
></script>

async is correct here: nothing is needed until a person submits a form. Keep async (or defer); the loader relies on it to retry with a compatible bundle if the first one cannot run.

The script has to run in the same document as the form it captures. It reads the page it is loaded into and nothing else, so a form inside an iframe needs the script inside that iframe.

Error events

Every error the SDK throws is also dispatched on window as an expressconsent:error event, so you can route SDK failures into your own monitoring without wrapping every call site.

javascript
window.addEventListener("expressconsent:error", (event) => {
  reportToMonitoring(event.detail.code, event.detail.message);
});

The detail carries name (always "ExpressConsentError"), code, message, and timestampMs; the page url when it can be read; details with backendCode and backendMessage when the server rejected the upload; and a cause summary when there was an underlying error.

Route details.backendCode into monitoring; it is the reason behind an UPLOAD_FAILED. Codes are listed on SDK errors.