Skip to content

Commit 9a2d78c

Browse files
committed
log web vitals in dev
1 parent 81a19a6 commit 9a2d78c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

frontend/src/index.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ const getEventValueFromMetric = (metric: Metric) => {
3030
}
3131
return Math.round(metric.value)
3232
}
33-
33+
3434
const reportHandler = (metric: Metric) => {
35-
ReactGA.event({
35+
const event = {
3636
category: 'Web Vitals',
3737
action: metric.name,
3838
value: getEventValueFromMetric(metric),
3939
label: metric.id,
4040
nonInteraction: true
41-
})
41+
}
42+
43+
if (process.env.NODE_ENV && process.env.NODE_ENV === 'development') {
44+
console.log(`[web-vitals-dev] ${metric.name}: ${metric.id}`, metric) // eslint-disable-line no-console
45+
} else {
46+
ReactGA.event(event)
47+
}
4248
}
4349

44-
// If you want to start measuring performance in your app, pass a function
45-
// to log results (for example: reportWebVitals(console.log))
46-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
4750
reportWebVitals(reportHandler)

0 commit comments

Comments
 (0)