Skip to content

Commit 1d2a55d

Browse files
authored
Merge pull request #37 from oslabs-beta/jimmyTryWebMetric
Collaboration for adding our web metrics
2 parents 6cdb5a0 + d9368cf commit 1d2a55d

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
"redux-mock-store": "^1.5.4",
241241
"styled-components": "^6.0.4",
242242
"util": "^0.12.4",
243-
"web-vitals": "^1.1.0",
243+
"web-vitals": "^3.5.0",
244244
"yarn": "^1.22.19"
245245
}
246246
}

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const StateRoute = (props: StateRouteProps) => {
9292
let FCPColor: String;
9393
let TTFBColor: String;
9494
let CLSColor: String;
95+
let INPColor: String;
9596

9697
// adjust the strings that represent colors of the webmetrics performance bar for 'Largest Contentful Paint (LCP)', 'First Input Delay (FID)', 'First Contentfuly Paint (FCP)', and 'Time to First Byte (TTFB)' based on webMetrics outputs.
9798
if (webMetrics.LCP <= 2000) LCPColor = '#0bce6b';
@@ -108,6 +109,11 @@ const StateRoute = (props: StateRouteProps) => {
108109
if (webMetrics.CLS <= 0.1) TTFBColor = '#0bce6b';
109110
if (webMetrics.CLS > 0.1 && webMetrics.CLS <= 0.25) TTFBColor = '#E56543';
110111
if (webMetrics.CLS > 0.25) TTFBColor = '#fc2000';
112+
113+
//INP Stuff - Turns it red? change this to green
114+
if (webMetrics.INP <= 200) INPColor = '#0bce6b';
115+
if (webMetrics.INP <= 500) INPColor = '#E56543';
116+
if (webMetrics.INP > 500) INPColor = '#fc2000';
111117
console.log('WEBMETRICS YOOO', webMetrics);
112118

113119
return (
@@ -149,11 +155,19 @@ const StateRoute = (props: StateRouteProps) => {
149155
<WebMetrics
150156
color={CLSColor}
151157
series={webMetrics.CLS * 10}
152-
formatted={(val) => (Number.isNaN(val) ? 'CLS Score: N/A' : `CLS Score: ${val / 10}`)}
158+
formatted={(val) => `CLS Score: ${(Number.isNaN(val) ? 'N/A' : `${(val / 10).toFixed(3)}`)}`}
153159
label='Cumulative Layout Shift'
154160
name='Cumulative Layout Shift'
155161
description='Calculates the shifting of elements while the page is being downloaded and rendered.'
156162
/>
163+
<WebMetrics
164+
color={INPColor}
165+
series={(webMetrics.INP / 10) * 100}
166+
formatted={(val) => `INP Value: ${(Number.isNaN(val) ? 'N/A' : `${val / 10}`)}`}
167+
label='Interaction to Next Paint'
168+
name='Interaction to Next Paint'
169+
description={`Assesses a page's overall responsiveness to user interactions by observing the latency of all click, tap, and keyboard interactions that occur throughout the lifespan of a user's visit to a page`}
170+
/>
157171
</div>
158172
);
159173
};

src/app/styles/layout/_stateContainer.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
.web-metrics-container {
192192
display: grid;
193193
grid-template-columns: auto auto;
194-
align-items: center;
195194
justify-content: center;
196195
}
197196

src/extension/contentScript.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Web vital metrics calculated by 'web-vitals' npm package to be displayed
22
// in Web Metrics tab of Reactime app.
3-
import { getTTFB, getLCP, getFID, getFCP, getCLS } from 'web-vitals';
3+
import { onTTFB, onLCP, onFID, onFCP, onCLS, onINP } from 'web-vitals';
44

55
// Reactime application starts off with this file, and will send
66
// first message to background.js for initial tabs object set up.
@@ -74,11 +74,13 @@ const gatherMetrics = ({ name, value }) => {
7474
};
7575

7676
// Functions that calculate web metric values.
77-
getTTFB(gatherMetrics);
78-
getLCP(gatherMetrics);
79-
getFID(gatherMetrics);
80-
getFCP(gatherMetrics);
81-
getCLS(gatherMetrics);
77+
onTTFB(gatherMetrics);
78+
onLCP(gatherMetrics);
79+
onFID(gatherMetrics);
80+
onFCP(gatherMetrics);
81+
onCLS(gatherMetrics);
82+
onINP(gatherMetrics);
83+
8284

8385
// Send message to background.js for injecting the initial script
8486
// into the app's DOM.

0 commit comments

Comments
 (0)