Files
landing_page/qdrant-landing/themes/qdrant-2024/assets/js/onetrust-helpers.js
T
jasonbryant84 1fb5cb4e32 Add Onetrust consent preferences to url params (#1939)
* adding onetrust consent preferences to outbout links to cloud.io

* ot_consent => qdrant_tech_ot_consent
2025-10-06 14:31:10 +01:00

68 lines
1.9 KiB
JavaScript

const CONSENT_PARAM_KEY = 'qdrant_tech_ot_consent';
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');
}
export function addOneTrustPreferencesToLinks() {
const activeGroups = window.OnetrustActiveGroups;
if (!activeGroups || typeof activeGroups !== 'string') return;
const links = document.querySelectorAll('a[href*="cloud.qdrant.io"]');
links.forEach(link => {
let url = new URL(link.href);
if (url.searchParams.has(CONSENT_PARAM_KEY)) {
url.searchParams.delete(CONSENT_PARAM_KEY);
}
url.searchParams.set(CONSENT_PARAM_KEY, activeGroups);
link.href = url.toString();
});
}