diff --git a/src/tracker/SessionTracker.ts b/src/tracker/SessionTracker.ts index 501c119..d41fd75 100644 --- a/src/tracker/SessionTracker.ts +++ b/src/tracker/SessionTracker.ts @@ -12,6 +12,7 @@ */ import { Logger } from '@aws-amplify/core'; import { BaseTracker } from './BaseTracker'; +import { PageViewTracker } from './PageViewTracker'; import { Session } from './Session'; import { BrowserInfo } from '../browser'; import { Event } from '../provider'; @@ -103,6 +104,7 @@ export class SessionTracker extends BaseTracker { } recordUserEngagement(isImmediate: boolean) { + PageViewTracker.updateIdleDuration(); this.provider.pageViewTracker.recordUserEngagement(isImmediate); } diff --git a/test/tracker/SessionTracker.test.ts b/test/tracker/SessionTracker.test.ts index 7c48443..f3c4c2e 100644 --- a/test/tracker/SessionTracker.test.ts +++ b/test/tracker/SessionTracker.test.ts @@ -397,6 +397,16 @@ describe('SessionTracker test', () => { expect(clearFailedEventsMock).not.toBeCalled(); }); + test('test hide page will update lastActiveTimestamp', async () => { + sessionTracker.setUp(); + const startTimestamp = PageViewTracker.lastActiveTimestamp; + await sleep(110); + hidePage(); + expect( + PageViewTracker.lastActiveTimestamp - startTimestamp > 100 + ).toBeTruthy(); + }); + function hidePage() { Object.defineProperty(window.document, 'hidden', { writable: true,