11import { Batch } from "../transport/batch" ;
22import { BrowserClientConfigType } from "../types/client" ;
33import { BrowserPerformanceType , LargestContentfulPaint , LayoutShift , ObserverType } from "../types/performance" ;
4- import { CAPTURE_ENDPOINT } from "../types/transport" ;
4+ import { BatchPayload , CAPTURE_ENDPOINT } from "../types/transport" ;
55import { utils } from "../utils" ;
66
77export class Performance {
@@ -22,6 +22,18 @@ export class Performance {
2222 this . handlePaintEntry ( ) ;
2323 }
2424
25+ // overrride to this.batch.add which inlcude some necessary data for each perfs
26+ public addToBatch ( payload : BatchPayload ) : void {
27+ const pathname = utils . pathname ( ) ;
28+
29+ const batchPayload : BatchPayload = {
30+ view : pathname ,
31+ ...payload
32+ } ;
33+
34+ this . batch . add ( batchPayload ) ;
35+ }
36+
2537 // https://developer.mozilla.org/en-US/docs/Web/API/PerformancePaintTiming
2638 // first-paint, first-contentful-paint
2739 private handlePaintEntry ( ) {
@@ -44,7 +56,7 @@ export class Performance {
4456 } ]
4557 } ;
4658
47- this . batch . add ( payload ) ;
59+ this . addToBatch ( payload ) ;
4860 }
4961 }
5062
@@ -69,7 +81,7 @@ export class Performance {
6981 name : "LCP"
7082 } ]
7183 } ;
72- this . batch . add ( payload ) ;
84+ this . addToBatch ( payload ) ;
7385 }
7486 this . observe < LargestContentfulPaint > ( "largest-contentful-paint" , handle ) ;
7587 }
@@ -97,7 +109,7 @@ export class Performance {
97109 value : entry . value
98110 } ]
99111 }
100- this . batch . add ( payload ) ;
112+ this . addToBatch ( payload ) ;
101113 }
102114
103115 }
@@ -118,7 +130,7 @@ export class Performance {
118130 value : entry . processingStart - entry . startTime
119131 } ]
120132 } ;
121- this . batch . add ( payload ) ;
133+ this . addToBatch ( payload ) ;
122134 }
123135 }
124136 this . observe < PerformanceEventTiming > ( "first-input" , handle ) ;
@@ -155,7 +167,7 @@ export class Performance {
155167 ]
156168 } ;
157169
158- this . batch . add ( payload ) ;
170+ this . addToBatch ( payload ) ;
159171 }
160172 } ;
161173
0 commit comments