UNPKG

umami-analytics-react

Version:

React hooks (useUmami, useUmamiView) and UmamiProvider for seamless Umami analytics integration, supporting page views, custom event tracking, and session identification.

24 lines (23 loc) 996 B
export function generateEnhancedIdentity(keyList, defaultValue = "unknown") { const isArray = Array.isArray(keyList); if (isArray && keyList.length === 0) { return {}; } const matchMedia = (query) => window.matchMedia(query).matches; const allValues = { timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, timezoneOffset: -new Date().getTimezoneOffset(), ect: navigator.connection?.effectiveType || defaultValue, systemTheme: matchMedia("(prefers-color-scheme: dark)") ? "dark" : "light", prefersReducedMotion: matchMedia("(prefers-reduced-motion: reduce)"), isTouchDevice: "ontouchstart" in window || navigator.maxTouchPoints > 0 || matchMedia("(pointer: coarse)"), zoomLevel: Math.round(window.outerWidth / window.innerWidth * 100) }; if (!isArray) { return allValues; } return keyList.reduce((acc, key) => { acc[key] = allValues[key]; return acc; }, {}); }