fix: include sw metric with web vitals (#6646)

This commit is contained in:
Zach Pomerantz 2023-05-25 10:12:20 -07:00 committed by GitHub
parent d23b6e5da6
commit 4446eb9b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -170,13 +170,16 @@ export default function App() {
const isServiceWorkerHit = Boolean((window as any).__isDocumentCached) const isServiceWorkerHit = Boolean((window as any).__isDocumentCached)
const serviceWorkerProperty = isServiceWorkerInstalled ? (isServiceWorkerHit ? 'hit' : 'miss') : 'uninstalled' const serviceWorkerProperty = isServiceWorkerInstalled ? (isServiceWorkerHit ? 'hit' : 'miss') : 'uninstalled'
sendAnalyticsEvent(SharedEventName.APP_LOADED, { service_worker: serviceWorkerProperty }) const pageLoadProperties = { service_worker: serviceWorkerProperty }
getCLS(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { cumulative_layout_shift: delta })) sendAnalyticsEvent(SharedEventName.APP_LOADED, pageLoadProperties)
getFCP(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { first_contentful_paint_ms: delta })) const sendWebVital =
getFID(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { first_input_delay_ms: delta })) (metric: string) =>
getLCP(({ delta }: Metric) => ({ delta }: Metric) =>
sendAnalyticsEvent(SharedEventName.WEB_VITALS, { largest_contentful_paint_ms: delta }) sendAnalyticsEvent(SharedEventName.WEB_VITALS, { ...pageLoadProperties, [metric]: delta })
) getCLS(sendWebVital('cumulative_layout_shift'))
getFCP(sendWebVital('first_contentful_paint_ms'))
getFID(sendWebVital('first_input_delay_ms'))
getLCP(sendWebVital('largest_contentful_paint_ms'))
}, []) }, [])
useEffect(() => { useEffect(() => {