diff --git a/CHANGELOG.md b/CHANGELOG.md index ad8566089..7c47eb201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- recording: network logs not counting the request transferSize but only the response transferSize ([#193](https://github.com/PostHog/posthog-ios/pull/193)) + ## 3.12.0 - 2024-09-12 - chore: add Is Emulator support ([#190](https://github.com/PostHog/posthog-ios/pull/190)) diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index bae7339c5..00c1fc2fc 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -120,9 +120,14 @@ "name": request?.url?.absoluteString ?? (response?.url?.absoluteString ?? ""), "initiatorType": "fetch", "entryType": "resource", - "transferSize": response?.expectedContentLength ?? 0, "timestamp": timestamp.toMillis()] + // the UI special case if the transferSize is 0 as coming from cache + let transferSize = Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0) + if transferSize > 0 { + requestsData["transferSize"] = transferSize + } + if let urlResponse = response as? HTTPURLResponse { requestsData["responseStatus"] = urlResponse.statusCode } diff --git a/PostHog/Replay/URLSessionInterceptor.swift b/PostHog/Replay/URLSessionInterceptor.swift index 6108f29d2..5d6a7c223 100644 --- a/PostHog/Replay/URLSessionInterceptor.swift +++ b/PostHog/Replay/URLSessionInterceptor.swift @@ -80,8 +80,11 @@ sample.httpMethod = request.httpMethod sample.initiatorType = "fetch" sample.duration = (date.toMillis() - sample.timeOrigin.toMillis()) - if let response = task.response { - sample.decodedBodySize = response.expectedContentLength + + // the UI special case if the transferSize is 0 as coming from cache + let transferSize = Int64(request.httpBody?.count ?? 0) + (task.response?.expectedContentLength ?? 0) + if transferSize > 0 { + sample.decodedBodySize = transferSize } self.finish(task: task, sample: sample)