-
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
1 parent
5c483f4
commit ed54eb2
Showing
7 changed files
with
64 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,6 @@ | ||
export const isNewSession = (sessionTimeout: number, lastEventTime: number = Date.now()): boolean => { | ||
const currentTime = 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 in a same session for undefined lastEventTime', () => { | ||
const isEventInNewSession = isNewSession(sessionTimeout, undefined); | ||
|
||
expect(isEventInNewSession).toBe(false); | ||
}); | ||
|
||
test('should be a new session', () => { | ||
const lastEventTime = Date.now() - sessionTimeout * 2; | ||
const isEventInNewSession = isNewSession(sessionTimeout, lastEventTime); | ||
|
||
expect(isEventInNewSession).toBe(true); | ||
}); | ||
|
||
test('should be in a same session', () => { | ||
const lastEventTime = Date.now(); | ||
const isEventInNewSession = isNewSession(sessionTimeout, lastEventTime); | ||
|
||
expect(isEventInNewSession).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