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

recording: do not rotate the session id for hybrid SDKs #253

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 ([#253](https://github.com/PostHog/posthog-ios/pull/253))

## 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 @@ -144,6 +145,9 @@ let maxRetryDelay = 30.0
registerNotifications()
captureScreenViews()

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

PostHogSessionManager.shared.startSession()

#if os(iOS)
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
Loading