()
| 5 | import { useEffect } from "react"; |
| 6 | |
| 7 | export default function PageTracker() { |
| 8 | const pathname = usePathname(); |
| 9 | |
| 10 | // Track page views |
| 11 | useEffect(() => { |
| 12 | const normalized = normalizedPathname(pathname); |
| 13 | |
| 14 | sendAnalyticEvents([ |
| 15 | { |
| 16 | name: "page_view", |
| 17 | data: { |
| 18 | path: normalized, |
| 19 | full_path: pathname === normalized ? undefined : pathname, |
| 20 | }, |
| 21 | }, |
| 22 | ]); |
| 23 | }, [pathname]); |
| 24 | |
| 25 | // Track unhandle rejection |
| 26 | useEffect(() => { |
| 27 | if (typeof window === "undefined") return; |
| 28 | |
| 29 | const handler = (event: PromiseRejectionEvent) => { |
| 30 | if (typeof event.reason === "string") { |
| 31 | sendAnalyticEvents([ |
| 32 | { |
| 33 | name: "unhandledrejection", |
| 34 | data: { message: event.reason, path: window.location.pathname }, |
| 35 | }, |
| 36 | ]); |
| 37 | } else if (event.reason?.message) { |
| 38 | sendAnalyticEvents([ |
| 39 | { |
| 40 | name: "unhandledrejection", |
| 41 | data: { |
| 42 | message: event.reason.message, |
| 43 | stack: event.reason.stack, |
| 44 | path: window.location.pathname, |
| 45 | }, |
| 46 | }, |
| 47 | ]); |
| 48 | } else { |
| 49 | sendAnalyticEvents([ |
| 50 | { |
| 51 | name: "unhandledrejection", |
| 52 | data: { |
| 53 | message: event.toString(), |
| 54 | }, |
| 55 | }, |
| 56 | ]); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | window.addEventListener("unhandledrejection", handler); |
| 61 | |
| 62 | return () => { |
| 63 | window.removeEventListener("unhandledrejection", handler); |
| 64 | }; |
nothing calls this directly
no test coverage detected