Files
Webserver/components/Analytics.tsx
Akshay Kolli 9b8a25f5c8
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 27s
Minor changes
2026-02-08 14:05:15 -05:00

31 lines
880 B
TypeScript

'use client';
import { useEffect } from 'react';
import { usePathname } from 'next/navigation';
export function Analytics() {
const pathname = usePathname();
useEffect(() => {
// Send beacon on mount and path change
const sendBeacon = async () => {
try {
// Send beacon to THIS website's API, which will relay it to the admin dash
await fetch('/api/analytics', {
method: 'POST',
body: JSON.stringify({ path: pathname, timestamp: Date.now() }),
headers: { 'Content-Type': 'application/json' },
keepalive: true,
});
} catch (e) {
// Fail silently
console.error('Analytics fail', e);
}
};
sendBeacon();
}, [pathname]);
return null;
}