//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(function () {
//const url = window.location.search;
//let urlParameters = new URLSearchParams(url);
const OPTION_TYPE = 10;
const OFFICE_ID = 2398;
const DOMAIN_ID = 70436;
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 {
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 = '';
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('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*/
(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('Ratesight - CA Analytics loaded');
}
}
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() {
[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();
//console.log('Popup triggered by time');
}
}, 1000);
}
function MonitorTriggerScroll() {
document.addEventListener("scroll", (event) => {
if (GetScrollPercent() > [SCROLLPERCENT]) {/*In WHOLE PERCENT*/
ShowRatesightPopupForm();
//console.log('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();
//console.log('Popup triggered by inactivity');
}
}
}
function MonitorTriggerAbandoned() {
jQuery(document).mouseleave(function () {
ShowRatesightPopupForm();
//console.log('Popup triggered by abandoned');
});
}
function MonitorTriggerLinkClicked() {
jQuery(document).on("click", "a", function (evt) {
evt.preventDefault();
ShowRatesightPopupForm();
//console.log('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)) {
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 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;
let url = window.location.href.toLowerCase();
if (url.includes('gclid') || url.includes('fbclid') || url.includes('msclkid') ||
url.includes('wbraid') || url.includes('gbraid'))
{
found = 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("+", "");
//console.log(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);
}
}
}
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 = 2398;
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 = 2398;
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 = 2398;
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 = 2398;
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 = 2398;
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) {
//console.log('Popup open suppressed because previously opened');
return;
}
if (_popupOpen) {
//console.log('Popup already open');
return;
}
if (_popUpMax < 1 || _popupCount < _popUpMax) {
_popupCount++;
const OFFICE_ID = 2398;
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 (_popupOpen) {
return;//Already opened on another thread
}
//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 = 2398;
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 = 2398;
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');
}