Commit 4446eb9b authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

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

parent d23b6e5d
...@@ -170,13 +170,16 @@ export default function App() { ...@@ -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(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment