Files
thrilltrack-explorer/src/components/analytics/AnalyticsWrapper.tsx
gpt-engineer-app[bot] 2468d3cc18 Enable admin-only stats and update subscriptions
Implement plan to fix database RPCs by migrating to photos table, update hooks to enable only on admin pages, switch real-time subscriptions to the photos table, and apply to remaining forms. Also disable analytics in development.
2025-11-11 23:49:56 +00:00

43 lines
982 B
TypeScript

import { Analytics } from "@vercel/analytics/react";
import { Component, ReactNode } from "react";
import { logger } from "@/lib/logger";
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
logger.info('Analytics failed to load, continuing without analytics', { error: error.message });
}
render() {
if (this.state.hasError) {
return null;
}
return this.props.children;
}
}
export function AnalyticsWrapper() {
// Disable analytics in development to reduce console noise
if (import.meta.env.DEV) {
return null;
}
return (
<AnalyticsErrorBoundary>
<Analytics />
</AnalyticsErrorBoundary>
);
}