mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-03 09:58:30 +02:00
* leverage OneTrust's setDataSubjectId() method, leverage SessionStorage for utm params (not cookies) * update setDataSubjectId formatting: https://developer.onetrust.com/onetrust/docs/javascript-api#set-data-subject-id
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
export function registerAndCall() {
|
|
const consentPreferences = window.OnetrustActiveGroups ?? '';
|
|
|
|
// Register OneTrust Integration plugin
|
|
window.analytics
|
|
.register({
|
|
name: 'OneTrust Integration Cookie',
|
|
version: '0.1.0',
|
|
type: 'enrichment',
|
|
isLoaded: () => true,
|
|
load: () => Promise.resolve(),
|
|
// context object and reference to the analytics.js instance
|
|
page: (ctx) => {
|
|
if (ctx.event.context) {
|
|
ctx.updateEvent('context.consent', { onetrust: consentPreferences });
|
|
}
|
|
return ctx;
|
|
},
|
|
track: (ctx) => {
|
|
if (ctx.event.context) {
|
|
ctx.updateEvent('context.consent', { onetrust: consentPreferences });
|
|
}
|
|
return ctx;
|
|
},
|
|
identify: (ctx) => {
|
|
if (ctx.event.context) {
|
|
ctx.updateEvent('context.consent', { onetrust: consentPreferences });
|
|
}
|
|
return ctx;
|
|
},
|
|
})
|
|
.catch(() => false);
|
|
|
|
return true;
|
|
} // registerAndCall
|
|
|
|
export function setOneTrustDataSubjectId() {
|
|
const analytics = window.analytics;
|
|
const activeGroups = window.OnetrustActiveGroups;
|
|
if (!analytics || !activeGroups) return;
|
|
|
|
const anonymousId = analytics.user?.()?.anonymousId?.();
|
|
if (!anonymousId) return;
|
|
|
|
window.OneTrust.setDataSubjectId(anonymousId, true, 'AnonymousID');
|
|
} |