Skip to content

Commit

Permalink
chore: remove attribution double check
Browse files Browse the repository at this point in the history
  • Loading branch information
williazz committed Sep 9, 2023
1 parent 9f0461c commit 133521c
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions src/plugins/event-plugins/WebVitalsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,46 @@ export class WebVitalsPlugin extends InternalPlugin {
}

handleLCP(metric: LCPMetricWithAttribution | Metric) {
const lcpEvent: LargestContentfulPaintEvent = {
const a = (metric as LCPMetricWithAttribution).attribution;
this.context?.record(LCP_EVENT_TYPE, {
version: '1.0.0',
value: metric.value
};
if ('attribution' in metric) {
const a = (metric as LCPMetricWithAttribution).attribution;
lcpEvent.attribution = {
value: metric.value,
attribution: {
element: a.element,
url: a.url,
timeToFirstByte: a.timeToFirstByte,
resourceLoadDelay: a.resourceLoadDelay,
resourceLoadTime: a.resourceLoadTime,
elementRenderDelay: a.elementRenderDelay
};
}
this.context?.record(LCP_EVENT_TYPE, lcpEvent);
}
} as LargestContentfulPaintEvent);
}

handleCLS(metric: CLSMetricWithAttribution | Metric) {
const clsEvent: CumulativeLayoutShiftEvent = {
const a = (metric as CLSMetricWithAttribution).attribution;
this.context?.record(CLS_EVENT_TYPE, {
version: '1.0.0',
value: metric.value
};
if ('attribution' in metric) {
const a = (metric as CLSMetricWithAttribution).attribution;
clsEvent.attribution = {
value: metric.value,
attribution: {
largestShiftTarget: a.largestShiftTarget,
largestShiftValue: a.largestShiftValue,
largestShiftTime: a.largestShiftTime,
loadState: a.loadState
};
}
this.context?.record(CLS_EVENT_TYPE, clsEvent);
}
} as CumulativeLayoutShiftEvent);
}

handleFID(metric: FIDMetricWithAttribution | Metric) {
const fidEvent: FirstInputDelayEvent = {
const a = (metric as FIDMetricWithAttribution).attribution;
this.context?.record(FID_EVENT_TYPE, {
version: '1.0.0',
value: metric.value
};
if ('attribution' in metric) {
const a = (metric as FIDMetricWithAttribution).attribution;
fidEvent.attribution = {
value: metric.value,
attribution: {
eventTarget: a.eventTarget,
eventType: a.eventType,
eventTime: a.eventTime,
loadState: a.loadState
};
}
this.context?.record(FID_EVENT_TYPE, fidEvent);
}
} as FirstInputDelayEvent);
}
}

0 comments on commit 133521c

Please sign in to comment.