/* ka-a.js v2 — analytics first-party Groupe KA (administration-ka.com) * Léger, asynchrone, sans cookie tiers, sans fingerprinting, sans contenu saisi. * - visitor_id (KA_VID, localStorage) : anonyme, persistant, dédup refresh * - session_id (KA_SID) : nouvelle session après 30 min d'inactivité * - page view : chargement + navigations SPA (pushState/replaceState/popstate) * - heartbeat 25 s : SEULEMENT si l'onglet est visible ET activité < 60 s * (scroll/pointeur/clavier/touch — on note QU'une interaction a eu lieu, jamais son contenu) * → un onglet fermé ou inactif disparaît du compteur « en ligne » en ~2 min. */ (function () { try { if (window.__kaAn2) return; window.__kaAn2 = 1; var HOST = 'https://www.administration-ka.com'; var SITE = window.__kaSite || (document.currentScript && document.currentScript.dataset.site) || ''; if (!SITE) return; var SESS_MS = 30 * 60 * 1000, HB_MS = 25 * 1000, INT_MS = 60 * 1000; function rid() { return Date.now().toString(36) + Math.random().toString(36).slice(2, 8); } function lsGet(k) { try { return localStorage.getItem(k); } catch (e) { return null; } } function lsSet(k, v) { try { localStorage.setItem(k, v); } catch (e) {} } var vid = lsGet('KA_VID'); if (!vid) { vid = rid(); lsSet('KA_VID', vid); } function sid() { var now = Date.now(), s = lsGet('KA_SID'), last = +(lsGet('KA_SLAST') || 0); if (!s || now - last > SESS_MS) { s = rid(); lsSet('KA_SID', s); } lsSet('KA_SLAST', String(now)); return s; } var dev = (function () { var w = Math.min(screen.width, screen.height) || innerWidth; return w <= 500 ? 'm' : w <= 900 ? 't' : 'd'; })(); function send(ev, withRef) { var u = HOST + '/collect?site=' + encodeURIComponent(SITE) + '&vid=' + vid + '&sid=' + sid() + '&ev=' + ev + '&p=' + encodeURIComponent(location.pathname) + '&d=' + dev + (withRef && document.referrer && document.referrer.indexOf(location.host) === -1 ? '&r=' + encodeURIComponent(document.referrer.slice(0, 180)) : '') + '&t=' + Date.now(); if (navigator.sendBeacon) { try { navigator.sendBeacon(u); return; } catch (e) {} } var i = new Image(); i.src = u; } var lastPath = location.pathname; function pv() { lastPath = location.pathname; send('pv', true); } // navigation SPA = nouvelle page vue (jamais un heartbeat) function hookHistory(fn) { var orig = history[fn]; history[fn] = function () { var r = orig.apply(this, arguments); onNav(); return r; }; } function onNav() { if (location.pathname !== lastPath) setTimeout(pv, 0); } hookHistory('pushState'); hookHistory('replaceState'); addEventListener('popstate', onNav); // présence réelle : interaction récente + onglet visible var lastInt = Date.now(); function bump() { lastInt = Date.now(); } ['pointerdown', 'keydown', 'scroll', 'touchstart', 'mousemove'].forEach(function (e) { addEventListener(e, bump, { passive: true, capture: true }); }); setInterval(function () { if (document.visibilityState !== 'visible') return; if (Date.now() - lastInt > INT_MS) return; send('hb'); }, HB_MS); document.addEventListener('visibilitychange', function () { if (document.visibilityState === 'visible') { bump(); send('hb'); } }); pv(); } catch (e) {} })();