<img src="img/onetrust-popup.jpg" width="500" />
npm install @segment/analytics-consent-wrapper-onetrust
Ensure that consent is enabled and that you have registered your integration-to-category mappings in Segment, which you can do through the Segment UI.
Note: "categories" are called "groups" in OneTrust.
If you don't see a "Consent Management" option like the one below, please contact support or your Solutions Engineer to have it enabled on your workspace.
!Segment.io consent management UI
- Debugging hints: this library expects the OneTrust Banner SDK to be available in order interact with OneTrust. This library derives the group IDs that are active for the current user from the window.OneTrustActiveGroups object provided by the OneTrust SDK. [Read this for more information [community.cookiepro.com]](https://community.cookiepro.com/s/article/UUID-66bcaaf1-c7ca-5f32-6760-c75a1337c226?language=en_US).
``html
src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
type="text/javascript"
charset="UTF-8"
data-domain-script="0000-0000-000-0000"
>
`
#### ⚠️ Reminder: _you must modify_ analytics.load('....') from the original Segment snippet. See markup comment in example above.
library users1. Ensure that OneTrust Snippet is loaded. See example above.
2. Install the package from npm
`shnpm
npm install @segment/analytics-consent-wrapper-onetrust
3. Initialize alongside analytics
`ts
import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'
import { AnalyticsBrowser } from '@segment/analytics-next'export const analytics = new AnalyticsBrowser()
withOneTrust(analytics).load({ writeKey: ' })
`Settings
$3
- opt-in - (strict, GDPR scenario) -- wait for explicit consent (i.e. alert box to be closed) before loading device mode destinations and initializing Segment. If consent is not given (no mapped categories are consented to), then Segment is not loaded.
- opt-out - Load segment immediately and all destinations, based on default categories. For device mode destinations, any analytics.js-originated events (e.g analytics.track) will be filtered based on consent.
- default/other - opt-out
This wrapper uses the
OneTrust.getDomainData() API to get the consent model for a given geolocation. Default behavior can be overridden by doing:`ts
withOneTrust(analytics, { consentModel: () => 'opt-in' | 'opt-out' })
.load({ writeKey: '' })
`Environments
$3
- We build the following versions of the library
| Format | Description | Path |
|--------|-------------|------|
|
cjs (CommonJS modules) | For npm library users | /dist/cjs/index.js |
| esm (ES6 modules) | For npm library users | /dist/esm/index.js |
| global (window bundle) | This is the least amount of code. When you load this bundle via script tag, it simply exposes window.withOneTrust | /dist/umd/analytics-onetrust.global.js |
| umd (umd bundle) | When a UMD bundle is required | /dist/umd/analytics-onetrust.umd.js |$3
-
cjs/esm - Support modern JS syntax (ES2020). These are our npm library users, so we expect them to transpile this module themselves using something like babel/webpack if they need extra legacy browser support.-
umd/global - Support back to IE11, but do not polyfill . See our docs on supported browsers.In order to get full ie11 support, you are expected to bring your own polyfills. e.g. adding the following to your script tag:
`html
``