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'; const PAYLOAD_BOILERPLATE = { url: window.location.href, title: document.title, }; /*******************/ /* General helpers */ /*******************/ const storedPayload = () => { const now = new Date(); return { ...PAYLOAD_BOILERPLATE, storedEvent: true, storedTimestamp: now.toISOString(), } }; const nameMapper = (url) => { // Mapping names based on pathname for Segment return url.includes('/blog/') ? 'Blog' : 'Marketing Site'; }; /***************/ /* DOM helpers */ /***************/ const handleClickInteraction = (event) => { const rawLabel = event.target.getAttribute('data-metric-label') ?? event.target.innerText; const cleanedLabel = rawLabel ? rawLabel.replace(/\s+/g, ' ').trim() : ''; const payload = { ...PAYLOAD_BOILERPLATE, location: event.target.getAttribute('data-metric-loc') ?? '', label: cleanedLabel, action: 'clicked' }; // If consented to tracking the track if(getCookie('cookie-consent')) { trackInteractionEvent(payload); // If element can be clicked more than once (ie user remains on same page) if (!event.target.hasAttribute('data-metric-keep')) { event.target.removeEventListener('click', handleClickInteraction); } } else { // If no consent yet the store in sessionStorage in case of later consent createSegmentStoredInteraction(payload); } }; // Gather all and