A personal community project under @kyletaylored, MIT licensed.Not provided or supported by Datadog.
OneTrust
Holds Datadog RUM until the visitor accepts OneTrust's analytics category, then reports the accepted categories as session context.
Install
import { datadogRum } from '@datadog/browser-rum'
import { oneTrustPlugin } from '@kyletaylored/datadog-rum-plugin-onetrust'
datadogRum.init({
applicationId, clientToken, site, service, env, version,
plugins: [oneTrustPlugin()],
})<script src="https://www.datadoghq-browser-agent.com/<site>/v6/datadog-rum.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@kyletaylored/[email protected]/dist/plugin.js"
integrity="sha384-REPLACE_WITH_THE_HASH_FROM_THE_RELEASE" crossorigin="anonymous"></script>
<script>
DD_RUM.init({ /* ... */, plugins: [DD_RUM_PLUGINS['onetrust']()] })
</script>The CDN URL is pinned to an exact version and needs the integrity hash from that release; there is no auto-updating latest URL. Platform path: Google Tag Manager Custom HTML tag.
Events this plugin sends
None. A consent adapter emits no custom actions of its own: it holds RUM until the visitor accepts, then reports the accepted categories as session context.
Session context it sets
| Property | Example value |
|---|---|
consent.categories | ["C0001","C0002"] |
What it touches
| Platform globals read | window.OnetrustActiveGroups, window.Optanon, window.OptanonWrapper |
|---|---|
| Platform events subscribed | OneTrustGroupsUpdated, Optanon.OnConsentChanged, OptanonWrapper, pagehide |
| Storage keys written | none |
| RUM APIs called | setTrackingConsent, setGlobalContextProperty |
| Consent source | OneTrust OnetrustActiveGroups |
Declared by the plugin and checked against its fixture run: the conformance suite fails if the adapter calls a RUM API this list does not mention. Also printed to the console in debug mode.
Options
| Option | Default | Effect |
|---|---|---|
category | "C0002" | OneTrust category that must be active before RUM may collect. Accepts an array for sites that require several. |
reportCategories | true | Send the accepted categories as the consent.categories global context property. |
timeoutMs | 10000 | How long to wait for the banner script before warning. RUM stays held either way. |
debug | false | Log consent transitions to the console. |
Compatibility and maintainer
| RUM SDK | @datadog/browser-rum@>=7.0.0 <8.0.0 |
|---|---|
| Schema | 1.0.0 · reference |
| Platforms | OneTrust Cookie Consent Any site running the OneTrust banner script (otSDKStub.js). |
| Maintainer | Kyle Taylor (@kyletaylored) |
| Source | packages/plugin-onetrust |
Verify the install
- Pass
debug: trueand reload. Every mapped event prints to the console, along with the plugin's declared footprint.plugins: [oneTrustPlugin({ debug: true })] - Query the RUM Explorer for the first action. It should appear within a minute of the first matching interaction on the site.
@type:session @context.consent.categories:* - Reconcile against the platform's own report before trusting the numbers. These are browser-measured and will undercount; the accuracy bar is within 5% of the platform admin over 7 days.