diff --git a/qdrant-landing/themes/qdrant-2024/assets/js/helpers.js b/qdrant-landing/themes/qdrant-2024/assets/js/helpers.js index f2a15433c..183dd010f 100644 --- a/qdrant-landing/themes/qdrant-2024/assets/js/helpers.js +++ b/qdrant-landing/themes/qdrant-2024/assets/js/helpers.js @@ -110,22 +110,27 @@ export function addGA4Properties(properties) { export function persistUTMParams() { 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 ampersand = false; - for (const key in utmParams) { - if (utmParams[key]) { - ampersand = filteredParams.length; - filteredParams += `${ampersand ? '&' : ''}${key}=${utmParams[key]}`; + for (const key in urlUtmParams) { + if (urlUtmParams[key]) { + ampersand = filteredParams.length > 0; + filteredParams += `${ampersand ? '&' : ''}${key}=${urlUtmParams[key]}`; } } - const oneYearInSeconds = 365 * 24 * 60 * 60; - document.cookie = `${UTM_PARAMS_KEY}=${filteredParams}; path=/; max-age=${oneYearInSeconds}`; + if (filteredParams) { + sessionStorage.setItem(UTM_PARAMS_KEY, filteredParams); + } +} + +export function getStoredUTMParams() { + return sessionStorage.getItem(UTM_PARAMS_KEY); } export function getUTMParams() { @@ -148,15 +153,17 @@ export function getUTMParams() { } export function addUTMToLinks() { - const utmParams = getCookie(UTM_PARAMS_KEY); + const utmParams = getStoredUTMParams(); - // Add url params to outbound links to product site if (utmParams) { - const links = document.querySelectorAll('a[href*="cloud.qdrant.io"]'); + const links = document.querySelectorAll('a[href*="cloud.qdrant.io"]'); + links.forEach(link => { const href = link.href; 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`; + } }); } -} +} \ No newline at end of file diff --git a/qdrant-landing/themes/qdrant-2024/assets/js/index.js b/qdrant-landing/themes/qdrant-2024/assets/js/index.js index b2da1238b..c908c8748 100644 --- a/qdrant-landing/themes/qdrant-2024/assets/js/index.js +++ b/qdrant-landing/themes/qdrant-2024/assets/js/index.js @@ -1,6 +1,10 @@ import scrollHandler from './scroll-handler'; import { XXL_BREAKPOINT } from './constants'; -import { initGoToTopButton, persistUTMParams } from './helpers'; +import { + addUTMToLinks, + initGoToTopButton, + persistUTMParams +} from './helpers'; import { handleSegmentReady } from './segment-helpers'; import { registerAndCall } from './onetrust-helpers'; import TableOfContents from './table-of-content'; @@ -9,6 +13,8 @@ persistUTMParams(); // on document ready document.addEventListener('DOMContentLoaded', function () { + addUTMToLinks(); + const handleOneTrustLoaded = () => { // One Trust Loaded window.OneTrust.OnConsentChanged(async () => { // One Trust Preference Updated registerAndCall(); diff --git a/qdrant-landing/themes/qdrant-2024/assets/js/onetrust-helpers.js b/qdrant-landing/themes/qdrant-2024/assets/js/onetrust-helpers.js index 19b7d82d1..54114e5ee 100644 --- a/qdrant-landing/themes/qdrant-2024/assets/js/onetrust-helpers.js +++ b/qdrant-landing/themes/qdrant-2024/assets/js/onetrust-helpers.js @@ -32,4 +32,15 @@ export function registerAndCall() { .catch(() => false); return true; - } // registerAndCall \ No newline at end of file + } // 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'); +} \ No newline at end of file diff --git a/qdrant-landing/themes/qdrant-2024/assets/js/segment-helpers.js b/qdrant-landing/themes/qdrant-2024/assets/js/segment-helpers.js index 23c09f858..e5ea8a50b 100644 --- a/qdrant-landing/themes/qdrant-2024/assets/js/segment-helpers.js +++ b/qdrant-landing/themes/qdrant-2024/assets/js/segment-helpers.js @@ -1,5 +1,5 @@ -import { addGA4Properties, addUTMToLinks, getCookie, getUTMParams, tagCloudUILinksWithAnonymousId } from './helpers'; -import { registerAndCall } from './onetrust-helpers'; +import { addGA4Properties, getCookie, getUTMParams, tagCloudUILinksWithAnonymousId } from './helpers'; +import { registerAndCall, setOneTrustDataSubjectId } from './onetrust-helpers'; const PAGES_SESSION_STORAGE_KEY = 'segmentPages'; const INTERACTIONS_SESSION_STORAGE_KEY = 'segmentInteractions'; @@ -161,9 +161,9 @@ function cleanSegmentUtmKeys(obj) { /* Handle Segment Ready */ /************************/ export function handleSegmentReady() { - addUTMToLinks(); - analytics.ready(() => { + setOneTrustDataSubjectId(); + const utmParams = getUTMParams() const cleanUtmParams = cleanSegmentUtmKeys(utmParams);