feat(analytics): add global background visitor geo telemetry to Layout

This commit is contained in:
ssbg04 committed 2026-10-22 01:08:40 +08:00
1 parent 7852c64a26
commit 5e5010c06c
1 file changed
+18
+18
View File
@@ -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) {}
})();
</script>
</body>