diff --git a/IntegrationTest/devicefarm/logcat_test.py b/IntegrationTest/devicefarm/logcat_test.py index 5dcbebc..fc0c9cf 100644 --- a/IntegrationTest/devicefarm/logcat_test.py +++ b/IntegrationTest/devicefarm/logcat_test.py @@ -66,11 +66,9 @@ def test_first_screen_view(self, path): if screen_view_event['event_json'].get('attributes')['_entrances'] == 0: screen_view_event = sorted_screen_view_events[1] assert screen_view_event['event_json'].get('attributes')['_entrances'] == 1 - assert '_screen_id' in screen_view_event['event_json'].get('attributes') assert '_screen_name' in screen_view_event['event_json'].get('attributes') assert '_screen_unique_id' in screen_view_event['event_json'].get('attributes') - assert '_session_id' in screen_view_event['event_json'].get('attributes') assert '_session_start_timestamp' in screen_view_event['event_json'].get('attributes') assert '_session_duration' in screen_view_event['event_json'].get('attributes') assert '_session_number' in screen_view_event['event_json'].get('attributes') @@ -85,11 +83,9 @@ def test_last_screen_view(self, path): (event for event in reversed(self.recorded_events) if '_screen_view' in event.get('event_name', '')), None) assert screen_view_event['event_json'].get('attributes')['_entrances'] == 0 - assert '_screen_id' in screen_view_event['event_json'].get('attributes') assert '_screen_name' in screen_view_event['event_json'].get('attributes') assert '_screen_unique_id' in screen_view_event['event_json'].get('attributes') - assert '_previous_screen_id' in screen_view_event['event_json'].get('attributes') assert '_previous_screen_name' in screen_view_event['event_json'].get('attributes') assert '_previous_screen_unique_id' in screen_view_event['event_json'].get('attributes') assert '_previous_timestamp' in screen_view_event['event_json'].get('attributes') diff --git a/Sources/Clickstream/Dependency/Clickstream/AutoRecord/AutoRecordEventClient.swift b/Sources/Clickstream/Dependency/Clickstream/AutoRecord/AutoRecordEventClient.swift index b879aaa..345fabe 100644 --- a/Sources/Clickstream/Dependency/Clickstream/AutoRecord/AutoRecordEventClient.swift +++ b/Sources/Clickstream/Dependency/Clickstream/AutoRecord/AutoRecordEventClient.swift @@ -76,6 +76,19 @@ class AutoRecordEventClient { } } + func recordScreenViewAfterSessionStart() { + if lastScreenName != nil { + let currentScreenName = lastScreenName! + let currentScreenUniqueId = lastScreenUniqueId ?? "" + let currentScreenId = lastScreenPath ?? "" + lastScreenName = nil + lastScreenUniqueId = nil + lastScreenPath = nil + onViewDidAppear(screenName: currentScreenName, screenPath: currentScreenId, + screenHashValue: currentScreenUniqueId) + } + } + func recordScreenViewEvent(_ event: ClickstreamEvent, _ screenName: String, _ screenPath: String?, _ screenUniqueId: String?) { diff --git a/Sources/Clickstream/Dependency/Clickstream/Session/SessionClient.swift b/Sources/Clickstream/Dependency/Clickstream/Session/SessionClient.swift index 66923c8..896e32e 100644 --- a/Sources/Clickstream/Dependency/Clickstream/Session/SessionClient.swift +++ b/Sources/Clickstream/Dependency/Clickstream/Session/SessionClient.swift @@ -44,6 +44,7 @@ class SessionClient: SessionClientBehaviour { if session!.isNewSession { autoRecordClient.recordSessionStartEvent() autoRecordClient.setIsEntrances() + autoRecordClient.recordScreenViewAfterSessionStart() } } diff --git a/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift b/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift index 1b90031..caa4b15 100644 --- a/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift +++ b/Tests/ClickstreamTests/Clickstream/SessionClientTests.swift @@ -186,6 +186,36 @@ class SessionClientTests: XCTestCase { XCTAssertFalse(appStartEvent.attributes[Event.ReservedAttribute.IS_FIRST_TIME] as! Bool) } + func testReopenAppAfterSessionTimeoutWillRecordScreenView() { + clickstream.configuration.sessionTimeoutDuration = 0 + activityTracker.callback?(.runningInForeground) + let viewController = MockViewControllerA() + let window = UIWindow(frame: UIScreen.main.bounds) + window.rootViewController = viewController + window.makeKeyAndVisible() + activityTracker.callback?(.runningInBackground) + activityTracker.callback?(.runningInForeground) + Thread.sleep(forTimeInterval: 0.1) + let events = eventRecorder.savedEvents + XCTAssertEqual(8, events.count) + XCTAssertEqual(Event.PresetEvent.FIRST_OPEN, events[0].eventType) + XCTAssertEqual(Event.PresetEvent.APP_START, events[1].eventType) + XCTAssertEqual(Event.PresetEvent.SESSION_START, events[2].eventType) + XCTAssertEqual(Event.PresetEvent.SCREEN_VIEW, events[3].eventType) + XCTAssertEqual(Event.PresetEvent.APP_END, events[4].eventType) + XCTAssertEqual(Event.PresetEvent.APP_START, events[5].eventType) + XCTAssertEqual(Event.PresetEvent.SESSION_START, events[6].eventType) + + XCTAssertEqual(Event.PresetEvent.SCREEN_VIEW, events[7].eventType) + XCTAssertNotNil(events[7].attributes[Event.ReservedAttribute.SCREEN_NAME]) + XCTAssertNotNil(events[7].attributes[Event.ReservedAttribute.SCREEN_ID]) + XCTAssertNotNil(events[7].attributes[Event.ReservedAttribute.SCREEN_UNIQUEID]) + XCTAssertNil(events[7].attributes[Event.ReservedAttribute.PREVIOUS_SCREEN_NAME]) + XCTAssertNil(events[7].attributes[Event.ReservedAttribute.PREVIOUS_SCREEN_ID]) + XCTAssertNil(events[7].attributes[Event.ReservedAttribute.PREVIOUS_SCREEN_UNIQUEID]) + XCTAssertEqual(1, events[7].attributes[Event.ReservedAttribute.ENTRANCES] as! Int) + } + func testLastScreenStartTimeStampUpdatedAfterReturnToForeground() { activityTracker.callback?(.runningInForeground) let viewController = MockViewControllerA()