Switch from segment to posthog directly
This commit is contained in:
@ -9,15 +9,6 @@
|
||||
"version" : "0.20220203.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "analytics-swift",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/segmentio/analytics-swift.git",
|
||||
"state" : {
|
||||
"revision" : "92cc824211160ab98c28c7d40c1e6d27645c2bf1",
|
||||
"version" : "1.2.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "appauth-ios",
|
||||
"kind" : "remoteSourceControl",
|
||||
@ -153,6 +144,15 @@
|
||||
"version" : "2.6.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "posthog-ios",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/PostHog/posthog-ios.git",
|
||||
"state" : {
|
||||
"revision" : "3a6afc24d6bde730a19470d4e6b713f44d076ad9",
|
||||
"version" : "2.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "promises",
|
||||
"kind" : "remoteSourceControl",
|
||||
@ -171,15 +171,6 @@
|
||||
"version" : "12.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "sovran-swift",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/segmentio/Sovran-Swift.git",
|
||||
"state" : {
|
||||
"revision" : "944c17d7c46bd95fc37f09136cabd172be5b413b",
|
||||
"version" : "1.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
||||
@ -47,7 +47,7 @@ let package = Package(
|
||||
.target(
|
||||
name: "Utils",
|
||||
dependencies: [
|
||||
.product(name: "Segment", package: "analytics-swift")
|
||||
.product(name: "PostHog", package: "posthog-ios")
|
||||
],
|
||||
resources: [.process("Resources")]
|
||||
),
|
||||
@ -67,10 +67,10 @@ var dependencies: [Package.Dependency] {
|
||||
.package(url: "https://github.com/Square/Valet", from: "4.1.2"),
|
||||
.package(url: "https://github.com/maticzav/swift-graphql", from: "2.3.1"),
|
||||
.package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "0.1.4"),
|
||||
.package(url: "https://github.com/segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")),
|
||||
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "6.2.2"),
|
||||
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.0.0"),
|
||||
.package(url: "https://github.com/exyte/PopupView.git", from: "2.6.0")
|
||||
.package(url: "https://github.com/exyte/PopupView.git", from: "2.6.0"),
|
||||
.package(url: "https://github.com/PostHog/posthog-ios.git", from: "2.0.0")
|
||||
]
|
||||
// Comment out following line for macOS build
|
||||
deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", from: "12.0.1"))
|
||||
|
||||
@ -41,6 +41,7 @@ import Views
|
||||
do {
|
||||
try await dataService.deleteAccount(userID: currentViewer.unwrappedUserID)
|
||||
authenticator.logout(dataService: dataService, isAccountDeletion: true)
|
||||
EventTracker.reset()
|
||||
} catch {
|
||||
deleteAccountErrorMessage = "We were unable to delete your account."
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ public final class Authenticator: ObservableObject {
|
||||
Authenticator.unregisterIntercomUser?()
|
||||
isLoggedIn = false
|
||||
showAppleRevokeTokenAlert = isAccountDeletion
|
||||
EventTracker.reset()
|
||||
}
|
||||
|
||||
public func clearCreds() {
|
||||
|
||||
@ -12,7 +12,7 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.LeaveGroupResult> {
|
||||
try $0.on(
|
||||
leaveGroupError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) },
|
||||
leaveGroupError: .init { .error(errorMessage: try $0.errorCodes().first?.rawValue ?? "Unknown Error") },
|
||||
leaveGroupSuccess: .init {
|
||||
.saved(success: try $0.success())
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.RecommendResult> {
|
||||
try $0.on(
|
||||
recommendError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) },
|
||||
recommendError: .init { .error(errorMessage: try $0.errorCodes().first?.rawValue ?? "Unknown Error") },
|
||||
recommendSuccess: .init {
|
||||
.saved(success: try $0.success())
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.UpdatePageResult> {
|
||||
try $0.on(
|
||||
updatePageError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) },
|
||||
updatePageError: .init { .error(errorMessage: try $0.errorCodes().first?.rawValue ?? "Unknown Error") },
|
||||
updatePageSuccess: .init {
|
||||
.saved(title: try $0.updatedPage(selection: Selection.Article { try $0.title() }))
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ extension DataService {
|
||||
|
||||
let selection = Selection<MutationResult, Unions.UpdatePageResult> {
|
||||
try $0.on(
|
||||
updatePageError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) },
|
||||
updatePageError: .init { .error(errorMessage: try $0.errorCodes().first?.rawValue ?? "Unknown Error") },
|
||||
updatePageSuccess: .init {
|
||||
.saved(title: try $0.updatedPage(selection: Selection.Article { try $0.title() }))
|
||||
}
|
||||
|
||||
@ -1,11 +1,24 @@
|
||||
import Foundation
|
||||
import Segment
|
||||
import PostHog
|
||||
|
||||
public enum EventTracker {
|
||||
public static func start() {
|
||||
// invoke the closure that creates the segment instance
|
||||
_ = segment?.version()
|
||||
}
|
||||
public static var posthog: PHGPostHog? = {
|
||||
guard let writeKey = AppKeys.sharedInstance?.posthogClientKey else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let posthogInstanceAddress = AppKeys.sharedInstance?.posthogInstanceAddress else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let configuration = PHGPostHogConfiguration(apiKey: writeKey, host: posthogInstanceAddress)
|
||||
|
||||
configuration.recordScreenViews = false
|
||||
configuration.captureApplicationLifecycleEvents = true
|
||||
|
||||
PHGPostHog.setup(with: configuration)
|
||||
return PHGPostHog.shared()
|
||||
}()
|
||||
|
||||
public static func trackForDebugging(_ message: String) {
|
||||
#if DEBUG
|
||||
@ -14,29 +27,14 @@ public enum EventTracker {
|
||||
}
|
||||
|
||||
public static func track(_ event: TrackableEvent) {
|
||||
segment?.track(name: event.name, properties: event.properties)
|
||||
posthog?.capture(event.name, properties: event.properties)
|
||||
}
|
||||
|
||||
public static func registerUser(userID: String) {
|
||||
segment?.identify(userId: userID)
|
||||
posthog?.identify(userID)
|
||||
}
|
||||
|
||||
public static func recordUserTraits(userID: String, traits: [String: String]) {
|
||||
segment?.identify(userId: userID, traits: traits)
|
||||
public static func reset() {
|
||||
posthog?.reset()
|
||||
}
|
||||
}
|
||||
|
||||
private let segment: Analytics? = {
|
||||
guard let writeKey = AppKeys.sharedInstance?.segmentClientKey else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let config = Configuration(writeKey: writeKey)
|
||||
.flushAt(20) // default is 20
|
||||
.trackApplicationLifecycleEvents(true) // default is true
|
||||
.autoAddSegmentDestination(true) // default is true
|
||||
.flushInterval(30) // default is 30 seconds
|
||||
.trackDeeplinks(true) // default is true
|
||||
|
||||
return Analytics(configuration: config)
|
||||
}()
|
||||
|
||||
@ -6,7 +6,8 @@ public struct AppKeys: Decodable {
|
||||
public let firebaseDemoKeys: FirebaseKeys?
|
||||
public let firebaseProdKeys: FirebaseKeys?
|
||||
public let iosClientGoogleId: String?
|
||||
public let segmentClientKey: String?
|
||||
public let posthogClientKey: String?
|
||||
public let posthogInstanceAddress: String?
|
||||
public static let sharedInstance = AppKeys.make()
|
||||
|
||||
private init() {
|
||||
@ -15,7 +16,8 @@ public struct AppKeys: Decodable {
|
||||
self.firebaseDemoKeys = nil
|
||||
self.firebaseProdKeys = nil
|
||||
self.iosClientGoogleId = nil
|
||||
self.segmentClientKey = nil
|
||||
self.posthogClientKey = nil
|
||||
self.posthogInstanceAddress = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,8 +42,6 @@ private let logger = Logger(subsystem: "app.omnivore", category: "app-delegate")
|
||||
}
|
||||
#endif
|
||||
|
||||
EventTracker.start()
|
||||
|
||||
if let intercomKeys = AppKeys.sharedInstance?.intercom {
|
||||
Intercom.setApiKey(intercomKeys.apiKey, forAppId: intercomKeys.appID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user