<!-- BEGIN WHATSSAPP NTEGRATION WITH ROISTAT -->
<script class="js-whatsapp-message-container">"Здавствуйте! У меня есть вопрос. Номер заявки: {roistat_visit}"</script>
<script>
(function() {
if (window.roistat !== undefined) {
handler();
} else {
var pastCallback = typeof window.onRoistatAllModulesLoaded === "function" ? window.onRoistatAllModulesLoaded : null;
window.onRoistatAllModulesLoaded = function () {
if (pastCallback !== null) {
pastCallback();
}
handler();
};
}
function handler() {
function init() {
appendMessageToLinks();
var delays = [1000, 5000, 15000];
setTimeout(function func(i) {
if (i === undefined) {
i = 0;
}
appendMessageToLinks();
i++;
if (typeof delays[i] !== 'undefined') {
setTimeout(func, delays[i], i);
}
}, delays[0]);
}
function replaceQueryParam(url, param, value) {
var explodedUrl = url.split('?');
var baseUrl = explodedUrl[0] || '';
var query = '?' + (explodedUrl[1] || '');
var regex = new RegExp("([?;&])" + param + "[^&;]*[;&]?");
var queryWithoutParameter = query.replace(regex, "$1").replace(/&$/, '');
return baseUrl + (queryWithoutParameter.length > 2 ? queryWithoutParameter + '&' : '?') + (value ? param + "=" + value : '');
}
function appendMessageToLinks() {
var message = document.querySelector('.js-whatsapp-message-container').text;
var text = message.replace(/{roistat_visit}/g, window.roistatGetCookie('roistat_visit'));
text = encodeURI(text);
var linkElements = document.querySelectorAll('[href^="whatsapp://send"], [href*="//wa.me"], [href*="//api.whatsapp.com/send"], [href*="//web.whatsapp.com/send"], [href^="wa.clck.bar"]');
for (var elementKey in linkElements) {
if (linkElements.hasOwnProperty(elementKey)) {
var element = linkElements[elementKey];
element.href = replaceQueryParam(element.href, 'text', text);
}
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
};
})();
</script>
<!-- END WHATSSAPP INTEGRATION WITH ROISTAT -->
<script>
(function () {function ChangeLinkWA() {this.text = "Здравствуйте! Номер моей заявки {wz_metric}";this.cookieSource = "roistat_visit";}
ChangeLinkWA.prototype.editLink = function (url, id) {
if ( decodeURIComponent(url.split("text=")[1]) === this.text.replace(/{wz_metric}/gi, id))
return;
var regexNumberPhone = /\d+/;
if (!regexNumberPhone.test(url)) return;
var phone = url.match(regexNumberPhone)[0];
var host = url.split(phone)[0];
var newUrl =
host === "https://wa.me/"
? host.toString()+phone.toString()+"?text="+(this.text.replace(/{wz_metric}/gi, id))
: host.toString()+phone.toString()+"&text="+(this.text.replace(/{wz_metric}/gi, id));
return newUrl;
};
ChangeLinkWA.prototype.getCookie = function (name) {
var cookie = document.cookie;
var matches = cookie.match(
new RegExp(
"(?:^|; )"+(name.replace(/([.$?*|{}()[]\/+^])/g, "\\$1"))+"=([^;]*)"
)
);
return matches ? decodeURIComponent(matches[1]) : undefined;
};
ChangeLinkWA.prototype.censusLinks = function () {
var links = document.querySelectorAll(
'[href*="//wa.me"], [href*="//api.whatsapp.com/send"], [href*="//web.whatsapp.com/send"], [href^="whatsapp://send"]'
);
var id = this.getCookie(this.cookieSource);
var that = this;
links.forEach(function (link) {
var newLink = that.editLink(link.href, id);
if (newLink) link.href = newLink;
});
};
window.addEventListener("DOMContentLoaded", function () {
if (!(window.__wz_scripts && window.__wz_scripts.scriptsChangeLinkWA)) {
if (!window.__wz_scripts) window.__wz_scripts = {};
window.__wz_scripts.scriptsChangeLinkWA = new ChangeLinkWA();
var interval = setInterval(function () {
var id = window.__wz_scripts.scriptsChangeLinkWA.getCookie(
window.__wz_scripts.scriptsChangeLinkWA.cookieSource
);
if (id) {
clearInterval(interval);
window.__wz_scripts.scriptsChangeLinkWA.censusLinks();
}
}, 200);
}
});
})();
</script>