mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 03:48:27 +00:00
Bump posthog SDK version to 3.2.0 (#2788)
Co-authored-by: Mauro <34335419+Velin92@users.noreply.github.com>
This commit is contained in:
@@ -6625,23 +6625,18 @@ class OrientationManagerMock: OrientationManagerProtocol {
|
||||
}
|
||||
}
|
||||
class PHGPostHogMock: PHGPostHogProtocol {
|
||||
var enabled: Bool {
|
||||
get { return underlyingEnabled }
|
||||
set(value) { underlyingEnabled = value }
|
||||
}
|
||||
var underlyingEnabled: Bool!
|
||||
|
||||
//MARK: - enable
|
||||
//MARK: - optIn
|
||||
|
||||
var enableUnderlyingCallsCount = 0
|
||||
var enableCallsCount: Int {
|
||||
var optInUnderlyingCallsCount = 0
|
||||
var optInCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return enableUnderlyingCallsCount
|
||||
return optInUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = enableUnderlyingCallsCount
|
||||
returnValue = optInUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
@@ -6649,34 +6644,34 @@ class PHGPostHogMock: PHGPostHogProtocol {
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
enableUnderlyingCallsCount = newValue
|
||||
optInUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
enableUnderlyingCallsCount = newValue
|
||||
optInUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var enableCalled: Bool {
|
||||
return enableCallsCount > 0
|
||||
var optInCalled: Bool {
|
||||
return optInCallsCount > 0
|
||||
}
|
||||
var enableClosure: (() -> Void)?
|
||||
var optInClosure: (() -> Void)?
|
||||
|
||||
func enable() {
|
||||
enableCallsCount += 1
|
||||
enableClosure?()
|
||||
func optIn() {
|
||||
optInCallsCount += 1
|
||||
optInClosure?()
|
||||
}
|
||||
//MARK: - disable
|
||||
//MARK: - optOut
|
||||
|
||||
var disableUnderlyingCallsCount = 0
|
||||
var disableCallsCount: Int {
|
||||
var optOutUnderlyingCallsCount = 0
|
||||
var optOutCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return disableUnderlyingCallsCount
|
||||
return optOutUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = disableUnderlyingCallsCount
|
||||
returnValue = optOutUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
@@ -6684,22 +6679,22 @@ class PHGPostHogMock: PHGPostHogProtocol {
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
disableUnderlyingCallsCount = newValue
|
||||
optOutUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
disableUnderlyingCallsCount = newValue
|
||||
optOutUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var disableCalled: Bool {
|
||||
return disableCallsCount > 0
|
||||
var optOutCalled: Bool {
|
||||
return optOutCallsCount > 0
|
||||
}
|
||||
var disableClosure: (() -> Void)?
|
||||
var optOutClosure: (() -> Void)?
|
||||
|
||||
func disable() {
|
||||
disableCallsCount += 1
|
||||
disableClosure?()
|
||||
func optOut() {
|
||||
optOutCallsCount += 1
|
||||
optOutClosure?()
|
||||
}
|
||||
//MARK: - reset
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@ import PostHog
|
||||
|
||||
extension PHGPostHogMock {
|
||||
func configureMockBehavior() {
|
||||
enableClosure = {
|
||||
self.enabled = true
|
||||
}
|
||||
// We don't need custom configuration anymore since update of the posthog SDK
|
||||
// Keeping boilerplate code in case needed later?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +31,7 @@ class MockPostHogFactory: PostHogFactory {
|
||||
self.mock = mock
|
||||
}
|
||||
|
||||
func createPostHog(config: PHGPostHogConfiguration) -> ElementX.PHGPostHogProtocol {
|
||||
func createPostHog(config: PostHogConfig) -> ElementX.PHGPostHogProtocol {
|
||||
mock
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user