(function () { 'use strict'; if (window.fiTrafficTracking || window.top !== window.self) return; window.fiTrafficTracking = true; var path = location.pathname.replace(/\/index\.php$/, '/').replace(/\/$/, ''); var area = path.split('/')[1] || (location.hostname === 'school.feisinfo.org' ? 'crm' : 'home'); var selected = new URLSearchParams(location.search).get('section') || ''; var lastSent = null; var timer; var pending = Promise.resolve(); function send() { if (document.visibilityState !== 'visible' || selected === lastSent) return; lastSent = selected; var body = new URLSearchParams({ section: selected, device: matchMedia('(max-width: 767px)').matches ? 'mobile' : 'desktop' }); pending = pending.then(function () { return fetch('/layout/traffic-collect.php', { method: 'POST', body: body, credentials: 'same-origin', referrerPolicy: 'same-origin', keepalive: true }); }).catch(function () {}); } function schedule() { clearTimeout(timer); timer = setTimeout(send, 180); } document.addEventListener('fi:section-view', function (event) { if (!event.detail || event.detail.area !== area || typeof event.detail.section !== 'string') return; selected = event.detail.section; schedule(); }); window.addEventListener('pageshow', function (event) { if (!event.persisted) return; lastSent = null; schedule(); }); document.addEventListener('visibilitychange', function () { if (document.visibilityState === 'visible') schedule(); }); if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', schedule); else schedule(); })();