From 5e5010c06c490836ab213c206bc1929716d1e44a Mon Sep 17 00:00:00 2001 From: ssbg04 Date: Thu, 22 Oct 2026 01:08:40 +0800 Subject: [PATCH] feat(analytics): add global background visitor geo telemetry to Layout --- src/layouts/Layout.astro | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 2dd0179..27c1266 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -285,6 +285,24 @@ const isRootPage = Astro.url.pathname === '/'; window.addEventListener('offline', function() { showStatus(false); }); if (!navigator.onLine) showStatus(false); } + + // 3. Global Visitor Geolocation Telemetry (Option A) + try { + if (!sessionStorage.getItem('geo_logged')) { + var pingGeo = function() { + fetch('/api/geo', { priority: 'low' }) + .then(function() { + sessionStorage.setItem('geo_logged', '1'); + }) + .catch(function() {}); + }; + if ('requestIdleCallback' in window) { + requestIdleCallback(pingGeo, { timeout: 3000 }); + } else { + setTimeout(pingGeo, 1500); + } + } + } catch (e) {} })();