MCPcopy Create free account
hub / github.com/dailydotdev/apps / useWebVitals

Function useWebVitals

packages/shared/src/hooks/useWebVitals.ts:6–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { useLogContext } from '../contexts/LogContext';
5
6export function useWebVitals(): void {
7 const { logEvent } = useLogContext();
8
9 const logMetric = useCallback(
10 (metric: Metric) => {
11 const { name, entries, id, ...rest } = metric;
12 logEvent({ event_name: name, extra: JSON.stringify(rest) });
13 },
14 [logEvent],
15 );
16
17 // Have to wait for document to load and ensure it's not run on SSR
18 useEffect(() => {
19 // We apply sampling rate of 10%
20 if (Math.random() < 0.1) {
21 onCLS(logMetric);
22 onFID(logMetric);
23 onLCP(logMetric);
24 onTTFB(logMetric);
25 onFCP(logMetric);
26 }
27 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
28 // eslint-disable-next-line react-hooks/exhaustive-deps
29 }, []);
30}

Callers 2

InternalAppFunction · 0.90
InternalAppFunction · 0.90

Calls 2

useLogContextFunction · 0.90
logEventFunction · 0.85

Tested by

no test coverage detected