Bump posthog SDK version to 3.2.0 (#2788)

Co-authored-by: Mauro <34335419+Velin92@users.noreply.github.com>
This commit is contained in:
Valere
2024-05-06 17:07:05 +02:00
committed by GitHub
parent c398338335
commit 176abd5841
10 changed files with 91 additions and 60 deletions
@@ -16,12 +16,13 @@
import PostHog
extension PHGPostHogConfiguration {
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PHGPostHogConfiguration? {
extension PostHogConfig {
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PostHogConfig? {
guard analyticsConfiguration.isEnabled else { return nil }
let postHogConfiguration = PHGPostHogConfiguration(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
postHogConfiguration.shouldSendDeviceID = false
let postHogConfiguration = PostHogConfig(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
// We capture screens manually
postHogConfiguration.captureScreenViews = false
return postHogConfiguration
}
@@ -19,11 +19,9 @@ import PostHog
// sourcery: AutoMockable
protocol PHGPostHogProtocol {
var enabled: Bool { get }
func optIn()
func enable()
func disable()
func optOut()
func reset()
@@ -33,13 +31,14 @@ protocol PHGPostHogProtocol {
}
protocol PostHogFactory {
func createPostHog(config: PHGPostHogConfiguration) -> PHGPostHogProtocol
func createPostHog(config: PostHogConfig) -> PHGPostHogProtocol
}
class DefaultPostHogFactory: PostHogFactory {
func createPostHog(config: PHGPostHogConfiguration) -> PHGPostHogProtocol {
PHGPostHog(configuration: config)
func createPostHog(config: PostHogConfig) -> PHGPostHogProtocol {
PostHogSDK.shared.setup(config)
return PostHogSDK.shared
}
}
extension PHGPostHog: PHGPostHogProtocol { }
extension PostHogSDK: PHGPostHogProtocol { }
@@ -38,19 +38,23 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
/// Not persisted for now, should be set on start.
private var superProperties: AnalyticsEvent.SuperProperties?
var isRunning: Bool { postHog?.enabled ?? false }
var isRunning: Bool { postHog != nil }
func start(analyticsConfiguration: AnalyticsConfiguration) {
// Only start if analytics have been configured in BuildSettings
guard let configuration = PHGPostHogConfiguration.standard(analyticsConfiguration: analyticsConfiguration) else { return }
guard let configuration = PostHogConfig.standard(analyticsConfiguration: analyticsConfiguration) else { return }
if postHog == nil {
postHog = posthogFactory.createPostHog(config: configuration)
if postHog != nil {
// start has been called twice in a row without calling stop()?
// Anyhow it's no-op if it's the case, but log for sanity
MXLog.failure("Posthog should always be nil when it's being started")
}
postHog = posthogFactory.createPostHog(config: configuration)
// Add super property cryptoSDK to the captured events, to allow easy
// filtering of events across different client by using same filter.
superProperties = AnalyticsEvent.SuperProperties(appPlatform: nil, cryptoSDK: .Rust, cryptoSDKVersion: nil)
postHog?.enable()
postHog?.optIn()
}
func reset() {
@@ -59,10 +63,8 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
}
func stop() {
postHog?.disable()
// As of PostHog 1.4.4, setting the client to nil here doesn't release
// it. Keep it around to avoid having multiple instances if the user re-enables
postHog?.optOut()
postHog = nil
}
func capture(_ event: AnalyticsEventProtocol) {