Skip to content

Commit c393166

Browse files
committed
Tighten analytics route labels
1 parent 7683833 commit c393166

4 files changed

Lines changed: 69 additions & 6 deletions

File tree

src/hooks/useCompetitionAnalytics/useCompetitionAnalytics.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,22 @@ describe('useCompetitionAnalytics', () => {
5757
user_id: undefined,
5858
});
5959
});
60+
61+
it.each([
62+
['/competitions/ExampleComp2026/activities', 'schedule'],
63+
['/competitions/ExampleComp2026/activities/1', 'schedule_activity'],
64+
['/competitions/ExampleComp2026/rooms', 'schedule_rooms'],
65+
['/competitions/ExampleComp2026/rooms/main', 'schedule_room'],
66+
])('tracks schedule views for %s', (initialEntry, page) => {
67+
renderHook(() => useCompetitionAnalytics('ExampleComp2026'), {
68+
wrapper: wrapper(initialEntry),
69+
});
70+
71+
expect(trackCompetitionEvent).toHaveBeenCalledWith('schedule_viewed', {
72+
competition_id: 'ExampleComp2026',
73+
page,
74+
feature: undefined,
75+
user_id: undefined,
76+
});
77+
});
6078
});

src/hooks/useCompetitionAnalytics/useCompetitionAnalytics.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const featureViewEventName = (page: string) => {
1010
return 'groups_viewed';
1111
}
1212

13-
if (page === 'schedule' || page === 'schedule_activity') {
13+
if (
14+
page === 'schedule' ||
15+
page === 'schedule_activity' ||
16+
page === 'schedule_rooms' ||
17+
page === 'schedule_room'
18+
) {
1419
return 'schedule_viewed';
1520
}
1621

src/lib/analyticsPages.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ describe('analyticsPages', () => {
1818
expect(competitionPageName(pathname, 'ExampleComp2026')).toBe(page);
1919
});
2020

21-
it('uses stable labels for unknown competition routes', () => {
21+
it('uses stable coarse labels for unknown competition routes', () => {
2222
expect(
23-
competitionPageName('/competitions/ExampleComp2026/custom/report', 'ExampleComp2026'),
24-
).toBe('custom_report');
23+
competitionPageName(
24+
'/competitions/ExampleComp2026/custom/potentially-sensitive-value',
25+
'ExampleComp2026',
26+
),
27+
).toBe('other');
28+
});
29+
30+
it('uses stable coarse labels for unknown admin routes', () => {
31+
expect(
32+
competitionPageName(
33+
'/competitions/ExampleComp2026/admin/potentially-sensitive-value',
34+
'ExampleComp2026',
35+
),
36+
).toBe('admin_other');
2537
});
2638
});

src/lib/analyticsPages.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,23 @@ export const competitionPageName = (pathname: string, competitionId: string) =>
5656
return 'live_activities';
5757
}
5858

59+
if (second === 'webhooks') {
60+
return 'webhooks';
61+
}
62+
5963
if (second === 'scramblers') {
6064
return 'assignments';
6165
}
6266

63-
return second ? sanitizePageName(second) : 'admin';
67+
if (second === 'stats') {
68+
return 'stats';
69+
}
70+
71+
if (second === 'sum-of-ranks') {
72+
return 'sum_of_ranks';
73+
}
74+
75+
return second ? 'admin_other' : 'admin';
6476
}
6577

6678
if (section === 'remote' || section === 'live') {
@@ -83,5 +95,21 @@ export const competitionPageName = (pathname: string, competitionId: string) =>
8395
return 'sum_of_ranks';
8496
}
8597

86-
return sanitizePageName(segments.join('_')) || 'competition';
98+
if (section === 'stream') {
99+
return 'stream';
100+
}
101+
102+
if (section === 'information') {
103+
return 'information';
104+
}
105+
106+
if (section === 'explore') {
107+
return 'explore';
108+
}
109+
110+
if (section === 'groups-schedule') {
111+
return 'groups_schedule';
112+
}
113+
114+
return 'other';
87115
};

0 commit comments

Comments
 (0)