toast-errors.tsx25 lines · main
| 1 | import { useEffect, useRef } from 'react' |
| 2 | import { useSonner } from 'sonner' |
| 3 | |
| 4 | import { useTrack } from '@/lib/telemetry/track' |
| 5 | |
| 6 | export const ToastErrorTracker = () => { |
| 7 | const track = useTrack() |
| 8 | const { toasts } = useSonner() |
| 9 | const trackRef = useRef(new Set<string | number>()) |
| 10 | |
| 11 | useEffect(() => { |
| 12 | toasts.forEach((toast) => { |
| 13 | if (toast.type === 'error' && !trackRef.current.has(toast.id)) { |
| 14 | trackRef.current.add(toast.id) |
| 15 | if (Math.random() < 0.1) { |
| 16 | track('dashboard_error_created', { |
| 17 | source: 'toast', |
| 18 | }) |
| 19 | } |
| 20 | } |
| 21 | }) |
| 22 | }, [toasts, track]) |
| 23 | |
| 24 | return null |
| 25 | } |