-
Notifications
You must be signed in to change notification settings - Fork 0
Rename visitorId to anonymousId #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,9 +9,9 @@ import { | |
| } from '../../../test-utils/networkMode'; | ||
| import { | ||
| EVENT_PAGEVIEW, | ||
| PREFIX_ANONYMOUS_ID, | ||
| PREFIX_DEVICE_ID, | ||
| PREFIX_SESSION_ID, | ||
| PREFIX_VISITOR_ID, | ||
| PROPERTY_LIB, | ||
| PROPERTY_LIB_VERSION, | ||
| PROPERTY_REFERER, | ||
|
|
@@ -28,11 +28,11 @@ import { UserId, UserTraits } from '../src/types'; | |
| const REGEXP_DATE_ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; | ||
| const REGEXP_SESSION_ID = new RegExp(`^${PREFIX_SESSION_ID}-`); | ||
| const REGEXP_DEVICE_ID = new RegExp(`^${PREFIX_DEVICE_ID}-`); | ||
| const REGEXP_VISITOR_ID = new RegExp(`^${PREFIX_VISITOR_ID}-`); | ||
| const REGEXP_ANONYMOUS_ID = new RegExp(`^${PREFIX_ANONYMOUS_ID}-`); | ||
|
|
||
| function createSessionData(overrides: Record<string, any> = {}) { | ||
| return JSON.stringify({ | ||
| distinctId: 'visitor-test-uuid-1-1234567890', | ||
| distinctId: 'anonymous-test-uuid-1-1234567890', | ||
| anonymousId: null, | ||
| sessionId: 'session-test-uuid-2-1234567890', | ||
| deviceId: 'device-test-uuid-3-1234567890', | ||
|
|
@@ -134,7 +134,7 @@ describe('Altertable', () => { | |
| event: EVENT_PAGEVIEW, | ||
| timestamp: expect.stringMatching(REGEXP_DATE_ISO), | ||
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| anonymous_id: null, | ||
| session_id: expect.stringMatching(REGEXP_SESSION_ID), | ||
| environment: 'production', | ||
|
|
@@ -165,7 +165,7 @@ describe('Altertable', () => { | |
| payload: { | ||
| event: 'eventName', | ||
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| timestamp: expect.stringMatching(REGEXP_DATE_ISO), | ||
| anonymous_id: null, | ||
| session_id: expect.stringMatching(REGEXP_SESSION_ID), | ||
|
|
@@ -611,7 +611,7 @@ describe('Altertable', () => { | |
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| traits: {}, | ||
| distinct_id: userId, | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
@@ -629,7 +629,7 @@ describe('Altertable', () => { | |
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| traits, | ||
| distinct_id: userId, | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
@@ -747,7 +747,7 @@ describe('Altertable', () => { | |
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| traits: { email: '[email protected]' }, | ||
| distinct_id: userId, | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| }, | ||
| }); | ||
|
|
||
|
|
@@ -759,7 +759,7 @@ describe('Altertable', () => { | |
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| traits: { email: '[email protected]' }, | ||
| distinct_id: userId, | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
@@ -799,7 +799,7 @@ describe('Altertable', () => { | |
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| traits: newTraits, | ||
| distinct_id: 'user123', | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| session_id: expect.stringMatching(REGEXP_SESSION_ID), | ||
| }, | ||
| }); | ||
|
|
@@ -881,7 +881,7 @@ describe('Altertable', () => { | |
| environment: expect.any(String), | ||
| device_id: expect.stringMatching(REGEXP_DEVICE_ID), | ||
| new_user_id: 'user456', | ||
| distinct_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| anonymous_id: null, | ||
| }) | ||
| ); | ||
|
|
@@ -933,7 +933,7 @@ describe('Altertable', () => { | |
| }).toRequestApi('/alias', { | ||
| payload: expect.objectContaining({ | ||
| new_user_id: 'user456', | ||
| distinct_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| distinct_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| anonymous_id: null, | ||
| }), | ||
| }); | ||
|
|
@@ -954,7 +954,7 @@ describe('Altertable', () => { | |
| payload: expect.objectContaining({ | ||
| new_user_id: 'user456', | ||
| distinct_id: 'user123', | ||
| anonymous_id: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymous_id: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| }), | ||
| }); | ||
| }); | ||
|
|
@@ -973,10 +973,10 @@ describe('Altertable', () => { | |
| }); | ||
|
|
||
| it('persists session ID across page reloads', () => { | ||
| const testVisitorId = 'visitor-test-uuid-1-1234567890'; | ||
| const testAnonymousId = 'anonymous-test-uuid-1-1234567890'; | ||
| const testSessionId = 'session-test-uuid-2-1234567890'; | ||
| const existingSessionData = createSessionData({ | ||
| visitorId: testVisitorId, | ||
| anonymousId: testAnonymousId, | ||
| sessionId: testSessionId, | ||
| }); | ||
|
|
||
|
|
@@ -999,13 +999,13 @@ describe('Altertable', () => { | |
| describe('session renewal', () => { | ||
| it('regenerates session ID when event sent after 30 minutes', () => { | ||
| vi.useFakeTimers(); | ||
| const testVisitorId = 'visitor-test-uuid-3-1234567890'; | ||
| const testAnonymousId = 'anonymous-test-uuid-3-1234567890'; | ||
| const testSessionId = 'session-test-uuid-4-1234567890'; | ||
| const thirtyMinutesAgo = new Date( | ||
| Date.now() - 30 * 60 * 1000 - 1000 | ||
| ).toISOString(); | ||
| const existingSessionData = createSessionData({ | ||
| visitorId: testVisitorId, | ||
| anonymousId: testAnonymousId, | ||
| sessionId: testSessionId, | ||
| lastEventAt: thirtyMinutesAgo, | ||
| }); | ||
|
|
@@ -1045,13 +1045,13 @@ describe('Altertable', () => { | |
|
|
||
| it('does not regenerate session ID when event sent within 30 minutes', () => { | ||
| vi.useFakeTimers(); | ||
| const testVisitorId = 'visitor-test-uuid-5-1234567890'; | ||
| const testAnonymousId = 'anonymous-test-uuid-5-1234567890'; | ||
| const testSessionId = 'session-test-uuid-6-1234567890'; | ||
| const twentyNineMinutesAgo = new Date( | ||
| Date.now() - 29 * 60 * 1000 | ||
| ).toISOString(); | ||
| const existingSessionData = createSessionData({ | ||
| visitorId: testVisitorId, | ||
| anonymousId: testAnonymousId, | ||
| sessionId: testSessionId, | ||
| lastEventAt: twentyNineMinutesAgo, | ||
| }); | ||
|
|
@@ -1099,7 +1099,7 @@ describe('Altertable', () => { | |
|
|
||
| altertable.reset(); | ||
| const distinctId = altertable['_sessionManager'].getDistinctId(); | ||
| expect(distinctId).toMatch(REGEXP_VISITOR_ID); | ||
| expect(distinctId).toMatch(REGEXP_ANONYMOUS_ID); | ||
| const anonymousId = altertable['_sessionManager'].getAnonymousId(); | ||
| expect(anonymousId).toBeNull(); | ||
| }); | ||
|
|
@@ -1120,7 +1120,7 @@ describe('Altertable', () => { | |
| expect(newSessionId).toMatch(REGEXP_SESSION_ID); | ||
|
|
||
| const newDistinctId = altertable['_sessionManager'].getDistinctId(); | ||
| expect(newDistinctId).toMatch(REGEXP_VISITOR_ID); | ||
| expect(newDistinctId).toMatch(REGEXP_ANONYMOUS_ID); | ||
| const newAnonymousId = altertable['_sessionManager'].getAnonymousId(); | ||
| expect(newAnonymousId).toBeNull(); | ||
| }); | ||
|
|
@@ -1174,15 +1174,15 @@ describe('Altertable', () => { | |
| ]; | ||
| const storedData = JSON.parse(lastCall[1]); | ||
| expect(storedData).toMatchObject({ | ||
| anonymousId: expect.stringMatching(REGEXP_VISITOR_ID), | ||
| anonymousId: expect.stringMatching(REGEXP_ANONYMOUS_ID), | ||
| sessionId: expect.stringMatching(REGEXP_SESSION_ID), | ||
| distinctId: 'user123', | ||
| lastEventAt: null, | ||
| }); | ||
| }); | ||
|
|
||
| it('recovers storage data on initialization', () => { | ||
| const testAnonymousId = 'visitor-test-uuid-3-1234567890'; | ||
| const testAnonymousId = 'anonymous-test-uuid-3-1234567890'; | ||
| const testSessionId = 'session-test-uuid-4-1234567890'; | ||
| const existingData = createSessionData({ | ||
| anonymousId: testAnonymousId, | ||
|
|
@@ -1233,7 +1233,7 @@ describe('Altertable', () => { | |
| const distinctId = altertable['_sessionManager'].getDistinctId(); | ||
| const sessionId = altertable['_sessionManager'].getSessionId(); | ||
| const anonymousId = altertable['_sessionManager'].getAnonymousId(); | ||
| expect(distinctId).toMatch(REGEXP_VISITOR_ID); | ||
| expect(distinctId).toMatch(REGEXP_ANONYMOUS_ID); | ||
| expect(sessionId).toMatch(REGEXP_SESSION_ID); | ||
| expect(anonymousId).toBeNull(); | ||
| }); | ||
|
|
@@ -1635,7 +1635,7 @@ describe('Altertable', () => { | |
| // 6. Reset (should clear state) | ||
| altertable.reset(); | ||
| expect(altertable['_sessionManager'].getDistinctId()).toMatch( | ||
| REGEXP_VISITOR_ID | ||
| REGEXP_ANONYMOUS_ID | ||
| ); | ||
| expect(altertable['_sessionManager'].getAnonymousId()).toBeNull(); | ||
| expect(altertable['_sessionManager'].getSessionId()).toMatch( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fixed the semantics in comments