23 lines
559 B
TypeScript
23 lines
559 B
TypeScript
|
|
'use client';
|
||
|
|
|
||
|
|
import { useEffect } from 'react';
|
||
|
|
import { usePathname } from 'next/navigation';
|
||
|
|
|
||
|
|
export default function AnalyticsTracker() {
|
||
|
|
const pathname = usePathname();
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
if (!pathname || pathname.startsWith('/admin') || pathname.startsWith('/api')) return;
|
||
|
|
|
||
|
|
fetch('/api/analytics/track', {
|
||
|
|
method: 'POST',
|
||
|
|
headers: { 'Content-Type': 'application/json' },
|
||
|
|
body: JSON.stringify({ path: pathname }),
|
||
|
|
}).catch(() => {
|
||
|
|
// Ignore background tracking errors
|
||
|
|
});
|
||
|
|
}, [pathname]);
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|