accesscodes/src/components/conditional-analytics.tsx
anonymousratwastaken 06bf69c167 made analytics work
2025-12-21 09:39:58 +00:00

39 lines
No EOL
1.1 KiB
TypeScript

"use client";
import { Analytics } from "@vercel/analytics/next";
import { SpeedInsights } from "@vercel/speed-insights/next";
export function ConditionalAnalytics() {
return (
<>
<Analytics
beforeSend={(event) => {
// check if user has consented
const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true";
// if not consented, return null to block the event
if (!analyticsEnabled) {
return null;
}
// if consented, return the event to send it
return event;
}}
/>
<SpeedInsights
beforeSend={(event) => {
// check if user has consented
const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true";
// if not consented, return null to block the event
if (!analyticsEnabled) {
return null;
}
// if consented, return the event to send it
return event;
}}
/>
</>
);
}