Skip to content

Commit 23baab4

Browse files
alanjcharlesAlan Charles
and
Alan Charles
authored
feat: add anonymousId logic to reset (#475)
* feat: add anonymousId logic to reset * refactor: add Oscar's changes Co-authored-by: Alan Charles <[email protected]>
1 parent 02167e0 commit 23baab4

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

packages/core/src/__tests__/analytics.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ describe('SegmentClient', () => {
119119
});
120120

121121
describe('#reset', () => {
122+
it('resets all userInfo except anonymousId', () => {
123+
client = new SegmentClient(clientArgs);
124+
const setUserInfo = jest.spyOn(store.userInfo, 'set');
125+
126+
client.reset(false);
127+
128+
expect(setUserInfo).toHaveBeenCalledWith({
129+
anonymousId: 'anonymousId',
130+
userId: undefined,
131+
traits: undefined,
132+
});
133+
});
134+
122135
it('resets user data, identity, traits', () => {
123136
client = new SegmentClient(clientArgs);
124137
const setUserInfo = jest.spyOn(store.userInfo, 'set');

packages/core/src/analytics.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,18 @@ export class SegmentClient {
651651
this.appState = nextAppState;
652652
}
653653

654-
reset() {
654+
reset(resetAnonymousId: boolean = true) {
655+
const anonymousId =
656+
resetAnonymousId === true
657+
? getUUID()
658+
: this.store.userInfo.get().anonymousId;
659+
655660
this.store.userInfo.set({
656-
anonymousId: getUUID(),
661+
anonymousId,
657662
userId: undefined,
658663
traits: undefined,
659664
});
665+
660666
this.logger.info('Client has been reset');
661667
}
662668
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,10 +2113,10 @@
21132113
conventional-recommended-bump "^6.1.0"
21142114
prepend-file "^2.0.0"
21152115

2116-
"@segment/sovran-react-native@^0.2.4":
2117-
version "0.2.4"
2118-
resolved "https://registry.yarnpkg.com/@segment/sovran-react-native/-/sovran-react-native-0.2.4.tgz#8f73ba41febf8cb2f711a0d15d38a79384b0b767"
2119-
integrity sha512-+r98+pDMUQj8Siw4gG3KRSH7pIt4Q6omu4vwBfT0oBRpZ0dsSz6a17xTlEZkUU3ytgDj1c/fmJQg6V8tLgkbWw==
2116+
"@segment/sovran-react-native@^0.2.6":
2117+
version "0.2.6"
2118+
resolved "https://registry.yarnpkg.com/@segment/sovran-react-native/-/sovran-react-native-0.2.6.tgz#895ef37b71c299f56c89515cf8d200f13fce2251"
2119+
integrity sha512-SxqKvMvgu9PZo0jSkZ0yys08H9qJbI1uGbaeBvJFZfs92TIvQmcW0PYQZsspqt85RPzrL4J9KDio6xoLXmHurw==
21202120
dependencies:
21212121
"@react-native-async-storage/async-storage" "^1.15.15"
21222122
ansi-regex "5.0.1"

0 commit comments

Comments
 (0)