mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-03 09:58:30 +02:00
OneTrust setDataSubjectID (#1937)
* 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
This commit is contained in:
@@ -110,22 +110,27 @@ export function addGA4Properties(properties) {
|
|||||||
export function persistUTMParams() {
|
export function persistUTMParams() {
|
||||||
if (!window.location.search) return;
|
if (!window.location.search) return;
|
||||||
|
|
||||||
const utmParams = getUTMParams();
|
const urlUtmParams = getUTMParams();
|
||||||
|
|
||||||
if (!Object.keys(utmParams).length) return;
|
if (!Object.keys(urlUtmParams).some(key => urlUtmParams[key])) return;
|
||||||
|
|
||||||
let filteredParams = '';
|
let filteredParams = '';
|
||||||
let ampersand = false;
|
let ampersand = false;
|
||||||
|
|
||||||
for (const key in utmParams) {
|
for (const key in urlUtmParams) {
|
||||||
if (utmParams[key]) {
|
if (urlUtmParams[key]) {
|
||||||
ampersand = filteredParams.length;
|
ampersand = filteredParams.length > 0;
|
||||||
filteredParams += `${ampersand ? '&' : ''}${key}=${utmParams[key]}`;
|
filteredParams += `${ampersand ? '&' : ''}${key}=${urlUtmParams[key]}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const oneYearInSeconds = 365 * 24 * 60 * 60;
|
if (filteredParams) {
|
||||||
document.cookie = `${UTM_PARAMS_KEY}=${filteredParams}; path=/; max-age=${oneYearInSeconds}`;
|
sessionStorage.setItem(UTM_PARAMS_KEY, filteredParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStoredUTMParams() {
|
||||||
|
return sessionStorage.getItem(UTM_PARAMS_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUTMParams() {
|
export function getUTMParams() {
|
||||||
@@ -148,15 +153,17 @@ export function getUTMParams() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function addUTMToLinks() {
|
export function addUTMToLinks() {
|
||||||
const utmParams = getCookie(UTM_PARAMS_KEY);
|
const utmParams = getStoredUTMParams();
|
||||||
|
|
||||||
// Add url params to outbound links to product site
|
|
||||||
if (utmParams) {
|
if (utmParams) {
|
||||||
const links = document.querySelectorAll('a[href*="cloud.qdrant.io"]');
|
const links = document.querySelectorAll('a[href*="cloud.qdrant.io"]');
|
||||||
|
|
||||||
links.forEach(link => {
|
links.forEach(link => {
|
||||||
const href = link.href;
|
const href = link.href;
|
||||||
const separator = href.indexOf('?') === -1 ? '?' : '&';
|
const separator = href.indexOf('?') === -1 ? '?' : '&';
|
||||||
link.href = `${href}${separator}${utmParams}&qdrant_ref=qdrant_tech`;
|
if (!href.includes(UTM_PARAMS_KEY)) {
|
||||||
|
link.href = `${href}${separator}${utmParams}&qdrant_ref=qdrant_tech`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
import scrollHandler from './scroll-handler';
|
import scrollHandler from './scroll-handler';
|
||||||
import { XXL_BREAKPOINT } from './constants';
|
import { XXL_BREAKPOINT } from './constants';
|
||||||
import { initGoToTopButton, persistUTMParams } from './helpers';
|
import {
|
||||||
|
addUTMToLinks,
|
||||||
|
initGoToTopButton,
|
||||||
|
persistUTMParams
|
||||||
|
} from './helpers';
|
||||||
import { handleSegmentReady } from './segment-helpers';
|
import { handleSegmentReady } from './segment-helpers';
|
||||||
import { registerAndCall } from './onetrust-helpers';
|
import { registerAndCall } from './onetrust-helpers';
|
||||||
import TableOfContents from './table-of-content';
|
import TableOfContents from './table-of-content';
|
||||||
@@ -9,6 +13,8 @@ persistUTMParams();
|
|||||||
|
|
||||||
// on document ready
|
// on document ready
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
addUTMToLinks();
|
||||||
|
|
||||||
const handleOneTrustLoaded = () => { // One Trust Loaded
|
const handleOneTrustLoaded = () => { // One Trust Loaded
|
||||||
window.OneTrust.OnConsentChanged(async () => { // One Trust Preference Updated
|
window.OneTrust.OnConsentChanged(async () => { // One Trust Preference Updated
|
||||||
registerAndCall();
|
registerAndCall();
|
||||||
|
|||||||
@@ -33,3 +33,14 @@ export function registerAndCall() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // registerAndCall
|
} // 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');
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { addGA4Properties, addUTMToLinks, getCookie, getUTMParams, tagCloudUILinksWithAnonymousId } from './helpers';
|
import { addGA4Properties, getCookie, getUTMParams, tagCloudUILinksWithAnonymousId } from './helpers';
|
||||||
import { registerAndCall } from './onetrust-helpers';
|
import { registerAndCall, setOneTrustDataSubjectId } from './onetrust-helpers';
|
||||||
|
|
||||||
const PAGES_SESSION_STORAGE_KEY = 'segmentPages';
|
const PAGES_SESSION_STORAGE_KEY = 'segmentPages';
|
||||||
const INTERACTIONS_SESSION_STORAGE_KEY = 'segmentInteractions';
|
const INTERACTIONS_SESSION_STORAGE_KEY = 'segmentInteractions';
|
||||||
@@ -161,9 +161,9 @@ function cleanSegmentUtmKeys(obj) {
|
|||||||
/* Handle Segment Ready */
|
/* Handle Segment Ready */
|
||||||
/************************/
|
/************************/
|
||||||
export function handleSegmentReady() {
|
export function handleSegmentReady() {
|
||||||
addUTMToLinks();
|
|
||||||
|
|
||||||
analytics.ready(() => {
|
analytics.ready(() => {
|
||||||
|
setOneTrustDataSubjectId();
|
||||||
|
|
||||||
const utmParams = getUTMParams()
|
const utmParams = getUTMParams()
|
||||||
const cleanUtmParams = cleanSegmentUtmKeys(utmParams);
|
const cleanUtmParams = cleanSegmentUtmKeys(utmParams);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user