//Script which calls WidgetContent.ashx to load content based upon URL parameters // Workflow: EmbeddedScript > WidgetJS.ashx > load advanced script (wdg_content.js) > WidgetContent.ashx > WidgetMethods (optional) // done with help from this article by Sam Deering: https://www.sitepoint.com/dynamically-load-jquery-library-javascript/ //const _scriptTag = document.currentScript;//The script that started all of this //document.addEventListener("DOMContentLoaded", function () { LoadjQuery(); });//DOM elements exist //document.addEventListener("load", function () { LoadjQuery(); });//Document elements are ready to be manipulated /*const pixelId = '[PIXELID]';*/ const START_TIME = Date.now(); let _modalOpen = false; let _popupCount = 0; let _popUpMax = 1; let _suppressOpen = false; let _suppressOpenSetting = false; let _lastScrollTop = 0; let _logVerbose = false; DisplayTime('Loading Ratesight Widgets'); /*LoadCapitalAudienceScript();*///Load before document is ready window.addEventListener("load", function () {//Page and images are fully loaded LoadRatesightjQuery(); }); function LoadRatesightjQuery() { if (!window.jQuery) { AddHeadScript('jQuery', 'https://resources.ratesight.com/vendor/jquery/v3.5.1/dist/jquery.min.js', function () { LoadRatesightResizer(); LoadRatesightWidgets(); }); } else { LoadRatesightResizer(); LoadRatesightWidgets(); } } function LoadRatesightBootstrap() { if (!window.bootstrap) { AddHeadScript('Bootstrap', "https://resources.ratesight.com/vendor/bootstrap/v5.3.0/js/bootstrap.bundle.min.js", function () { }); } } function LoadRatesightResizer() { AddHeadScript('rsResizer', "https://resources.ratesight.com/vendor/iframe-resizer/iframe-resizer.parent.js", function () { }); } function LoadRatesightWidgets() { jQuery(function () { //const url = window.location.search; //let urlParameters = new URLSearchParams(url); const OPTION_TYPE = 10; const OFFICE_ID = 172718; const DOMAIN_ID = 3173824; GetRatesightWidgetContent(OPTION_TYPE, OFFICE_ID, DOMAIN_ID); window.addEventListener("message", function (messageObject) { RatesightMessageProcessor(messageObject); }) LoadVisitIQ(); LoadMetaPixelScript(); /*LoadAudiencLabs();*/ }); } async function GetRatesightWidgetContent(typ, oid, did) { if (document.getElementById('wpadminbar') === null) { } else { AddHeadStyle('header.et_pb_section_0_tb_header { top: 64px !important; }'); } let originUrl = window.location.href; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetContent.ashx?typ=' + typ + '&oid=' + oid + '&did=' + did + "&url=" + originUrl; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetContent.ashx?typ=' + typ + '&oid=' + oid + '&did=' + did + "&url=" + originUrl; } jQuery.ajax({ type: 'GET', url: targetUrl, success: onSuccess, error: onFailure }); function onSuccess(result) { /*Load sidebar at very top of body*/ let contentDiv = document.createElement('div'); contentDiv.id = 'rsContent'; contentDiv.innerHTML = result; document.body.insertBefore(contentDiv, document.body.firstChild); DisplayTime("Ratesight - Sidebar loaded"); } function onFailure(error) { console.log('Error!!' + error.log); } } async function LoadVisitIQ() { const PIX_IMAGE_ID = ''; if (PIX_IMAGE_ID != undefined && PIX_IMAGE_ID != '') { //let element = document.createElement('script'); //element.src = 'https://pixel.visitiq.io/vpixel.js'; //element.type = 'text/javascript'; //document.body.appendChild(element); //let idEl = document.createElement('script'); //idEl.innerText = "vpixel.piximage('5d398723-ba6c-4b38-9a61-164a5a5fb748');"; //idEl.async = true; //idEl.type = 'text/javascript'; //document.body.appendChild(idEl); jQuery.ajax({ url: 'https://pixel.visitiq.io/vpixel.js', dataType: "script", success: onSuccess, error: onFailure }); } function onSuccess() { vpixel.piximage(PIX_IMAGE_ID);//Method call of loaded script DisplayTime('Ratesight - Visitor Analytics Loaded'); } function onFailure(error) { console.log('Error!!' + error.log); } } async function LoadAudiencLabsScript() { /*Run script from script*/ if (pixelId != undefined && pixelId != '') { jQuery.ajax({ url: 'https://cdn.audiencelab.io/pixel_V2.js', dataType: "script", success: onSuccess, error: onFailure }); } function onSuccess(result) { DisplayTime('Ratesight - AL Analytics Loaded'); } function onFailure(error) { console.log('Error!!' + error.log); } } async function LoadCapitalAudienceScript() { /*const CA_PIXEL_ID = '';*/ if (CA_PIXEL_ID != undefined && CA_PIXEL_ID != '') { /*Run script from script*/ AddHeadScript('Capital Audience', 'https://api.targeting.capitalaudience.com/pixel/script.js', function () { }); window.analyticsLayer = window.analyticsLayer || []; window.analyticsLayer.push({ event: 'pageview', websiteId: CA_PIXEL_ID }); } } async function LoadMetaPixelScript() { const META_PIXEL_ID = ''; if (META_PIXEL_ID != undefined && META_PIXEL_ID != '') { !function (f, b, e, v, n, t, s) { if (f.fbq) return; n = f.fbq = function () { n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments) }; if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0; t.src = v; s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s) }(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', META_PIXEL_ID); fbq('track', 'PageView'); DisplayTime('Meta - Advertising Pixel loaded'); } } function MonitorPopupConditions() { if (sessionStorage.getItem('popupCount')) { _popupCount = parseInt(sessionStorage.getItem('popupCount')); WriteVerbose('Retrieved PopupCount: ' + sessionStorage.getItem('popupCount').toLowerCase()); } if (sessionStorage.getItem('suppressOpen')) { _suppressOpen = sessionStorage.getItem('suppressOpen').toLowerCase() === 'true'; WriteVerbose('Retrieved Suppress Open: ' + sessionStorage.getItem('suppressOpen').toLowerCase()); } [TRIGGERTIME] [TRIGGERSCROLL] [TRIGGERINACTIVETIME] [TRIGGERABANDONED] [TRIGGERLINKCLICK] [SESSIONSHOWS] [SUPRESSSHOWS] } function MonitorTriggerTime() { let pageTimeSeconds = [PAGETIMESECONDS];/*In milliseconds*/ let loadDateTime = Date.now(); let triggerInterval = setInterval(function () { if (Date.now() - loadDateTime >= pageTimeSeconds) { clearInterval(triggerInterval); ShowRatesightPopupForm(); WriteVerbose('Popup triggered by time'); } }, 1000); } function MonitorTriggerScroll() { document.addEventListener("scroll", (event) => { if (GetScrollPercent() > [SCROLLPERCENT]) {/*In WHOLE PERCENT*/ ShowRatesightPopupForm(); WriteVerbose('Popup triggered by scroll'); } }); } function MonitorTriggerInactive() { let inactiveTime = 0; let inactiveInterval = setInterval(inactiveTimerIncrement, 1000); // 1 minute jQuery(this).mousemove(function (e) { inactiveTime = 0; }); jQuery(this).keypress(function (e) { inactiveTime = 0; }); function inactiveTimerIncrement() { inactiveTime = inactiveTime + 1; if (inactiveTime > [INACTIVETIME]) { clearInterval(inactiveInterval); ShowRatesightPopupForm(); WriteVerbose('Popup triggered by inactivity'); } } } function MonitorTriggerAbandoned() { // Detect mouse leave (for desktop) jQuery(document).mouseleave(function () { ShowRatesightPopupForm(); WriteVerbose('Popup triggered by abandoned'); }); if (IsMobileDevice()) { document.addEventListener("scroll", (event) => { // Detect scroll up (for mobile) let scrollTop = window.scrollY || document.documentElement.scrollTop; if (scrollTop < _lastScrollTop) { ShowRatesightPopupForm(); WriteVerbose('Popup triggered by scrolling up on mobile'); } _lastScrollTop = scrollTop; }); // Detect back button press (for mobile) window.addEventListener('popstate', function () { ShowRatesightPopupForm(); WriteVerbose('Popup triggered by back button on mobile'); }); } } function MonitorTriggerLinkClicked() { let aLinks = document.querySelectorAll('a[href="#rs[FORMID]"]'); aLinks.forEach(link => { link.addEventListener('click', function (evt) { evt.preventDefault(); ShowRatesightPopupForm(true); WriteVerbose('Popup triggered by link clicked'); }); }); //jQuery(document).on("click", "a", function (evt) { // evt.preventDefault(); // ShowRatesightPopupForm(); // WriteVerbose('Popup triggered by link clicked'); //}); } function RatesightMessageProcessor(messageObject) { if (messageObject == undefined || messageObject == null) { return; } if (messageObject.data == null || messageObject.data == undefined) { return; } let rsFilter = '[Ratesight]'; let cmd = String(messageObject.data); if (cmd.startsWith(rsFilter)) { WriteVerbose("PostMessage processing: " + messageObject.data); cmd = cmd.slice(rsFilter.length); if (cmd == 'showprivacypolicyform') { CloseRatesightPrivacyPolicy(); ShowRatesightPrivacyPolicyForm(); } else if (cmd == 'closeprivacypolicyform') { CloseRatesightPrivacyPolicy(); ShowRatesightPrivacyPolicyLink(); } else if (cmd == 'showchatbotform') { CloseRatesightChatBot(); ShowRatesightChatBotForm(); } else if (cmd == 'closechatbotform') { CloseRatesightChatBot(); ShowRatesightChatBotLink(); } else if (cmd == 'closepopupform') { CloseRatesightPopupForm(); } else if (cmd == 'popupcomplete') { _suppressOpen = true; sessionStorage.setItem("suppressOpen", _suppressOpen); } else if (cmd == 'opensidebar') { ShowRatesightSidebar(); } else if (cmd == 'closesidebar') { HideRatesightModal(); } else if (cmd == 'showmakepayment') { ShowRatesightMakePayment(); } else { HideRatesightModal();//Just in case ShowRatesightModal(cmd); HideRatesightSidebar();//Don't need that now } /*WriteVerbose("PostMessage processing complete");*/ } } function ShowRatesightSidebar() { const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetSidebar'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetSidebar'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { _modalOpen = true; WriteVerbose("Showing sidebar"); AddAfterRatesightDivContent(result.d); ResizeIframeById('rs-sidebar-widget'); } async function onError(error) { console.log('Sidebar load error: ' + error.d); } } function HideRatesightSidebar() { CloseForm('rs-sidebar-widget'); } async function LoadSocialProof() { jQuery(document).ready(function () { const RS_SP_INTERVAL = 20000; const RS_SP_TIMEOUT = 7000; CloseForm('rs-socialproof-widget'); DisplayTime("Ratesight - Social Proof loaded"); setInterval(function notify() { setTimeout(function () { OpenSocialProof(); }, 1500); setTimeout(function () { jQuery("#rs-socialproof-widget").fadeOut("slow", function () { CloseForm('rs-socialproof-widget'); }); }, RS_SP_TIMEOUT); return notify; }(), RS_SP_INTERVAL); }); } async function OpenSocialProof() { //console.log("Opening Social Proof"); const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetSocialProof'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetSocialProof'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { //console.log("Showing sidebar"); AddAfterRatesightDivContent(result.d); jQuery("#rs-socialproof-widget").fadeIn("slow", function () { jQuery("#rs-socialproof-widget").show(); }); } async function onError(error) { console.log('SocialProof load error: ' + error.d); } } function ShowRatesightPrivacyPolicyForm() { const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetPrivacyPolicyForm'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetPrivacyPolicyForm'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { _modalOpen = true; //console.log("Showing Privacy Policy"); AddAfterRatesightDivContent(result.d); ResizeIframeById('rs-privacy-policy'); } async function onError(error) { console.log('Privacy Policy load error: ' + error.d); } } async function ShowRatesightPrivacyPolicyLink() { WriteVerbose('Trying to show Privacy Policy link'); const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetPrivacyPolicyLink'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetPrivacyPolicyLink'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { WriteVerbose("Showing Privacy Policy Link"); AddAfterRatesightDivContent(result.d); } async function onError(error) { WriteVerbose('Privacy Policy load error: ' + error.d); } } function CloseRatesightPrivacyPolicy() { _modalOpen = false; CloseForm('rs-privacy-policy'); } function ShowRatesightChatBotForm() { WriteVerbose('Trying to show ChatBot form'); const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetChatbotForm'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetChatbotForm'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { _modalOpen = true; WriteVerbose("Showing chatbot"); AddAfterRatesightDivContent(result.d); /*ResizeIframeById('rs-message-widget');*/ } async function onError(error) { console.log('Chatbot load error: ' + error.d); } } function ShowRatesightChatBotLink() { WriteVerbose('Trying to show ChatBot link'); const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetChatbotLink'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetChatbotLink'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { WriteVerbose("Showing chatbot"); AddAfterRatesightDivContent(result.d); } async function onError(error) { console.log('Chatbot load error: ' + error.d); } } function CloseRatesightChatBot() { _modalOpen = false; CloseForm('rs-message-widget'); } function ShowRatesightPopupForm(alwaysShow = false) { if (_suppressOpen && !alwaysShow) { WriteVerbose('Popup open suppressed because previously opened'); return; } if (_modalOpen && !alwaysShow) { WriteVerbose('Popup already open'); return; } WriteVerbose('Show Popup form'); if (alwaysShow || (_popUpMax < 1 || _popupCount < _popUpMax)) { _popupCount++; sessionStorage.setItem("popupCount", _popupCount); const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/WidgetMethods.aspx/GetPopupForm'; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetMethods.aspx/GetPopupForm'; } jQuery.ajax({ type: 'POST', url: targetUrl, contentType: 'application/json; charset=utf-8', data: JSON.stringify({ oid: OFFICE_ID }), dataType: 'json', success: onSuccess, error: onError }); async function onSuccess(result) { if (_modalOpen) { return; // Already opened on another thread } WriteVerbose("Showing popup"); _modalOpen = true; AddAfterRatesightDivContent(result.d); ResizeIframeById('rs-popup-widget'); } async function onError(error) { console.log('Popup load error: ' + error.d); } } else { WriteVerbose('Popup already shown'); } } function CloseRatesightPopupForm() { CloseForm("rs-popup-widget"); _modalOpen = false; _suppressOpen = _suppressOpenSetting; sessionStorage.setItem("suppressOpen", _suppressOpen); WriteVerbose("Set SuppressOpen: " + sessionStorage.getItem('suppressOpen')); } function ShowRatesightMakePayment() { const OFFICE_ID = 172718; let targetUrl = 'https://go.ratesight.com/Widgets/Sidebar_MakePayment.aspx?OID=' + OFFICE_ID; ShowRatesightModal(targetUrl); } function ShowRatesightModal(url) { _modalOpen = true; if (window.location.href.includes('localhost')) { url = url.replace('https://go.ratesight.com/', 'http://localhost:60574/'); } let iframeContent = ''; AddAfterRatesightDivContent(iframeContent); ResizeIframeById('rsModal'); WriteVerbose('Showing ' + url); } async function LoadNumberReplace() { const ORIGINAL_PHONE = '[ORIGINAL_PHONE]'; const ORIGINAL_PHONE_A = '[ORIGINAL_PHONE_A]'; const ORIGINAL_PHONE_B = '[ORIGINAL_PHONE_B]'; const ORIGINAL_PHONE_C = '[ORIGINAL_PHONE_C]'; const ORIGINAL_PHONE_D = '[ORIGINAL_PHONE_D]'; const ORIGINAL_PHONE_E = '[ORIGINAL_PHONE_E]'; const ORIGINAL_PHONE_F = '[ORIGINAL_PHONE_F]'; const RS_REPLACE_NUMBER = '[RS_REPLACE_NUMBER]'; const RS_REPLACE_NUMBER_FORMATTED = '[RS_REPLACE_NUMBER_FORMATTED]'; const IS_URI_AWARE = [RS_REPLACE_URIAWARE]; if (IS_URI_AWARE) { let found = false; if (sessionStorage.getItem('replaceNumber')) { found = sessionStorage.getItem('replaceNumber') === 'true'; } else { let url = window.location.href.toLowerCase(); if (url.includes('gclid') || url.includes('fbclid') || url.includes('msclkid') || url.includes('wbraid') || url.includes('gbraid')) { found = true; sessionStorage.setItem('replaceNumber', 'true'); } } if (!found) { return; } } DisplayTime("Ratesight - Overwriting phone numbers"); ReplaceInText(document.body, ORIGINAL_PHONE, RS_REPLACE_NUMBER); ReplaceInText(document.body, ORIGINAL_PHONE_A, RS_REPLACE_NUMBER_FORMATTED); ReplaceInText(document.body, ORIGINAL_PHONE_B, RS_REPLACE_NUMBER_FORMATTED); ReplaceInText(document.body, ORIGINAL_PHONE_C, RS_REPLACE_NUMBER_FORMATTED); ReplaceInText(document.body, ORIGINAL_PHONE_D, RS_REPLACE_NUMBER_FORMATTED); ReplaceInText(document.body, ORIGINAL_PHONE_E, RS_REPLACE_NUMBER_FORMATTED); ReplaceInText(document.body, ORIGINAL_PHONE_F, RS_REPLACE_NUMBER_FORMATTED); } function ReplaceInText(element, oldPhoneNumber, newPhoneNumber) { for (let node of element.childNodes) { switch (node.nodeType) { case Node.ELEMENT_NODE: if (node.tagName == 'A' && node.href && node.href.includes(oldPhoneNumber)) { node.href = node.href.replace(oldPhoneNumber, newPhoneNumber); node.href = node.href.replace("+", ""); WriteVerbose(node.tagName); } ReplaceInText(node, oldPhoneNumber, newPhoneNumber); break; case Node.TEXT_NODE: if (node.textContent.includes(oldPhoneNumber)) { node.textContent = node.textContent.replace(oldPhoneNumber, newPhoneNumber); } break; case Node.DOCUMENT_NODE: ReplaceInText(node, oldPhoneNumber, newPhoneNumber); } } } function AddHeadStyle(style) { jQuery('head').append(''); } function AddHeadScript(id, url, callback) { if (!document.getElementById(id)) { let header_script = document.createElement("script"); header_script.type = "text/javascript"; header_script.setAttribute('crossorigin', 'anonymous'); header_script.id = id; if (header_script.readyState) { header_script.onreadystatechange = function () { if (header_script.readyState == "loaded" || header_script.readyState == "complete") { header_script.onreadystatechange = null; callback(); } } } else { header_script.onload = function () { callback(); } } header_script.src = url; document.getElementsByTagName("head")[0].appendChild(header_script); DisplayTime('Ratesight - Loaded ' + id); } } function AddAfterRatesightDivContent(content) { /*Append content after the original script, wherever it is located*/ jQuery('#ratesight-sidebar-widget').after(content); } function ResizeIframeById(id) { iframeResize({ license: '1jy4dww5qzv-s54r73oxcn-v59f4kfgfz', checkOrigin: false }, '#' + id); WriteVerbose('Resizing ' + id); } function HideRatesightModal() { _modalOpen = false; CloseForm('rsModal'); } function CloseForm(formID) { let existingForm = document.getElementById(formID); while (existingForm != undefined && existingForm != null) { document.getElementById(formID).remove(); existingForm = document.getElementById(formID);//Somehow getting duplicates or something, remove again WriteVerbose('Hiding ' + formID); } } function IsMobileDevice() { return /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } function GetScrollPercent() { var h = document.documentElement, b = document.body, st = 'scrollTop', sh = 'scrollHeight'; return (h[st] || b[st]) / ((h[sh] || b[sh]) - h.clientHeight) * 100; } async function DisplayTime(message) { console.log(message + ' - ' + (Date.now() - START_TIME) + ' milliseconds'); } async function WriteVerbose(message) { if (_logVerbose) { console.log(message); } }