Fix: guard Umami tracking and web vitals performance APIs

Avoid calling undefined umami.track, add safe checks for Performance APIs, and clean up load listeners to prevent .call() crashes in Chrome.
This commit is contained in:
Cursor Agent
2026-01-14 02:09:22 +00:00
parent ba99889782
commit abfb710c4b
3 changed files with 26 additions and 4 deletions

View File

@@ -25,12 +25,21 @@ export interface WebVitalsMetric {
// Track custom events to Umami
export const trackEvent = (event: string, data?: Record<string, unknown>) => {
if (typeof window !== 'undefined' && window.umami) {
window.umami.track(event, {
if (typeof window === "undefined") return;
const trackFn = window.umami?.track;
if (typeof trackFn !== "function") return;
try {
trackFn(event, {
...data,
timestamp: Date.now(),
url: window.location.pathname,
});
} catch (error) {
// Silently fail - analytics must never break the app
if (process.env.NODE_ENV === "development") {
console.warn("Error tracking Umami event:", error);
}
}
};