diff --git a/src/App.tsx b/src/App.tsx index 8f1751fe..932fe13a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,7 @@ import { BrowserRouter, Routes, Route } from "react-router-dom"; import { AuthProvider } from "@/hooks/useAuth"; import { AuthModalProvider } from "@/contexts/AuthModalContext"; import { LocationAutoDetectProvider } from "@/components/providers/LocationAutoDetectProvider"; -import { Analytics } from "@vercel/analytics/react"; +import { AnalyticsWrapper } from "@/components/analytics/AnalyticsWrapper"; import { Footer } from "@/components/layout/Footer"; import { PageLoader } from "@/components/loading/PageSkeletons"; @@ -162,7 +162,7 @@ const App = (): React.JSX.Element => ( {import.meta.env.DEV && } - + ); diff --git a/src/components/analytics/AnalyticsWrapper.tsx b/src/components/analytics/AnalyticsWrapper.tsx new file mode 100644 index 00000000..698f1f16 --- /dev/null +++ b/src/components/analytics/AnalyticsWrapper.tsx @@ -0,0 +1,36 @@ +import { Analytics } from "@vercel/analytics/react"; +import { Component, ReactNode } from "react"; + +class AnalyticsErrorBoundary extends Component< + { children: ReactNode }, + { hasError: boolean } +> { + constructor(props: { children: ReactNode }) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError() { + return { hasError: true }; + } + + componentDidCatch(error: Error) { + // Silently fail - analytics should never break the app + console.info('[Analytics] Failed to load, continuing without analytics'); + } + + render() { + if (this.state.hasError) { + return null; + } + return this.props.children; + } +} + +export function AnalyticsWrapper() { + return ( + + + + ); +} diff --git a/vercel.json b/vercel.json index 157bb1e8..cd80b850 100644 --- a/vercel.json +++ b/vercel.json @@ -26,6 +26,10 @@ { "key": "X-XSS-Protection", "value": "1; mode=block" + }, + { + "key": "Permissions-Policy", + "value": "browsing-topics=(), interest-cohort=()" } ] },