@ht-sdks/events-sdk-js-consent-tools
v1.0.0
Published
This package provides a generic interface for integrating with a Consent Management Platform (CMP). We currently offer an implementation for [OneTrust](https://www.onetrust.com/) via the [`@ht-sdks/events-sdk-js-consent-wrapper-onetrust`](../consent-wrapp
Downloads
5
Keywords
Readme
@ht-sdks/events-sdk-js-consent-tools
This package provides a generic interface for integrating with a Consent Management Platform (CMP). We currently offer an implementation for OneTrust via the @ht-sdks/events-sdk-js-consent-wrapper-onetrust
package. You can use this library for integrating with other CMPs.
Usage
// wrapper.js
import { createWrapper, resolveWhen } from '@ht-sdks/events-sdk-js-consent-tools'
export const withCMP = createWrapper({
// Wrapper waits to load htevents / get categories until this function resolves
shouldLoad: async (ctx) => {
const CMP = await getCMP()
await resolveWhen(() => !CMP.popUpVisible())
// Optional -- for granular control of initialization
if (noConsentNeeded) {
ctx.abort({ loadHightouchNormally: true })
} else if (allTrackingDisabled) {
ctx.abort({ loadHightouchNormally: false })
}
},
getCategories: async () => {
const CMP = await getCMP()
return normalizeCategories(CMP.consentedCategories()) // Expected format: { foo: true, bar: false }
},
registerOnConsentChanged: async (setCategories) => {
const CMP = await getCMP()
CMP.onConsentChanged((event) => {
setCategories(normalizeCategories(event.detail))
})
},
})
const getCMP = async () => {
await resolveWhen(() => window.CMP != null)
return window.CMP
}
Installation
npm
import { HtEventsBrowser } from '@ht-sdks/events-sdk-js-browser'
import { withCMP } from './cmp-wrapper'
export const htevents = new HtEventsBrowser()
withCMP(htevents).load({ writeKey: 'WRITE_KEY' })
Snippet users (window.htevents)
Note: This assumes a project that can consume the library via es6 imports, using a like Webpack.
- Delete the
htevents.load()
line from the snippet
- htevents.load('WRITE_KEY');
- Import Analytics
import { withCMP } from './cmp-wrapper'
withCMP(window.htevents).load('WRITE_KEY')
Wrapper Implementations
Settings / Options / Configuration
See the complete list of settings in the Settings interface
Development
- Build this package + all dependencies
npx turbo build
- Run tests
npx turbo test