Skip to content

Commit 64b2a8e

Browse files
committed
Avoid logging detailed/repeat interception setup data
1 parent a137438 commit 64b2a8e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/metrics.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,26 @@ const normalizeUrl = (url: string) =>
8383
.replace(/\/mock\/[a-z0-9\-]+/, '/mock') // Strip mock rule ids
8484
.replace(/\?.*/, ''); // Strip any query & hash params
8585

86+
const SINGLE_EVENT_CATEGORIES = ["Interceptors"];
87+
const seenLimitedEvents: string[] = [];
88+
8689
export function trackEvent(event: {
8790
category: string,
8891
action: string,
8992
value?: string
9093
}) {
9194
if (!enabled) return;
9295

96+
if (SINGLE_EVENT_CATEGORIES.includes(event.category)) {
97+
const eventKey = `${event.category}${event.action}${event.value}`;
98+
99+
// For events in these categories, we only want to log them once
100+
// per session. No need to track more detail than that, good to
101+
// avoid tracking unnecessary data where possible.
102+
if (seenLimitedEvents.includes(eventKey)) return;
103+
else seenLimitedEvents.push(eventKey);
104+
}
105+
93106
const currentUrl = normalizeUrl(location.href);
94107

95108
posthog.capture(`${event.category}:${event.action}`, {

0 commit comments

Comments
 (0)