|
| 1 | +import { Config, CoreClient, Event } from '@amplitude/analytics-types' |
| 2 | + |
1 | 3 | import config from 'config'
|
2 | 4 |
|
3 |
| -import { AmplitudeEventTracker, initAmplitude } from './amplitude' |
| 5 | +import { |
| 6 | + AmplitudeEventTracker, |
| 7 | + initAmplitude, |
| 8 | + pageViewTrackingSanitization, |
| 9 | +} from './amplitude' |
4 | 10 |
|
5 | 11 | const mockIdentifySet = vi.hoisted(() => vi.fn())
|
6 | 12 | const mockIdentifyConstructor = vi.hoisted(() => vi.fn())
|
@@ -53,6 +59,53 @@ describe('when initAmplitude is called', () => {
|
53 | 59 | })
|
54 | 60 | })
|
55 | 61 |
|
| 62 | +describe('pageViewTrackingSanitization', () => { |
| 63 | + it('removes sensitive info from Page Viewed event properties', async () => { |
| 64 | + const plugin = pageViewTrackingSanitization() |
| 65 | + |
| 66 | + if (plugin.setup) { |
| 67 | + plugin?.setup({} as Config, {} as CoreClient) |
| 68 | + } |
| 69 | + |
| 70 | + if (plugin.execute) { |
| 71 | + const event = await plugin.execute({ |
| 72 | + event_type: '[Amplitude] Page Viewed', |
| 73 | + event_properties: { |
| 74 | + '[Amplitude] Page Counter': 1, |
| 75 | + '[Amplitude] Page Domain': 'app.codecov.io', |
| 76 | + '[Amplitude] Page Path': '/sensitive/info', |
| 77 | + '[Amplitude] Page Location': 'https://app.codecov.io/sensitive/info', |
| 78 | + }, |
| 79 | + } as Event) |
| 80 | + expect(event?.event_properties).toMatchObject({ |
| 81 | + '[Amplitude] Page Counter': 1, |
| 82 | + '[Amplitude] Page Domain': 'app.codecov.io', |
| 83 | + path: undefined, |
| 84 | + }) |
| 85 | + } |
| 86 | + }) |
| 87 | + |
| 88 | + it('does not touch other event types', async () => { |
| 89 | + const plugin = pageViewTrackingSanitization() |
| 90 | + |
| 91 | + if (plugin.setup) { |
| 92 | + plugin?.setup({} as Config, {} as CoreClient) |
| 93 | + } |
| 94 | + |
| 95 | + if (plugin.execute) { |
| 96 | + const event = await plugin.execute({ |
| 97 | + event_type: 'Button Clicked', |
| 98 | + event_properties: { |
| 99 | + '[Amplitude] Page Path': '/sensitive/info', |
| 100 | + }, |
| 101 | + } as Event) |
| 102 | + expect(event?.event_properties).toMatchObject({ |
| 103 | + '[Amplitude] Page Path': '/sensitive/info', |
| 104 | + }) |
| 105 | + } |
| 106 | + }) |
| 107 | +}) |
| 108 | + |
56 | 109 | describe('AmplitudeEventTracker', () => {
|
57 | 110 | describe('identify', () => {
|
58 | 111 | describe('when identify is called', () => {
|
|
0 commit comments