Skip to content

Commit

Permalink
ref: Update Amplitude page view sanitization (#3739)
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov authored Feb 14, 2025
1 parent 594a732 commit dd109a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/services/events/amplitude/amplitude.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ describe('pageViewTrackingSanitization', () => {
event_properties: {
'[Amplitude] Page Counter': 1,
'[Amplitude] Page Domain': 'app.codecov.io',
'[Amplitude] Page Title': 'Codecov',
'[Amplitude] Page Path': '/sensitive/info',
'[Amplitude] Page Location': 'https://app.codecov.io/sensitive/info',
'[Amplitude] Page URL': 'https://app.codecov.io/sensitive/info',
},
} as Event)
expect(event?.event_properties).toMatchObject({
'[Amplitude] Page Counter': 1,
'[Amplitude] Page Domain': 'app.codecov.io',
'[Amplitude] Page Title': 'Codecov',
path: undefined,
})
}
Expand Down
16 changes: 9 additions & 7 deletions src/services/events/amplitude/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export const pageViewTrackingSanitization = (): EnrichmentPlugin => {
type: 'enrichment',
setup: async () => undefined,
execute: async (event) => {
/* eslint-disable camelcase */
if (event.event_type === '[Amplitude] Page Viewed') {
/* eslint-disable camelcase */
event.event_properties = {
'[Amplitude] Page Counter':
event.event_properties?.['[Amplitude] Page Counter'],
'[Amplitude] Page Domain':
event.event_properties?.['[Amplitude] Page Domain'],
path: eventTracker().context.path,
if (event.event_properties) {
// Remove any information containing names and/or ids.
delete event.event_properties['[Amplitude] Page Location'] // location.href
delete event.event_properties['[Amplitude] Page Path'] // Full path of current page
delete event.event_properties['[Amplitude] Page URL'] // Full URL of current page
delete event.event_properties.referrer // Full URL of previous page

event.event_properties.path = eventTracker().context.path // Add the React path match
}
}

Expand Down

0 comments on commit dd109a6

Please sign in to comment.