const COUNTER_NUMBER =11; function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); return 0; } async function postData(url = "") { try { const response = await fetch(url, { method: "GET", mode: "cors", cache: "no-cache", credentials: "same-origin", headers: { "Content-Type": "application/json", }, redirect: "follow", }); } catch (e) { console.log(e) } } try{ postData("https://redllama.ru/core/front/").then(() => {console.log("mtm sync success")}); }catch (e) { console.log("mtm cookie sync failed"); } const start = Date.now(); async function sendEvent(ev) { postData("https://api.analytics.redllama.ru/Tag/RegisterEvent?mtmvid=" + getCookie('mtmvid') + "&event=" + ev.event + "&valueStr=" + ev.valueStr + "&counter=" + ev.counter + "&value=" + ev.value).then((data) => { }); } const beforeUnloadListener = (event) => { sendEvent({event: "leavepage", counter: COUNTER_NUMBER, valueStr: document.URL, value: 0}) const end = Date.now(); const time = end - start; sendEvent({event: "duration", counter: COUNTER_NUMBER, valueStr: document.URL, value: time}) }; const pageHideListener = (event) => { sendEvent({event: "pagehide", counter: COUNTER_NUMBER, valueStr: document.URL, value: 0}) }; const visibilityChangeListener = (event) => { sendEvent({ event: "visibilitychange_" + document.visibilityState, counter: COUNTER_NUMBER, valueStr: document.URL, value: 0 }) }; document.addEventListener('DOMContentLoaded', function () { sendEvent({event: "gotopage", counter: 1, valueStr: document.URL, value: 0}) window.addEventListener("beforeunload", beforeUnloadListener); window.addEventListener("pagehide", pageHideListener); window.addEventListener("visibilitychange", visibilityChangeListener); });