Add page visit Telegram notifications
Some checks failed
Tests / Laravel tests (pull_request) Failing after 6m57s

This commit is contained in:
2026-06-03 23:19:06 +02:00
parent fdc10a0acb
commit bbfc64031f
10 changed files with 434 additions and 45 deletions

View File

@@ -170,6 +170,62 @@
});
</script>
<script>
(() => {
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
if (!csrfToken || !window.fetch) {
return;
}
const visitorKey = 'cv_visitor_id';
const createVisitorId = () => window.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
let visitorId = createVisitorId();
try {
visitorId = window.localStorage.getItem(visitorKey) || visitorId;
window.localStorage.setItem(visitorKey, visitorId);
} catch {
// Tracking should never break the page when storage is blocked.
}
window.fetch('{{ route('page-visits.store') }}', {
method: 'POST',
keepalive: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': csrfToken,
},
body: JSON.stringify({
visitor_id: visitorId,
url: window.location.href,
path: window.location.pathname,
title: document.title,
referrer: document.referrer,
language: navigator.language,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
screen: {
width: window.screen?.width,
height: window.screen?.height,
},
viewport: {
width: window.innerWidth,
height: window.innerHeight,
},
device_pixel_ratio: window.devicePixelRatio,
color_depth: window.screen?.colorDepth,
platform: navigator.platform,
vendor: navigator.vendor,
hardware_concurrency: navigator.hardwareConcurrency,
device_memory: navigator.deviceMemory,
cookies_enabled: navigator.cookieEnabled,
online: navigator.onLine,
}),
}).catch(() => {});
})();
</script>
@stack('scripts')
</body>