libconsent
Adapters

TrustArc

TrustArc — numeric consent levels, read out of two different globals.

npm i @libconsent/trustarc
import { ConsentProvider } from "@libconsent/core";
import { trustarc } from "@libconsent/trustarc";

<ConsentProvider adapter={trustarc({ domain: "example.com" })}>
  {children}
</ConsentProvider>;

TrustArc reports consent as a list of numeric levels, behind either truste.cma.callApi or PrivacyManagerAPI.callApi depending on the notice version, and announces changes with an untyped postMessage. The adapter reads whichever global answers, maps the levels onto categories, and re-reads on both the message and a slow poll.

The notice needs somewhere to render

TrustArc injects into markers you have to provide:

<div id="consent_blackbar"></div>
<div id="teconsent"></div>

Without #teconsent there is no settings link, and openSettings() has nothing to open.

Options

OptionDefault
domain—Required. The domain configured in TrustArc.
noticeType"bb""bb" is the banner bar; also "lightbox", "gdpr".
language—Force a language.
src—A different notice URL — region-specific or self-hosted.
manualfalseThe script is already on the page.
levelssee belowMap consent levels onto categories.
pollInterval2000How often to re-read, in ms. 0 turns it off.

Levels

The default three-tier configuration:

1 Required    → essential
2 Functional  → functional and analytics
3 Advertising → marketing

Analytics rides on level 2 because the standard TrustArc setup files measurement under "Functional" — there is no separate analytics level to map. Four-tier accounts should say what theirs are:

trustarc({
  domain: "example.com",
  levels: { 1: "essential", 2: "functional", 3: "analytics", 4: "marketing" },
});

Why it polls

TrustArc's change signal is a postMessage whose payload has been a bare string, a JSON string and a structured object across notice versions. The adapter matches all three loosely, but a slow poll is what makes it dependable. Two seconds costs nothing measurable; turn it off if you have verified the message arrives in your configuration:

trustarc({ domain: "example.com", pollInterval: 0 });

What it can do

open() and openSettings() both call truste.eu.clickListener(), which opens the preference manager; close() calls prefClose(). TrustArc exposes no way to accept or reject programmatically, so those actions are absent and useConsent().supports says so.

On this page