Skip to content

Commit 2c0b783

Browse files
feat/saving current view to events and perfs data
1 parent f81190d commit 2c0b783

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

packages/browser/src/performance/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Batch } from "../transport/batch";
22
import { BrowserClientConfigType } from "../types/client";
33
import { BrowserPerformanceType, LargestContentfulPaint, LayoutShift, ObserverType } from "../types/performance";
4-
import { CAPTURE_ENDPOINT } from "../types/transport";
4+
import { BatchPayload, CAPTURE_ENDPOINT } from "../types/transport";
55
import { utils } from "../utils";
66

77
export 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

packages/browser/src/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const browserDetails = (): BrowserInfoType => {
99
const engine = bowser.getEngine();
1010
const platform = bowser.getPlatform();
1111
const os = bowser.getOS();
12-
const url = window.location.href;
12+
const url = window.location.pathname;
1313

1414
return {
1515
browser,
@@ -42,9 +42,14 @@ const currentUnix = (): number => {
4242
return Math.floor(Date.now() / 1000);
4343
}
4444

45+
const pathname = () => {
46+
return window.location.pathname;
47+
}
48+
4549
export const utils = {
4650
browserDetails,
4751
getGlobalConfigs,
4852
toBytes,
49-
currentUnix
53+
currentUnix,
54+
pathname
5055
};

0 commit comments

Comments
 (0)