diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9126fcd..d34b9f069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- no user facing changes + ## 3.12.4 - 2024-09-19 - no user facing changes diff --git a/PostHog/PostHogConfig.swift b/PostHog/PostHogConfig.swift index 1c6a5bfd4..e2c9561c6 100644 --- a/PostHog/PostHogConfig.swift +++ b/PostHog/PostHogConfig.swift @@ -53,6 +53,8 @@ import Foundation // only internal var disableReachabilityForTesting: Bool = false var disableQueueTimerForTesting: Bool = false + // internal + public var storageManager: PostHogStorageManager? @objc(apiKey:) public init( diff --git a/PostHog/PostHogSDK.swift b/PostHog/PostHogSDK.swift index 8241f813a..eed9b0522 100644 --- a/PostHog/PostHogSDK.swift +++ b/PostHog/PostHogSDK.swift @@ -36,7 +36,6 @@ let maxRetryDelay = 30.0 private var replayQueue: PostHogQueue? private var api: PostHogApi? private var storage: PostHogStorage? - private var storageManager: PostHogStorageManager? #if !os(watchOS) private var reachability: Reachability? #endif @@ -99,7 +98,7 @@ let maxRetryDelay = 30.0 let theApi = PostHogApi(config) api = theApi featureFlags = PostHogFeatureFlags(config, theStorage, theApi) - storageManager = PostHogStorageManager(config) + config.storageManager = config.storageManager ?? PostHogStorageManager(config) #if os(iOS) replayIntegration = PostHogReplayIntegration(config) #endif @@ -159,7 +158,7 @@ let maxRetryDelay = 30.0 return "" } - return storageManager?.getDistinctId() ?? "" + return config.storageManager?.getDistinctId() ?? "" } @objc public func getAnonymousId() -> String { @@ -167,7 +166,7 @@ let maxRetryDelay = 30.0 return "" } - return storageManager?.getAnonymousId() ?? "" + return config.storageManager?.getAnonymousId() ?? "" } @objc public func getSessionId() -> String? { @@ -244,8 +243,8 @@ let maxRetryDelay = 30.0 config.personProfiles == .never || ( config.personProfiles == .identifiedOnly && - storageManager?.isIdentified() == false && - storageManager?.isPersonProcessing() == false + config.storageManager?.isIdentified() == false && + config.storageManager?.isPersonProcessing() == false ) ) } @@ -256,7 +255,7 @@ let maxRetryDelay = 30.0 hedgeLog("personProfiles is set to `never`. This call will be ignored.") return false } - storageManager?.setPersonProcessing(true) + config.storageManager?.setPersonProcessing(true) return true } @@ -294,7 +293,7 @@ let maxRetryDelay = 30.0 props["$groups"] = mergedGroups } - if let isIdentified = storageManager?.isIdentified() { + if let isIdentified = config.storageManager?.isIdentified() { props["$is_identified"] = isIdentified } @@ -345,7 +344,7 @@ let maxRetryDelay = 30.0 // storage also removes all feature flags storage?.reset() - storageManager?.reset() + config.storageManager?.reset() flagCallReported.removeAll() PostHogSessionManager.shared.endSession { self.resetViews() @@ -443,7 +442,7 @@ let maxRetryDelay = 30.0 return } - guard let queue = queue, let storageManager = storageManager else { + guard let queue = queue, let storageManager = config.storageManager else { return } let oldDistinctId = getDistinctId() @@ -748,7 +747,7 @@ let maxRetryDelay = 30.0 return } - guard let featureFlags = featureFlags, let storageManager = storageManager else { + guard let featureFlags = featureFlags, let storageManager = config.storageManager else { return } @@ -885,8 +884,8 @@ let maxRetryDelay = 30.0 #endif queue = nil replayQueue = nil - storageManager?.reset() - storageManager = nil + config.storageManager?.reset() + config.storageManager = nil config = PostHogConfig(apiKey: "") api = nil featureFlags = nil diff --git a/PostHog/PostHogStorageManager.swift b/PostHog/PostHogStorageManager.swift index 326832275..5d7662246 100644 --- a/PostHog/PostHogStorageManager.swift +++ b/PostHog/PostHogStorageManager.swift @@ -7,7 +7,8 @@ import Foundation -class PostHogStorageManager { +// Internal class to manage the storage metadata of the PostHog SDK +public class PostHogStorageManager { private let storage: PostHogStorage! private let anonLock = NSLock()