toast-errors.tsx 632 B

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