Skip to content

Commit

Permalink
recording: do not rotate the session id for hybrid SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Nov 15, 2024
1 parent b30fca1 commit c5d5934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- recording: do not rotate the session id for hybrid SDKs ([#249](https://github.com/PostHog/posthog-ios/pull/249))

## 3.15.2 - 2024-11-13

- fix: allow changing person properties after identify ([#249](https://github.com/PostHog/posthog-ios/pull/249))
Expand Down
19 changes: 15 additions & 4 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let maxRetryDelay = 30.0
private var capturedAppInstalled = false
private var appFromBackground = false
private var isInBackground = false
private var isiOSNativeSdk = true
#if os(iOS)
private var replayIntegration: PostHogReplayIntegration?
#endif
Expand Down Expand Up @@ -143,6 +144,9 @@ let maxRetryDelay = 30.0

registerNotifications()
captureScreenViews()

// postHogSdkName will be set to eg posthog-react-native if not
isiOSNativeSdk = postHogSdkName == postHogiOSSdkName

PostHogSessionManager.shared.startSession()

Expand Down Expand Up @@ -597,7 +601,8 @@ let maxRetryDelay = 30.0
}

// If events fire in the background after the threshold, they should no longer have a sessionId
if isInBackground {
// for hybrid SDKs, the session is handled by the hybrid SDK
if isInBackground, isiOSNativeSdk {
PostHogSessionManager.shared.resetSessionIfExpired {
self.resetViews()
}
Expand Down Expand Up @@ -1150,8 +1155,11 @@ let maxRetryDelay = 30.0
}

@objc func handleAppDidBecomeActive() {
PostHogSessionManager.shared.rotateSessionIdIfRequired {
self.resetViews()
// for hybrid SDKs, the session is handled by the hybrid SDK
if isiOSNativeSdk {
PostHogSessionManager.shared.rotateSessionIdIfRequired {
self.resetViews()
}
}

isInBackground = false
Expand Down Expand Up @@ -1188,7 +1196,10 @@ let maxRetryDelay = 30.0
@objc func handleAppDidEnterBackground() {
captureAppBackgrounded()

PostHogSessionManager.shared.updateSessionLastTime()
// for hybrid SDKs, the session is handled by the hybrid SDK
if isiOSNativeSdk {
PostHogSessionManager.shared.updateSessionLastTime()
}

isInBackground = true
}
Expand Down
3 changes: 2 additions & 1 deletion PostHog/PostHogVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import Foundation
// This property is internal only
public var postHogVersion = "3.15.2"

public let postHogiOSSdkName = "posthog-ios"
// This property is internal only
public var postHogSdkName = "posthog-ios"
public var postHogSdkName = postHogiOSSdkName

0 comments on commit c5d5934

Please sign in to comment.