-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: deduplicate subsequent identify calls (#1649)
* feat: deduplicate identify calls * chore: cache identify on first call * chore: pull hash fn off the class, add logging
- Loading branch information
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -208,6 +208,22 @@ describe('identify()', () => { | |
) | ||
expect(instance.featureFlags.setAnonymousDistinctId).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('does not call $set when duplicate properties are passed', () => { | ||
instance.identify('a-new-id', { email: '[email protected]' }, { howOftenAmISet: 'once!' }) | ||
instance.identify('a-new-id', { email: '[email protected]' }, { howOftenAmISet: 'once!' }) | ||
|
||
expect(beforeSendMock).toHaveBeenCalledTimes(1) | ||
expect(instance.featureFlags.setAnonymousDistinctId).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('calls $set when different properties are passed with the same distinct_id', () => { | ||
instance.identify('a-new-id', { email: '[email protected]' }, { howOftenAmISet: 'once!' }) | ||
instance.identify('a-new-id', { email: '[email protected]' }, { howOftenAmISet: 'twice!' }) | ||
|
||
expect(beforeSendMock).toHaveBeenCalledTimes(2) | ||
expect(instance.featureFlags.setAnonymousDistinctId).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('invalid id passed', () => { | ||
|
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
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,10 @@ | ||
import { jsonStringify } from '../request' | ||
import type { Properties } from '../types' | ||
|
||
export function getIdentifyHash( | ||
distinct_id: string, | ||
userPropertiesToSet?: Properties, | ||
userPropertiesToSetOnce?: Properties | ||
): string { | ||
return jsonStringify({ distinct_id, userPropertiesToSet, userPropertiesToSetOnce }) | ||
} |