Skip to content

Commit

Permalink
fix: capture timestamp along with snapshot events
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Dec 13, 2024
1 parent 5faf328 commit 9fc8a1e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
12 changes: 10 additions & 2 deletions PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion PostHog/Replay/UIApplicationTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion PostHog/Replay/URLSessionExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion PostHog/Replay/URLSessionInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9fc8a1e

Please sign in to comment.