libconsent
Adapters

OneTrust

OneTrust — group ids turned into categories.

bun add @libconsent/onetrust
import { onetrust } from "@libconsent/onetrust";

<ConsentProvider adapter={onetrust({ domainScript: "0000-0000-0000-0000" })}>
  {children}
</ConsentProvider>;

OneTrust reports consent as group ids on a global, and expects a global OptanonWrapper callback. The adapter handles both and exposes the result as categories.

Options

OptionDefault
domainScript—Required. The data-domain-script UUID.
groups—Map group ids onto categories. Merged with the defaults.
src—A different SDK stub — region-specific or self-hosted.
manualfalseThe script is already on the page.

Groups

The standard groups are recognised:

C0001 Strictly Necessary → essential
C0002 Performance        → analytics
C0003 Functional         → functional
C0004 Targeting          → marketing
C0005 Social Media       → marketing

Custom groups need one line:

onetrust({
  domainScript: "0000-0000-0000-0000",
  groups: { C0006: "functional", C0007: "analytics" },
});

Two groups can map to the same category; it is granted when any of them is.

Gating on a specific group

Group ids are reported as services, so you can also target one directly:

<CookieService id="social-embed" name="Social embeds" aliases={["C0005"]}>
  <TwitterEmbed />
</CookieService>

Group names from GetDomainData() are reported too, so an alias of "Social Media Cookies" works as well.

OptanonWrapper

The adapter installs it, calling any existing one first, and restores the previous value when the provider unmounts. Nothing to add to your HTML.

Actions

OneTrust has one dialog, so open() and openSettings() both open the preference centre. reset() and setConsent are not available.

On this page