mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +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:
parent
c398338335
commit
176abd5841
@ -7352,7 +7352,7 @@
|
|||||||
repositoryURL = "https://github.com/PostHog/posthog-ios";
|
repositoryURL = "https://github.com/PostHog/posthog-ios";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = upToNextMinorVersion;
|
kind = upToNextMinorVersion;
|
||||||
minimumVersion = 2.0.3;
|
minimumVersion = 3.2.4;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
9A472EE0218FE7DCF5283429 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
|
9A472EE0218FE7DCF5283429 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
|
||||||
|
@ -166,8 +166,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/PostHog/posthog-ios",
|
"location" : "https://github.com/PostHog/posthog-ios",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "9298825fe26899a58b976d400254e0b050daa578",
|
"revision" : "d127599034e08f12f340e5e2da13090a894d55d6",
|
||||||
"version" : "2.0.5"
|
"version" : "3.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -6625,23 +6625,18 @@ class OrientationManagerMock: OrientationManagerProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class PHGPostHogMock: PHGPostHogProtocol {
|
class PHGPostHogMock: PHGPostHogProtocol {
|
||||||
var enabled: Bool {
|
|
||||||
get { return underlyingEnabled }
|
|
||||||
set(value) { underlyingEnabled = value }
|
|
||||||
}
|
|
||||||
var underlyingEnabled: Bool!
|
|
||||||
|
|
||||||
//MARK: - enable
|
//MARK: - optIn
|
||||||
|
|
||||||
var enableUnderlyingCallsCount = 0
|
var optInUnderlyingCallsCount = 0
|
||||||
var enableCallsCount: Int {
|
var optInCallsCount: Int {
|
||||||
get {
|
get {
|
||||||
if Thread.isMainThread {
|
if Thread.isMainThread {
|
||||||
return enableUnderlyingCallsCount
|
return optInUnderlyingCallsCount
|
||||||
} else {
|
} else {
|
||||||
var returnValue: Int? = nil
|
var returnValue: Int? = nil
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
returnValue = enableUnderlyingCallsCount
|
returnValue = optInUnderlyingCallsCount
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue!
|
return returnValue!
|
||||||
@ -6649,34 +6644,34 @@ class PHGPostHogMock: PHGPostHogProtocol {
|
|||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if Thread.isMainThread {
|
if Thread.isMainThread {
|
||||||
enableUnderlyingCallsCount = newValue
|
optInUnderlyingCallsCount = newValue
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
enableUnderlyingCallsCount = newValue
|
optInUnderlyingCallsCount = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var enableCalled: Bool {
|
var optInCalled: Bool {
|
||||||
return enableCallsCount > 0
|
return optInCallsCount > 0
|
||||||
}
|
}
|
||||||
var enableClosure: (() -> Void)?
|
var optInClosure: (() -> Void)?
|
||||||
|
|
||||||
func enable() {
|
func optIn() {
|
||||||
enableCallsCount += 1
|
optInCallsCount += 1
|
||||||
enableClosure?()
|
optInClosure?()
|
||||||
}
|
}
|
||||||
//MARK: - disable
|
//MARK: - optOut
|
||||||
|
|
||||||
var disableUnderlyingCallsCount = 0
|
var optOutUnderlyingCallsCount = 0
|
||||||
var disableCallsCount: Int {
|
var optOutCallsCount: Int {
|
||||||
get {
|
get {
|
||||||
if Thread.isMainThread {
|
if Thread.isMainThread {
|
||||||
return disableUnderlyingCallsCount
|
return optOutUnderlyingCallsCount
|
||||||
} else {
|
} else {
|
||||||
var returnValue: Int? = nil
|
var returnValue: Int? = nil
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
returnValue = disableUnderlyingCallsCount
|
returnValue = optOutUnderlyingCallsCount
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue!
|
return returnValue!
|
||||||
@ -6684,22 +6679,22 @@ class PHGPostHogMock: PHGPostHogProtocol {
|
|||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if Thread.isMainThread {
|
if Thread.isMainThread {
|
||||||
disableUnderlyingCallsCount = newValue
|
optOutUnderlyingCallsCount = newValue
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
disableUnderlyingCallsCount = newValue
|
optOutUnderlyingCallsCount = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var disableCalled: Bool {
|
var optOutCalled: Bool {
|
||||||
return disableCallsCount > 0
|
return optOutCallsCount > 0
|
||||||
}
|
}
|
||||||
var disableClosure: (() -> Void)?
|
var optOutClosure: (() -> Void)?
|
||||||
|
|
||||||
func disable() {
|
func optOut() {
|
||||||
disableCallsCount += 1
|
optOutCallsCount += 1
|
||||||
disableClosure?()
|
optOutClosure?()
|
||||||
}
|
}
|
||||||
//MARK: - reset
|
//MARK: - reset
|
||||||
|
|
||||||
|
@ -19,9 +19,8 @@ import PostHog
|
|||||||
|
|
||||||
extension PHGPostHogMock {
|
extension PHGPostHogMock {
|
||||||
func configureMockBehavior() {
|
func configureMockBehavior() {
|
||||||
enableClosure = {
|
// We don't need custom configuration anymore since update of the posthog SDK
|
||||||
self.enabled = true
|
// Keeping boilerplate code in case needed later?
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ class MockPostHogFactory: PostHogFactory {
|
|||||||
self.mock = mock
|
self.mock = mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func createPostHog(config: PHGPostHogConfiguration) -> ElementX.PHGPostHogProtocol {
|
func createPostHog(config: PostHogConfig) -> ElementX.PHGPostHogProtocol {
|
||||||
mock
|
mock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
import PostHog
|
import PostHog
|
||||||
|
|
||||||
extension PHGPostHogConfiguration {
|
extension PostHogConfig {
|
||||||
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PHGPostHogConfiguration? {
|
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PostHogConfig? {
|
||||||
guard analyticsConfiguration.isEnabled else { return nil }
|
guard analyticsConfiguration.isEnabled else { return nil }
|
||||||
|
|
||||||
let postHogConfiguration = PHGPostHogConfiguration(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
|
let postHogConfiguration = PostHogConfig(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
|
||||||
postHogConfiguration.shouldSendDeviceID = false
|
// We capture screens manually
|
||||||
|
postHogConfiguration.captureScreenViews = false
|
||||||
|
|
||||||
return postHogConfiguration
|
return postHogConfiguration
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,9 @@ import PostHog
|
|||||||
|
|
||||||
// sourcery: AutoMockable
|
// sourcery: AutoMockable
|
||||||
protocol PHGPostHogProtocol {
|
protocol PHGPostHogProtocol {
|
||||||
var enabled: Bool { get }
|
func optIn()
|
||||||
|
|
||||||
func enable()
|
func optOut()
|
||||||
|
|
||||||
func disable()
|
|
||||||
|
|
||||||
func reset()
|
func reset()
|
||||||
|
|
||||||
@ -33,13 +31,14 @@ protocol PHGPostHogProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol PostHogFactory {
|
protocol PostHogFactory {
|
||||||
func createPostHog(config: PHGPostHogConfiguration) -> PHGPostHogProtocol
|
func createPostHog(config: PostHogConfig) -> PHGPostHogProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultPostHogFactory: PostHogFactory {
|
class DefaultPostHogFactory: PostHogFactory {
|
||||||
func createPostHog(config: PHGPostHogConfiguration) -> PHGPostHogProtocol {
|
func createPostHog(config: PostHogConfig) -> PHGPostHogProtocol {
|
||||||
PHGPostHog(configuration: config)
|
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.
|
/// Not persisted for now, should be set on start.
|
||||||
private var superProperties: AnalyticsEvent.SuperProperties?
|
private var superProperties: AnalyticsEvent.SuperProperties?
|
||||||
|
|
||||||
var isRunning: Bool { postHog?.enabled ?? false }
|
var isRunning: Bool { postHog != nil }
|
||||||
|
|
||||||
func start(analyticsConfiguration: AnalyticsConfiguration) {
|
func start(analyticsConfiguration: AnalyticsConfiguration) {
|
||||||
// Only start if analytics have been configured in BuildSettings
|
// 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 {
|
if postHog != nil {
|
||||||
postHog = posthogFactory.createPostHog(config: configuration)
|
// 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
|
// Add super property cryptoSDK to the captured events, to allow easy
|
||||||
// filtering of events across different client by using same filter.
|
// filtering of events across different client by using same filter.
|
||||||
superProperties = AnalyticsEvent.SuperProperties(appPlatform: nil, cryptoSDK: .Rust, cryptoSDKVersion: nil)
|
superProperties = AnalyticsEvent.SuperProperties(appPlatform: nil, cryptoSDK: .Rust, cryptoSDKVersion: nil)
|
||||||
postHog?.enable()
|
postHog?.optIn()
|
||||||
}
|
}
|
||||||
|
|
||||||
func reset() {
|
func reset() {
|
||||||
@ -59,10 +63,8 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
postHog?.disable()
|
postHog?.optOut()
|
||||||
|
postHog = nil
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func capture(_ event: AnalyticsEventProtocol) {
|
func capture(_ event: AnalyticsEventProtocol) {
|
||||||
|
@ -265,4 +265,38 @@ class AnalyticsTests: XCTestCase {
|
|||||||
XCTAssertEqual(capturedEvent2?.properties?["appPlatform"] as? String, "A thing")
|
XCTAssertEqual(capturedEvent2?.properties?["appPlatform"] as? String, "A thing")
|
||||||
XCTAssertEqual(capturedEvent2?.properties?["cryptoSDKVersion"] as? String, "001")
|
XCTAssertEqual(capturedEvent2?.properties?["cryptoSDKVersion"] as? String, "001")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testShouldNotReportIfNotStarted() {
|
||||||
|
// Given a client with user properties set
|
||||||
|
let client = PostHogAnalyticsClient(posthogFactory: MockPostHogFactory(mock: posthogMock))
|
||||||
|
|
||||||
|
// No call to start
|
||||||
|
|
||||||
|
client.screen(AnalyticsEvent.MobileScreen(durationMs: nil, screenName: .Home))
|
||||||
|
|
||||||
|
XCTAssertEqual(posthogMock.screenPropertiesCalled, false)
|
||||||
|
|
||||||
|
// It should be the same for any event
|
||||||
|
let someEvent = AnalyticsEvent.Error(context: nil,
|
||||||
|
cryptoModule: .Rust,
|
||||||
|
cryptoSDK: .Rust,
|
||||||
|
domain: .E2EE,
|
||||||
|
eventLocalAgeMillis: nil,
|
||||||
|
isFederated: nil,
|
||||||
|
isMatrixDotOrg: nil,
|
||||||
|
name: .OlmKeysNotSentError,
|
||||||
|
timeToDecryptMillis: nil,
|
||||||
|
userTrustsOwnIdentity: nil,
|
||||||
|
wasVisibleToUser: nil)
|
||||||
|
client.capture(someEvent)
|
||||||
|
|
||||||
|
XCTAssertEqual(posthogMock.capturePropertiesCalled, false)
|
||||||
|
|
||||||
|
// start now
|
||||||
|
client.start(analyticsConfiguration: appSettings.analyticsConfiguration)
|
||||||
|
XCTAssertEqual(posthogMock.optInCalled, true)
|
||||||
|
|
||||||
|
client.capture(someEvent)
|
||||||
|
XCTAssertEqual(posthogMock.capturePropertiesCalled, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1
changelog.d/2788.misc
Normal file
1
changelog.d/2788.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Bump posthog sdk version to 3.2.0
|
@ -107,7 +107,7 @@ packages:
|
|||||||
minorVersion: 5.13.0
|
minorVersion: 5.13.0
|
||||||
PostHog:
|
PostHog:
|
||||||
url: https://github.com/PostHog/posthog-ios
|
url: https://github.com/PostHog/posthog-ios
|
||||||
minorVersion: 2.0.3
|
minorVersion: 3.2.4
|
||||||
Prefire:
|
Prefire:
|
||||||
url: https://github.com/BarredEwe/Prefire
|
url: https://github.com/BarredEwe/Prefire
|
||||||
minorVersion: 2.0.4
|
minorVersion: 2.0.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user