/////////////////////////////////////////////////////////////////////////// ////////////////////////source/medium tracking///////////////////////////// /////////////////////////////////////////////////////////////////////////// ////function for getting utm parameters function getTrackingParameters() { const queryParams = new URLSearchParams(window.location.search); return { utmMedium: queryParams.get('utm_medium') || null, utmSource: queryParams.get('utm_source') || null, utmCampaign: queryParams.get('utm_campaign') || 'unknown', fbclid: queryParams.get('fbclid') || null, gclid: queryParams.get('gclid') || null, msclkid: queryParams.get('msclkid') || null, }; } // Function for getting source and medium function getSourceAndMedium() { const params = getTrackingParameters(); // Set defaults let medium = 'direct'; let source = 'unknown'; // First priority to UTM parameters if (params.utmMedium || params.utmSource) { medium = params.utmMedium; source = params.utmSource; } // Next priority to PPC detection via gclid, fbclid, msclkid if (params.gclid) { medium = 'ppc'; source = 'google'; } else if (params.fbclid) { medium = 'ppc'; source = 'facebook'; } else if (params.msclkid) { medium = 'ppc'; source = 'bing'; } else { // If none of the above, then we check for referral const referrer = document.referrer; if (referrer) { const currentUrl = new URL(window.location.href); const referrerUrl = new URL(referrer); // If the referrer is not the current website, set to referral if (currentUrl.hostname !== referrerUrl.hostname) { medium = 'referral'; source = referrerUrl.hostname; } } } return { source, medium }; } ////function for creating iframe parameter function createIframeTrackingParam() { const { source, medium } = getSourceAndMedium(); const { utmCampaign, gclid, fbclid, msclkid } = getTrackingParameters(); const campaign = utmCampaign || 'unknown'; // const fullUrl = window.location.href; // Get the current URL const params = new URLSearchParams({ source, medium, campaign }); // Encode the full URL and add it to the parameters // params.set('fullurl', encodeURIComponent(fullUrl)); // Add the encoded URL to the parameters // Consolidate gclid, fbclid, msclkid into utm_clid const clid = gclid || fbclid || msclkid; if (clid) { params.set('utm_clid', clid); } // Construct the query parameters string queryParamsString = '?' + params.toString(); } queryParamsString = ''; // Call this function to start collection of parameters createIframeTrackingParam(); /////////////////////////////////////////////////////////////////////////// ////////////////////////custom session management////////////////////////// /////////////////////////////////////////////////////////////////////////// ////function for generating unique session function generateUniqueSessionID() { var timestamp = new Date().getTime(); // Current time in milliseconds var randomNum = Math.random().toString(36).substring(2, 15); // A random string return timestamp + '' + randomNum; } ////function for getting cookie function getCookie(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } ////function for setting cookie function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } var session = getCookie('chatbotsession'); if (!session) { // If session doesn't exist, create a new one session = generateUniqueSessionID(); setCookie('chatbotsession', session, 1); // Setting cookie for 1 day } /////////////////////////////////////////////////////////////////////////// ////////////////////////do the thing now/////////////////////////////////// /////////////////////////////////////////////////////////////////////////// ///create the script for iframe resizer var script = document.createElement('script'); script.onload = function () { iFrameResize({ log: false, heightCalculationMethod: 'bodyOffset', checkOrigin:false }, '#ssQuoteFormBotWidget12'); ////run resize once for height validation checksizeandhideiftoolarge(); ////then bind it to resize window.addEventListener('resize', checksizeandhideiftoolarge); }; script.src = 'https://demo.thequotebot.com/code/scripts/iframeresizer/iframeResizerBot.min.js'; document.head.appendChild(script); ////create the iframe var containerbox = document.getElementById('ssiframecontainerbot'); var appendatend = false; if (typeof(containerbox) == 'undefined' || containerbox == null){ ///create container if not already defined var containerbox = document.createElement('div'); containerbox.setAttribute('id', 'ssiframecontainerbot'); appendatend = true; } containerbox.innerHTML = ''; if(appendatend){ document.getElementsByTagName('body')[0].appendChild(containerbox); } ////function for height checks var iframeElementBox = document.getElementById("ssQuoteFormBotWidget12"); var ssQuoteFormBotWidgetheight = iframeElementBox.offsetWidth function checksizeandhideiftoolarge(){ if (window.innerHeight < ssQuoteFormBotWidgetheight) { iframeElementBox.style.display = "none"; } else { iframeElementBox.style.display = "block"; iframeElementBox.iFrameResizer.resize(); } } ///start listening for messages from iframe window.addEventListener('message', function (event) { if(event.data.redirect != null && event.data.redirect.length > 5){ event.data.redirect = event.data.redirect.replace("%%currenturl%%", window.location.href.split(/[?#]/)[0]); window.location.replace(event.data.redirect); } });