mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:11:17 -05:00
feat: Add analytics error handling
This commit is contained in:
@@ -9,7 +9,7 @@ import { BrowserRouter, Routes, Route } from "react-router-dom";
|
|||||||
import { AuthProvider } from "@/hooks/useAuth";
|
import { AuthProvider } from "@/hooks/useAuth";
|
||||||
import { AuthModalProvider } from "@/contexts/AuthModalContext";
|
import { AuthModalProvider } from "@/contexts/AuthModalContext";
|
||||||
import { LocationAutoDetectProvider } from "@/components/providers/LocationAutoDetectProvider";
|
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 { Footer } from "@/components/layout/Footer";
|
||||||
import { PageLoader } from "@/components/loading/PageSkeletons";
|
import { PageLoader } from "@/components/loading/PageSkeletons";
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ const App = (): React.JSX.Element => (
|
|||||||
</AuthModalProvider>
|
</AuthModalProvider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
{import.meta.env.DEV && <ReactQueryDevtools initialIsOpen={false} position="bottom" />}
|
{import.meta.env.DEV && <ReactQueryDevtools initialIsOpen={false} position="bottom" />}
|
||||||
<Analytics />
|
<AnalyticsWrapper />
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
36
src/components/analytics/AnalyticsWrapper.tsx
Normal file
36
src/components/analytics/AnalyticsWrapper.tsx
Normal file
@@ -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 (
|
||||||
|
<AnalyticsErrorBoundary>
|
||||||
|
<Analytics />
|
||||||
|
</AnalyticsErrorBoundary>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -26,6 +26,10 @@
|
|||||||
{
|
{
|
||||||
"key": "X-XSS-Protection",
|
"key": "X-XSS-Protection",
|
||||||
"value": "1; mode=block"
|
"value": "1; mode=block"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Permissions-Policy",
|
||||||
|
"value": "browsing-topics=(), interest-cohort=()"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user