Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ open class AppEnvironment {
public var lastLoginAccount: APIAccountResult?
public let k5 = K5State()
public weak var loginDelegate: LoginDelegate?
public var userDidLogin: (() -> Void)?

public weak var window: UIWindow?
open var isTest: Bool { false }
private var subscriptions = Set<AnyCancellable>()
Expand Down
10 changes: 10 additions & 0 deletions Horizon/Horizon/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
<string>canvas-Horizon</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>pendo-pairing-horizon</string>
<key>CFBundleURLSchemes</key>
<array>
<string>pendo-9f913bef</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
Expand Down
55 changes: 55 additions & 0 deletions Horizon/Horizon/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

import Combine
import Core
import HorizonUI
import UIKit
Expand All @@ -25,15 +26,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AppEnvironmentDelegate {
var window: UIWindow?

private let sessionInteractor = SessionInteractor()
private lazy var analyticsTracker: PendoAnalyticsTracker = .init(environment: environment)

lazy var environment: AppEnvironment = {
let env = AppEnvironment.shared
env.loginDelegate = sessionInteractor
env.router = Router(routes: HorizonRoutes.routeHandlers())
env.app = .horizon
env.window = window
env.userDidLogin = userDidLogin
return env
}()

private var subscriptions = Set<AnyCancellable>()

func application(
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
Expand Down Expand Up @@ -66,4 +72,53 @@ extension AppDelegate {
func application(_: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
AppEnvironment.shared.reportError(error)
}

func application(_: UIApplication, open url: URL, options _: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if url.scheme?.range(of: "pendo") != nil {
analyticsTracker.initManager(with: url)
return true
}
return false
}
}

// MARK: - Usage Analytics

extension AppDelegate: Core.AnalyticsHandler {
func userDidLogin() {
initializeTracking()
}

func handleEvent(_ name: String, parameters: [String: Any]?) {
analyticsTracker.track(name, properties: parameters)

PageViewEventController.instance.logPageView(
name,
attributes: parameters
)
}

private func initializeTracking() {
guard !ProcessInfo.isUITest else { return }

ReactiveStore(
useCase: GetEnvironmentFeatureFlags(context: Context.currentUser)
)
.getEntities()
.replaceError(with: [])
.sink { [weak self] environmentFeatureFlags in
let isTrackingEnabled = environmentFeatureFlags.isFeatureEnabled(.send_usage_metrics)

if isTrackingEnabled {
self?.analyticsTracker.startSession()
} else {
self?.analyticsTracker.endSession()
}
}
.store(in: &subscriptions)
}

private func disableTracking() {
analyticsTracker.endSession()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class SplashViewModel: ObservableObject {
isLoginTransition: true,
viewController: HorizonTabBarController()
)
environment.userDidLogin?()
UIApplication.shared.registerForPushNotifications()
})
.store(in: &subscriptions)
Expand Down