File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Sources/Clickstream/Dependency/Clickstream
Tests/ClickstreamTests/Clickstream Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ class AutoRecordEventClient {
8989 }
9090 }
9191
92+ func updateLastScreenStartTimestamp( ) {
93+ lastScreenStartTimestamp = Date ( ) . millisecondsSince1970
94+ }
95+
9296 func getPreviousScreenViewTimestamp( ) -> Int64 {
9397 if lastScreenStartTimestamp > 0 {
9498 return lastScreenStartTimestamp
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class SessionClient: SessionClientBehaviour {
5858 private func handleAppEnterForeground( ) {
5959 log. debug ( " Application entered the foreground. " )
6060 autoRecordClient. handleAppStart ( )
61+ autoRecordClient. updateLastScreenStartTimestamp ( )
6162 let isNewSession = initialSession ( )
6263 if isNewSession {
6364 autoRecordClient. setIsEntrances ( )
Original file line number Diff line number Diff line change @@ -187,4 +187,21 @@ class SessionClientTests: XCTestCase {
187187 XCTAssertNotNil ( appStartEvent. attributes [ Event . ReservedAttribute. SCREEN_ID] )
188188 XCTAssertFalse ( appStartEvent. attributes [ Event . ReservedAttribute. IS_FIRST_TIME] as! Bool )
189189 }
190+
191+ func testLastScreenStartTimeStampUpdatedAfterReturnToForeground( ) {
192+ activityTracker. callback ? ( . runningInForeground)
193+ let viewController = MockViewControllerA ( )
194+ let window = UIWindow ( frame: UIScreen . main. bounds)
195+ window. rootViewController = viewController
196+ window. makeKeyAndVisible ( )
197+ Thread . sleep ( forTimeInterval: 0.2 )
198+ activityTracker. callback ? ( . runningInForeground)
199+ Thread . sleep ( forTimeInterval: 1 )
200+ activityTracker. callback ? ( . runningInBackground)
201+ let events = eventRecorder. savedEvents
202+ XCTAssertEqual ( 7 , events. count)
203+ let userEngagementEvent = events [ 6 ]
204+ XCTAssertEqual ( Event . PresetEvent. USER_ENGAGEMENT, userEngagementEvent. eventType)
205+ XCTAssertTrue ( ( userEngagementEvent. attributes [ Event . ReservedAttribute. ENGAGEMENT_TIMESTAMP] as! Int64 ) < 1_200 )
206+ }
190207}
You can’t perform that action at this time.
0 commit comments