Add Onetrust consent preferences to url params (#1939)

* adding onetrust consent preferences to outbout links to cloud.io

* ot_consent => qdrant_tech_ot_consent
This commit is contained in:
jasonbryant84
2025-10-06 14:31:10 +01:00
committed by GitHub
parent 31ada8c911
commit 1fb5cb4e32
2 changed files with 26 additions and 1 deletions
@@ -6,7 +6,7 @@ import {
persistUTMParams
} from './helpers';
import { handleSegmentReady } from './segment-helpers';
import { registerAndCall } from './onetrust-helpers';
import { addOneTrustPreferencesToLinks, registerAndCall } from './onetrust-helpers';
import TableOfContents from './table-of-content';
persistUTMParams();
@@ -16,7 +16,10 @@ document.addEventListener('DOMContentLoaded', function () {
addUTMToLinks();
const handleOneTrustLoaded = () => { // One Trust Loaded
addOneTrustPreferencesToLinks();
window.OneTrust.OnConsentChanged(async () => { // One Trust Preference Updated
addOneTrustPreferencesToLinks();
registerAndCall();
await window.analytics.track('onetrust_consent_preference_updated', {
@@ -1,3 +1,5 @@
const CONSENT_PARAM_KEY = 'qdrant_tech_ot_consent';
export function registerAndCall() {
const consentPreferences = window.OnetrustActiveGroups ?? '';
@@ -43,4 +45,24 @@ export function setOneTrustDataSubjectId() {
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();
});
}