Skip to content

Commit

Permalink
fid
Browse files Browse the repository at this point in the history
  • Loading branch information
SETHULAKSHMI-PM committed May 22, 2024
1 parent 87e79c7 commit c99ecd9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
30 changes: 15 additions & 15 deletions lib/webVitals.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow

// $FlowFixMe Flow doesn't find the file. Let's ignore this for now.
import {onCLS, onLCP, onFID, onINP} from 'web-vitals';
import {onFID} from 'web-vitals';
import type {PageLoadBeacon} from './types';
import {pageLoadStartTimestamp} from './timings';
import {reportCustomEvent} from './customEvents';
import vars from './vars';

interface Metric {
name: 'CLS' | 'FID' | 'LCP';
name: 'FID';

value: number;
id?: string;
Expand All @@ -31,26 +31,26 @@ function reportExtraMetrics(metric: Metric) {
}

export function addWebVitals(beacon: PageLoadBeacon) {
if (onLCP) {
onLCP(onMetric, true);
}
// if (onLCP) {
// onLCP(onMetric, true);
// }
if (onFID) {
onFID(onMetric, true);
}
if (onINP) {
onINP(onMetric, true);
}
if (onCLS) {
onCLS(onMetricWithoutRounding, true);
}
// if (onINP) {
// onINP(onMetric, true);
// }
// if (onCLS) {
// onCLS(onMetricWithoutRounding, true);
// }

function onMetric(metric: Metric) {
beacon['t_' + metric.name.toLocaleLowerCase()] = Math.round(metric.value);
reportExtraMetrics(metric);
}

function onMetricWithoutRounding(metric: Metric) {
beacon['t_' + metric.name.toLocaleLowerCase()] = metric.value;
reportExtraMetrics(metric);
}
// function onMetricWithoutRounding(metric: Metric) {
// beacon['t_' + metric.name.toLocaleLowerCase()] = metric.value;
// reportExtraMetrics(metric);
// }
}
50 changes: 25 additions & 25 deletions test/e2e/12_webvitalsAsCustomEvent/webvitalsAsCustomEvent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ describe('12_webvitalsAsCustomEvent', () => {
cexpect(beacon.ty).to.equal('pl');
});

expectOneMatching(beacons, beacon => {
cexpect(beacon.ty).to.equal('cus');
cexpect(beacon.ts).to.be.a('string');
cexpect(parseFloat(beacon.d)).to.be.above(3000);
cexpect(beacon.n).to.equal('instana-webvitals-LCP');
cexpect(beacon.l).to.be.a('string');
cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
});
// expectOneMatching(beacons, beacon => {
// cexpect(beacon.ty).to.equal('cus');
// cexpect(beacon.ts).to.be.a('string');
// cexpect(parseFloat(beacon.d)).to.be.above(3000);
// cexpect(beacon.n).to.equal('instana-webvitals-LCP');
// cexpect(beacon.l).to.be.a('string');
// cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });

expectOneMatching(beacons, beacon => {
cexpect(beacon.ty).to.equal('cus');
Expand All @@ -57,23 +57,23 @@ describe('12_webvitalsAsCustomEvent', () => {
cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
});

expectOneMatching(beacons, beacon => {
cexpect(beacon.ty).to.equal('cus');
cexpect(beacon.ts).to.be.a('string');
cexpect(beacon.n).to.equal('instana-webvitals-CLS');
cexpect(beacon.l).to.be.a('string');
cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
});
// expectOneMatching(beacons, beacon => {
// cexpect(beacon.ty).to.equal('cus');
// cexpect(beacon.ts).to.be.a('string');
// cexpect(beacon.n).to.equal('instana-webvitals-CLS');
// cexpect(beacon.l).to.be.a('string');
// cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });

expectOneMatching(beacons, beacon => {
cexpect(beacon.ty).to.equal('cus');
cexpect(beacon.ts).to.be.a('string');
cexpect(beacon.n).to.equal('instana-webvitals-INP');
cexpect(beacon.l).to.be.a('string');
cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
});
// expectOneMatching(beacons, beacon => {
// cexpect(beacon.ty).to.equal('cus');
// cexpect(beacon.ts).to.be.a('string');
// cexpect(beacon.n).to.equal('instana-webvitals-INP');
// cexpect(beacon.l).to.be.a('string');
// cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });
});
});
});
Expand Down

0 comments on commit c99ecd9

Please sign in to comment.