function loadScript(url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { // IE script.onreadystatechange = function() { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { // Others script.onload = function() { callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); } var RID = document.referrer.replace(/\//g, '~'); var WID = window.location.href.replace(/\//g, '~'); var GID = 'LFSITE-20251024-1'; var SID = '9a7c47df-edfd-408c-a9a9-c732797aded5'; var CID = getCustomerID(); var CEM = getCustomerEM(); // --- NEW: capture gclid on first visit and store for the session --- try { var _urlParams = new URLSearchParams(window.location.search); var _gclid = _urlParams.get('gclid'); if (_gclid) { sessionStorage.setItem('klaviyo_gclid', _gclid); } } catch (e) { console.log("Error capturing GCLID:", e); } // --- NEW: extract GA client id from _ga cookie safely --- function extractGAClientId(gaCookie) { try { var parts = gaCookie.split('.'); if (parts.length >= 2) { // If it starts with GAx.x., client id is last two segments if (gaCookie.indexOf('GA') === 0 && parts.length >= 4) { return parts.slice(-2).join('.'); } // Otherwise assume it already is client id return parts.slice(-2).join('.'); } } catch(e){} return ''; } // --- NEW: Tracking variables you asked to add --- var GA_CLIENT_ID = (function(){ var ga = getCookie('_ga'); return ga ? extractGAClientId(ga) : ''; })(); var FB_FBP = getCookie('_fbp') || ''; var FB_FBC = getCookie('_fbc') || ''; var GOOGLE_GCLID = sessionStorage.getItem('klaviyo_gclid') || ''; console.log('RID: ' + window.SHOPIFY_CUSTOMER_ID); console.log('WID: ' + window.SHOPIFY_CUSTOMER_EMAIL); console.log('GID:', GID); console.log('SID:', SID); console.log('CID (Shopify Customer ID):', CID); console.log('CEM (Shopify Customer Email):', CEM); // --- NEW: log the added tracking vars --- console.log('GA_CLIENT_ID:', GA_CLIENT_ID); console.log('FB_FBP:', FB_FBP); console.log('FB_FBC:', FB_FBC); console.log('GOOGLE_GCLID:', GOOGLE_GCLID); function getCustomerID() { return window.SHOPIFY_CUSTOMER_ID || '' } function getCustomerEM() { return window.SHOPIFY_CUSTOMER_EMAIL || '' } if (getCookie('GUID') !== null) { SID = getCookie('GUID'); } else { setCookie("GUID", SID, 1); } var loc = 'https://shopify.weboss.it/analytics.js/analytics/?GID=' + GID + '&SID=' + SID + '&WID=' + WID + '&RID=' + RID + '&CID=' + CID + '&CEM=' + CEM + '&GA_CLIENT_ID=' + GA_CLIENT_ID + '&FB_FBP=' + FB_FBP + '&FB_FBC=' + FB_FBC + '&GOOGLE_GCLID=' + GOOGLE_GCLID; loadScript(loc, function() { }); function SetLeadEmail(email) { if ((email && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) || (CID && CID !== '')) { var loc = 'https://shopify.weboss.it/analytics.js/analytics/?GID=' + GID + '&SID=' + SID + '&WID=' + WID + '&RID=' + RID + '&CID=' + CID + '&CEM=' + email + '&GA_CLIENT_ID=' + GA_CLIENT_ID + '&FB_FBP=' + FB_FBP + '&FB_FBC=' + FB_FBC + '&GOOGLE_GCLID=' + GOOGLE_GCLID; loadScript(loc, function() { }); } } function getCookie(name) { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i].trim(); if (cookie.indexOf(name + '=') == 0) { return cookie.substring(name.length + 1, cookie.length); } } return null; } function setCookie(name, value, daysToExpire) { var expires = ""; if (daysToExpire) { var date = new Date(); date.setTime(date.getTime() + (daysToExpire * 1 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/"; }