//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 _popupOpen = false; let _popupCount = 0; let _popUpMax = 1; let _suppressOpen = false; let _suppressOpenSetting = 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) { LoadRatesightjQuery("https://resources.ratesight.com/vendor/jquery/v3.5.1/dist/jquery.min.js", function () { LoadRatesightWidgets(); }); function LoadRatesightjQuery(url, callback) { var jquery_script = document.createElement("script"); jquery_script.type = "text/javascript"; if (jquery_script.readyState) { jquery_script.onreadystatechange = function () { if (jquery_script.readyState == "loaded" || jquery_script.readyState == "complete") { jquery_script.onreadystatechange = null; callback(); } } } else { jquery_script.onload = function () { callback(); } } jquery_script.src = url; document.getElementsByTagName("head")[0].appendChild(jquery_script); //console.log("Loaded jQuery 3.5.1"); } } else { LoadRatesightWidgets(); } } function LoadRatesightBootstrap() { if (!window.bootstrap) { LoadBootstrap("https://resources.ratesight.com/vendor/bootstrap/v5.3.0/js/bootstrap.bundle.min.js", function () { }); function LoadBootstrap(url, callback) { var bootstrap_script = document.createElement("script"); bootstrap_script.type = "text/javascript"; if (bootstrap_script.readyState) { bootstrap_script.onreadystatechange = function () { if (bootstrap_script.readyState == "loaded" || bootstrap_script.readyState == "complete") { bootstrap_script.onreadystatechange = null; callback(); } } } else { bootstrap_script.onload = function () { callback(); } } bootstrap_script.src = url; document.getElementsByTagName("head")[0].appendChild(bootstrap_script); DisplayTime("Ratesight loaded Bootstrap"); } } } function LoadRatesightWidgets() { jQuery(document).ready(function () { //const url = window.location.search; //let urlParameters = new URLSearchParams(url); const OPTION_TYPE = 10; const OFFICE_ID = 94512; const DOMAIN_ID = 438; GetRatesightWidgetContent(OPTION_TYPE, OFFICE_ID, DOMAIN_ID); window.addEventListener("message", function (messageObject) { RatesightMessageProcessor(messageObject); }) LoadVisitIQ(); /*LoadAudiencLabs();*/ }); } async function GetRatesightWidgetContent(typ, oid, did) { if (document.getElementById('wpadminbar') === null) { } else { jQuery('head').append(''); } let targetUrl = 'https://go.ratesight.com/Widgets/WidgetContent.ashx?typ=' + typ + '&oid=' + oid + '&did=' + did; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/WidgetContent.ashx?typ=' + typ + '&oid=' + oid + '&did=' + did; } jQuery.ajax({ type: 'GET', url: targetUrl, success: onSuccess, error: onFailure }); function onSuccess(result) { //document.body.appendChild(modalDiv); 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 = '6b218151-bc8f-416c-ab4e-9da5933fc711'; 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); DisplayTime('VisitIQ 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('AL Analytics Loaded'); } function onFailure(error) { console.log('Error!!' + error.log); } } async function LoadCapitalAudienceScript() { /*const CA_PIXEL_ID = '[CAPITALAUDIENCEID]';*/ if (CA_PIXEL_ID != undefined && CA_PIXEL_ID != '') { /*Run script from script*/ (function () { var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; g.async = true; g.src = 'https://api.targeting.capitalaudience.com/pixel/script.js'; s.parentNode.insertBefore(g, s); })(); window.analyticsLayer = window.analyticsLayer || []; window.analyticsLayer.push({ event: 'pageview', websiteId: CA_PIXEL_ID }); DisplayTime('CA Analytics loaded'); } } function MonitorPopupConditions() { [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(); } }, 1000); } function MonitorTriggerScroll() { document.addEventListener("scroll", (event) => { if (GetScrollPercent() > [SCROLLPERCENT]) {/*In WHOLE PERCENT*/ ShowRatesightPopupForm(); } }); } 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(); } } } function MonitorTriggerAbandoned() { jQuery(document).mouseleave(function () { ShowRatesightPopupForm(); }); } function MonitorTriggerLinkClicked() { jQuery(document).on("click", "a", function (evt) { evt.preventDefault(); ShowRatesightPopupForm(); }); } 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)) { 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 == '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 } } } async function LoadSocialProof() { jQuery(document).ready(function () { const RS_SP_INTERVAL = 15000; 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 = 94512; 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"); AddToRatesightDivContent(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 = 94512; 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) { //console.log("Showing Privacy Policy"); AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Privacy Policy load error: ' + error.d); } } async function ShowRatesightPrivacyPolicyLink() { //console.log('Trying to show Privacy Policy link'); const OFFICE_ID = 94512; 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) { //console.log("Showing Privacy Policy Link"); AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Privacy Policy load error: ' + error.d); } } function CloseRatesightPrivacyPolicy() { CloseForm('rs-privacy-policy'); } function ShowRatesightChatBotForm() { //console.log('Trying to show ChatBot form'); const OFFICE_ID = 94512; 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) { //console.log("Showing chatbot"); AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Chatbot load error: ' + error.d); } } function ShowRatesightChatBotLink() { //console.log('Trying to show ChatBot link'); const OFFICE_ID = 94512; 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) { //console.log("Showing chatbot"); AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Chatbot load error: ' + error.d); } } function CloseRatesightChatBot() { CloseForm('rs-message-widget'); } function ShowRatesightPopupForm() { //console.log('Show Popup form'); if (_suppressOpen) return; if (_popUpMax < 1 || _popupCount < _popUpMax) { _popupCount++; const OFFICE_ID = 94512; 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) { //console.log("Showing popup"); _popupOpen = true; AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Popup load error: ' + error.d); } } else { //console.log('Popup already shown'); } } function CloseRatesightPopupForm() { CloseForm("rs-popup-widget"); _popupOpen = false; _suppressOpen = _suppressOpenSetting; //Update cookie data indicate never open? } function ShowRatesightSidebar() { const OFFICE_ID = 94512; 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) { //console.log("Showing sidebar"); AddToRatesightDivContent(result.d); } async function onError(error) { console.log('Sidebar load error: ' + error.d); } } function HideRatesightSidebar() { CloseForm('rs-sidebar-widget'); } function ShowRatesightMakePayment() { const OFFICE_ID = 94512; let targetUrl = 'https://go.ratesight.com/Widgets/Sidebar_MakePayment.aspx?OID=' + OFFICE_ID; if (window.location.href.includes('localhost')) { targetUrl = 'http://localhost:60574/Widgets/Sidebar_MakePayment.aspx?OID=' + OFFICE_ID; } ShowRatesightModal(targetUrl); } function ShowRatesightModal(url) { let iframeContent = ''; AddToRatesightDivContent(iframeContent); //console.log('Showing modal'); } function AddToRatesightDivContent(content) { jQuery('#ratesight-sidebar-widget').after(content); } function HideRatesightModal() { 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 //console.log('Hiding ' + formID); } } 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'); }