2026-02-08 03:01:52 -05:00
|
|
|
'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 {
|
2026-02-08 14:05:15 -05:00
|
|
|
// Send beacon to THIS website's API, which will relay it to the admin dash
|
|
|
|
|
await fetch('/api/analytics', {
|
2026-02-08 03:01:52 -05:00
|
|
|
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;
|
|
|
|
|
}
|