Skip to content

Commit

Permalink
recording: do not rotate the session id for hybrid SDKs (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Nov 18, 2024
1 parent b30fca1 commit 052971b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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
20 changes: 20 additions & 0 deletions PostHog/PostHogSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ import Foundation
timeNow - sessionLastTimestamp > sessionChangeThreshold
}

private func isiOSNativeSdk() -> Bool {
// postHogSdkName will be set to eg posthog-react-native if not
postHogSdkName == postHogiOSSdkName
}

func resetSessionIfExpired(_ completion: () -> Void) {
// for hybrid SDKs, the session is handled by the hybrid SDK
guard isiOSNativeSdk() else {
return
}

sessionLock.withLock {
let timeNow = now().timeIntervalSince1970
if sessionId != nil,
Expand Down Expand Up @@ -79,6 +89,11 @@ import Foundation
}

func rotateSessionIdIfRequired(_ completion: @escaping (() -> Void)) {
// for hybrid SDKs, the session is handled by the hybrid SDK
guard isiOSNativeSdk() else {
return
}

sessionLock.withLock {
let timeNow = now().timeIntervalSince1970

Expand All @@ -94,6 +109,11 @@ import Foundation
}

func updateSessionLastTime() {
// for hybrid SDKs, the session is handled by the hybrid SDK
guard isiOSNativeSdk() else {
return
}

sessionLock.withLock {
sessionLastTimestamp = now().timeIntervalSince1970
}
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 052971b

Please sign in to comment.