39 lines
No EOL
1.1 KiB
TypeScript
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;
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
} |