-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix web attribution behavior for no referrer in the same session
- Loading branch information
Alyssa.Yu
authored and
Alyssa.Yu
committed
Aug 22, 2023
1 parent
502a080
commit 8f1f7af
Showing
7 changed files
with
65 additions
and
5 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
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,7 @@ | ||
export const isNewSession = (sessionTimeout: number, lastEventTime?: number): boolean => { | ||
const _currentTime = Date.now(); | ||
const _lastEventTime = lastEventTime || Date.now(); | ||
const timeSinceLastEvent = _currentTime - _lastEventTime; | ||
|
||
return timeSinceLastEvent > sessionTimeout; | ||
}; |
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,25 @@ | ||
import { isNewSession } from '../src/session'; | ||
|
||
describe('session', () => { | ||
const sessionTimeout: number = 30 * 60 * 1000; | ||
|
||
test('should be a new session for the first event', () => { | ||
const _isNewSession = isNewSession(sessionTimeout, undefined); | ||
|
||
expect(_isNewSession).toBe(false); | ||
}); | ||
|
||
test('should be a new session', () => { | ||
const lastEventTime = Date.now() - sessionTimeout * 2; | ||
const _isNewSession = isNewSession(sessionTimeout, lastEventTime); | ||
|
||
expect(_isNewSession).toBe(true); | ||
}); | ||
|
||
test('should be in a same session', () => { | ||
const lastEventTime = Date.now(); | ||
const _isNewSession = isNewSession(sessionTimeout, lastEventTime); | ||
|
||
expect(_isNewSession).toBe(false); | ||
}); | ||
}); |
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
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