-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: include initial stable id in web analytics (#412)
* fix: include initial stable id in web analytics * chore: linter * chore: set user * chore: fix accidental default value * chore: edit fn name
- Loading branch information
1 parent
b6d1ad4
commit 17d7956
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
packages/combo/src/__tests__/WebAnalyticsInitialStableID.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import fetchMock from 'jest-fetch-mock'; | ||
|
||
import { StatsigClient, StatsigUser } from '@statsig/js-client'; | ||
import { | ||
StatsigAutoCapturePlugin, | ||
runStatsigAutoCapture, | ||
} from '@statsig/web-analytics'; | ||
|
||
describe('Plugin Stable ID Override Tests', () => { | ||
let client: StatsigClient; | ||
const user: StatsigUser = { | ||
userID: 'a-user', | ||
customIDs: { | ||
stableID: 'a-stable-id', | ||
}, | ||
}; | ||
beforeAll(() => { | ||
fetchMock.enableMocks(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await client.shutdown(); | ||
fetchMock.mockClear(); | ||
}); | ||
|
||
it('Run auto capture includes initial user stable Id', async () => { | ||
client = new StatsigClient('client-key', user); | ||
runStatsigAutoCapture(client); | ||
await client.initializeAsync(); | ||
|
||
const request = fetchMock.mock.calls[1]; | ||
const body = JSON.parse(String(request[1]?.body ?? '')) as any; | ||
expect(body.events).toHaveLength(1); | ||
|
||
const event = body.events[0]; | ||
expect(event.eventName).toEqual('auto_capture::page_view'); | ||
expect(event.user?.customIDs?.stableID).toEqual('a-stable-id'); | ||
expect(body?.statsigMetadata?.stableID).toEqual('a-stable-id'); | ||
}); | ||
|
||
it('Auto capture plugin includes initial user stable Id', async () => { | ||
client = new StatsigClient('client-key', user, { | ||
plugins: [new StatsigAutoCapturePlugin()], | ||
}); | ||
await client.initializeAsync(); | ||
|
||
const request = fetchMock.mock.calls[1]; | ||
const body = JSON.parse(String(request[1]?.body ?? '')) as any; | ||
expect(body.events).toHaveLength(1); | ||
|
||
const event = body.events[0]; | ||
expect(event.eventName).toEqual('auto_capture::page_view'); | ||
expect(event.user?.customIDs?.stableID).toEqual('a-stable-id'); | ||
expect(body?.statsigMetadata?.stableID).toEqual('a-stable-id'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters