From 9fc8a1ef908354d79166e267fd1e89362cb9ebab Mon Sep 17 00:00:00 2001 From: Ioannis J Date: Fri, 13 Dec 2024 10:36:14 +0200 Subject: [PATCH] fix: capture timestamp along with snapshot events --- PostHog/Replay/PostHogReplayIntegration.swift | 12 ++++++++++-- PostHog/Replay/UIApplicationTracker.swift | 9 ++++++++- PostHog/Replay/URLSessionExtension.swift | 8 +++++++- PostHog/Replay/URLSessionInterceptor.swift | 9 ++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/PostHog/Replay/PostHogReplayIntegration.swift b/PostHog/Replay/PostHogReplayIntegration.swift index 03ebd93d4..8b7fde505 100644 --- a/PostHog/Replay/PostHogReplayIntegration.swift +++ b/PostHog/Replay/PostHogReplayIntegration.swift @@ -145,7 +145,8 @@ private func generateSnapshot(_ window: UIWindow, _ screenName: String? = nil) { var hasChanges = false - let timestamp = Date().toMillis() + let timestampDate = Date() + let timestamp = timestampDate.toMillis() let snapshotStatus = windowViews.object(forKey: window) ?? ViewTreeSnapshotStatus() guard let wireframe = config.sessionReplayConfig.screenshotMode ? toScreenshotWireframe(window) : toWireframe(window) else { @@ -185,7 +186,14 @@ let snapshotData: [String: Any] = ["type": 2, "data": data, "timestamp": timestamp] snapshotsData.append(snapshotData) - PostHogSDK.shared.capture("$snapshot", properties: ["$snapshot_source": "mobile", "$snapshot_data": snapshotsData]) + PostHogSDK.shared.capture( + "$snapshot", + properties: [ + "$snapshot_source": "mobile", + "$snapshot_data": snapshotsData, + ], + timestamp: timestampDate + ) } } diff --git a/PostHog/Replay/UIApplicationTracker.swift b/PostHog/Replay/UIApplicationTracker.swift index 1fe95b413..10bc6e8a9 100644 --- a/PostHog/Replay/UIApplicationTracker.swift +++ b/PostHog/Replay/UIApplicationTracker.swift @@ -87,7 +87,14 @@ snapshotsData.append(data) } if !snapshotsData.isEmpty { - PostHogSDK.shared.capture("$snapshot", properties: ["$snapshot_source": "mobile", "$snapshot_data": snapshotsData]) + PostHogSDK.shared.capture( + "$snapshot", + properties: [ + "$snapshot_source": "mobile", + "$snapshot_data": snapshotsData, + ], + timestamp: date + ) } } } diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index da94325de..182faa2e8 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -140,7 +140,13 @@ let recordingData: [String: Any] = ["type": 6, "data": pluginData, "timestamp": timestamp.toMillis()] snapshotsData.append(recordingData) - PostHogSDK.shared.capture("$snapshot", properties: ["$snapshot_source": "mobile", "$snapshot_data": snapshotsData]) + PostHogSDK.shared.capture( + "$snapshot", + properties: + ["$snapshot_source": "mobile", + "$snapshot_data": snapshotsData], + timestamp: timestamp + ) } } } diff --git a/PostHog/Replay/URLSessionInterceptor.swift b/PostHog/Replay/URLSessionInterceptor.swift index c9857a497..2a7bc3a62 100644 --- a/PostHog/Replay/URLSessionInterceptor.swift +++ b/PostHog/Replay/URLSessionInterceptor.swift @@ -131,7 +131,14 @@ let data: [String: Any] = ["type": 6, "data": pluginData, "timestamp": sample.timeOrigin.toMillis()] snapshotsData.append(data) - PostHogSDK.shared.capture("$snapshot", properties: ["$snapshot_source": "mobile", "$snapshot_data": snapshotsData]) + PostHogSDK.shared.capture( + "$snapshot", + properties: [ + "$snapshot_source": "mobile", + "$snapshot_data": snapshotsData + ], + timestamp: sample.timeOrigin + ) tasksLock.withLock { _ = samplesByTask.removeValue(forKey: task)