in packages/sdk/src/trackers/webVitals.ts [52:73]
export function webVitals({
lcp = true,
inp = true,
cls = true,
ttfb = false,
}: WebVitalsOptions = {}): Trackable.Manager {
return controller => {
const handleMetric = ({ name, id, delta }: Metric) => {
// TODO consider this example https://www.npmjs.com/package/web-vitals#send-attribution-data. Should we have some metric event?
const metricKey = name.toLocaleLowerCase() as 'lcp' | 'inp' | 'cls' | 'ttfb';
const eventName = `web-vitals-${metricKey}` as const;
controller.track(eventName, {
metric_id: id,
metric_delta: delta,
});
};
if (lcp) onLCP(handleMetric);
if (inp) onINP(handleMetric);
if (cls) onCLS(handleMetric);
if (ttfb) onTTFB(handleMetric);
};
}