(function setupMetrika() { let initialized = false; function counterIdFrom(content) { const value = String(content?.["analytics.metrikaCounterId"] || "").trim(); return /^\d+$/.test(value) ? Number(value) : null; } function reachGoal(counterId, name, params) { if (typeof window.ym === "function") { window.ym(counterId, "reachGoal", name, params || {}); } } function placementFor(element) { if (element.classList.contains("header-cta")) return "header"; if (element.classList.contains("mobile-sticky-cta")) return "mobile_sticky"; if (element.closest(".hero-actions")) return "hero"; if (element.closest(".final-cta")) return "final"; if (element.closest("footer")) return "footer"; if (element.closest("nav, .mobile-menu")) return "navigation"; return "content"; } function enableDetailedTracking(counterId) { document.addEventListener("click", (event) => { const link = event.target.closest?.("a[data-link-key]"); if (!link) return; const key = link.dataset.linkKey; const params = { link: key, placement: placementFor(link) }; if (key === "links.apply") reachGoal(counterId, "application_click", params); else if (key === "links.regulation") reachGoal(counterId, "regulation_download", params); else if (["links.vk", "links.telegram", "links.website", "links.phone", "links.email"].includes(key)) { reachGoal(counterId, "contact_click", params); } else reachGoal(counterId, "navigation_click", params); }); document.querySelectorAll("details[data-faq-id]").forEach((item) => { item.addEventListener("toggle", () => { if (item.open) reachGoal(counterId, "faq_open", { question: item.dataset.faqId }); }); }); const reached = new Set(); const depths = [25, 50, 75, 90]; let scheduled = false; function checkDepth() { scheduled = false; const available = document.documentElement.scrollHeight - window.innerHeight; const depth = available > 0 ? Math.round((window.scrollY / available) * 100) : 100; depths.forEach((value) => { if (depth >= value && !reached.has(value)) { reached.add(value); reachGoal(counterId, `scroll_${value}`, { depth: value }); } }); } window.addEventListener("scroll", () => { if (scheduled) return; scheduled = true; window.requestAnimationFrame(checkDepth); }, { passive: true }); checkDepth(); window.setTimeout(() => reachGoal(counterId, "engaged_30s"), 30000); } function initialize(content) { if (initialized) return; const counterId = counterIdFrom(content); if (!counterId) return; initialized = true; window.__PFP_METRIKA_ID__ = counterId; window.ym = window.ym || function metrikaQueue() { (window.ym.a = window.ym.a || []).push(arguments); }; window.ym.l = Date.now(); const script = document.createElement("script"); script.async = true; script.src = `https://mc.yandex.ru/metrika/tag.js?id=${counterId}`; document.head.append(script); window.ym(counterId, "init", { ssr: true, clickmap: true, trackLinks: true, accurateTrackBounce: true, webvisor: true, referrer: document.referrer, url: window.location.href, }); window.ym(counterId, "params", { programme: "scholarship_2026" }); enableDetailedTracking(counterId); } document.addEventListener("pfp:content-ready", (event) => initialize(event.detail)); if (window.__PFP_CONTENT__) initialize(window.__PFP_CONTENT__); })();