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.
If you don't see a "Consent Management" option like the one below, please contact Segment's support or your Segment Solutions Engineer to have it enabled on your workspace.
![Screenshot 2024-09-26 at 10 51 23 AM](https://private-user-images.githubusercontent.com/5453691/371279036-61838cf1-b5e9-45ea-8a04-5c400ad88781.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjY4NjMsIm5iZiI6MTczOTU2NjU2MywicGF0aCI6Ii81NDUzNjkxLzM3MTI3OTAzNi02MTgzOGNmMS1iNWU5LTQ1ZWEtOGEwNC01YzQwMGFkODg3ODEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMjA1NjAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTEwMDNjMDMyMzg1NGY1MWVjNjdkMzg2ODQzYjAzNDJmYjMzOWI2NWYzOTAwYjFiMDNhZWM5YzE3NzI4OGU5MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.cimkzWB0JgRtxueMlBJeDAR-yVigzjAlBwmhEx4P6kw)
- Debugging hints: this library expects the TrustArc CCM script to be available in order to interact with TrustArc. This library derives the category IDs that are active for the current user from the
window.truste
object provided by TrustArc API.
<head>
<!-- TrustArc Cookies Consent script start for CCM Advanced -->
<script async="async" type="text/javascript" crossorigin="" src='//consent.trustarc.com/notice?domain=<instanceid>&c=teconsent&js=nj¬iceType=bb>m=1&'></script>
<!-- TrustArc Cookies Consent script start for CCM Pro -->
<script type="text/javascript" async="async" src="https://consent.trustarc.com/v2/notice/<instanceid>"></script>
<!-- Add Segment's TrustArc Consent Wrapper -->
<script src="https://consent.trustarc.com/get?name=trustarc-segment-wrapper-v1.0.js"></script>
<!--
Add / Modify Segment Analytics Snippet
* Find and replace: analytics.load('<MY_WRITE_KEY>') -> TrustArcWrapper.withTrustArc(analytics).load('<MY_WRITE_KEY'>)
-->
<script>
!function(){var analytics=window.analytics...
....
TrustArcWrapper.withTrustArc(analytics).load('<MY_WRITE_KEY>') // replace analytics.load()
analytics.page()
</script>
</head>
⚠️ Reminder: you must modify analytics.load('....')
from the original Segment snippet. See markup comment in example above.
-
Ensure that TrustArc Snippet is loaded.
-
Install both packages from your preferred package manager
# npm
npm install @trustarc/trustarc-segment-wrapper
npm install @segment/analytics-next
# yarn
yarn add @trustarc/trustarc-segment-wrapper
yarn add @segment/analytics-next
# pnpm
pnpm add @trustarc/trustarc-segment-wrapper
pnpm add @segment/analytics-next
- Initialize alongside analytics
import { withTrustArc } from '@trustarc/trustarc-segment-wrapper'
import { AnalyticsBrowser } from '@segment/analytics-next'
export const analytics = new AnalyticsBrowser()
withTrustArc(analytics).load({ writeKey: '<MY_WRITE_KEY'> })
- Here is an example of how you can load the CCM script with
useEffect
useEffect (() => {
withTrustArc(analytics).load({ writeKey: '<MY_WRITE_KEY'>' })
const taScript = document.createElement("script");
taScript.src = "//consent.trustarc.com/notice?domain=<yourdomain.com>&c=teconsent&js=nj¬iceType=bb>m=1";
document.head.appendChild(taScript);
return () => {
taScript.remove();
}
}, [])
-
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-in experience is the mapped for
EU
orexpressed
values in the notice behavior. See instructions below for more information. -
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 EU | US
values from the notice_behavior cookie dropped for the CCM Advanced and EU | NA | AN | AF | AS | SA | OC
for CCM Pro consent model according to the consent geolocation. Please refer to the TrustArc integration guide for a more comprehensive overview of the available options. The default behavior can also be customized using your own logic:
TrustArcWrapper.withTrustArc(analytics, { consentModel: () => 'opt-in' | 'opt-out' })
.load({ writeKey: '<MY_WRITE_KEY>' })
If you are using implied | expressed
to define the consent experience, you can inform that using the parameter consentModelBasedOnConsentExperience: true,
.
TrustArcWrapper.withTrustArc(analytics, { consentModelBasedOnConsentExperience: true })
.load({ writeKey: '<MY_WRITE_KEY>' })
If you are using Segment as a Required vendor, you can pass an additional parameter for Segment to load even on opt-in locations before there's any consent provided. This will allow Segment to load, while making sure that the visitor's consent choices are still propagated so that the destinations that are not mapped as required will not load.
IMPORTANT: Please always consult with your privacy team before enabling this option;
TrustArcWrapper.withTrustArc(analytics, { alwaysLoadSegment: true })
.load({ writeKey: '<MY_WRITE_KEY>' })
- We build the following versions of the library
Format | Description | Path |
---|---|---|
amd (amd bundle) |
When a AMD bundle is required | trustarc_segment_wrapper.js |
amd
- 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:
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.7.0/polyfill.min.js"></script>