Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rotate session id when reset is called #174

Merged
merged 10 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- fix: rotate session id when reset is called ([#174](https://github.com/PostHog/posthog-ios/pull/174))
- chore: expose session id ([#165](https://github.com/PostHog/posthog-ios/pull/165)), ([#170](https://github.com/PostHog/posthog-ios/pull/170)) and ([#171](https://github.com/PostHog/posthog-ios/pull/171))

## 3.7.2 - 2024-08-16
Expand Down
1 change: 1 addition & 0 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ let maxRetryDelay = 30.0
replayQueue?.clear()
flagCallReported.removeAll()
PostHogSessionManager.shared.endSession()
PostHogSessionManager.shared.startSession()
}

private func getGroups() -> [String: String] {
Expand Down
10 changes: 7 additions & 3 deletions PostHogTests/PostHogSDKTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ class PostHogSDKTest: QuickSpec {
sut.close()
}

it("clears sessionId after reset") {
it("reset sessionId after reset") {
let sut = self.getSut(captureApplicationLifecycleEvents: true, flushAt: 1)
let mockNow = MockDate()
now = { mockNow.date }
Expand All @@ -676,7 +676,8 @@ class PostHogSDKTest: QuickSpec {
var events = getBatchedEvents(server)
expect(events.count) == 1

expect(events[0].properties["$session_id"] as? String).toNot(beNil())
let currentSessionId = events[0].properties["$session_id"] as? String
expect(currentSessionId).toNot(beNil())

sut.reset()

Expand All @@ -690,7 +691,10 @@ class PostHogSDKTest: QuickSpec {
events = getBatchedEvents(server)
expect(events.count) == 1

expect(events[0].properties["$session_id"] as? String).to(beNil())
let newSessionId = events[0].properties["$session_id"] as? String
expect(newSessionId).toNot(beNil())

expect(currentSessionId).toNot(equal(newSessionId))

sut.reset()
sut.close()
Expand Down
Loading