// =========== PRODUZIONE // Funzione per ottenere il valore di un parametro URL specifico function getParamValue (paramName) { const url = window.location.href const regex = new RegExp('[?&]' + paramName + '(=([^&#]*)|&|#|$)') const results = regex.exec(url) if (!results) return null if (!results[2]) return '' return decodeURIComponent(results[2].replace(/\+/g, ' ')) } // Funzione per salvare i dati nel sessionStorage function saveToSessionStorage (key, value) { if (typeof (Storage) !== 'undefined') { sessionStorage.setItem(key, value) } else { console.warn('Il tuo browser non supporta Web Storage...') } } // Lista di parametri GET da catturare const getutmLinkParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'cta', 'event', 'prev_site', 'datainvio', 'IDmessage'] // Loop sui parametri e salva i valori nel sessionStorage for (let i = 0; i < getutmLinkParams.length; i++) { const paramValue = getParamValue(getutmLinkParams[i]) if (paramValue) { saveToSessionStorage(getutmLinkParams[i], paramValue) } } function getReferrer () { if (document.referrer !== '') { const referrerUrl = new URL(document.referrer) const secondPart = referrerUrl.pathname return secondPart } } // Salva l'ultima pagina vista (referrer) come "utm_content" const referrer = getReferrer() if (referrer) { saveToSessionStorage('utm_content', encodeURIComponent(referrer)) } // Salva InteractionId di Sitecore // var interactionId = window.yourGlobalVariable // Sostituisco con la mia variabile globale // if (interactionId) { // saveToSessionStorage('InteractionId', interactionId) // }