feat: Add analytics error handling

This commit is contained in:
gpt-engineer-app[bot]
2025-11-02 18:40:23 +00:00
parent 6d68427f5b
commit 7435aa8746
3 changed files with 42 additions and 2 deletions

View 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>
);
}