Skip to content

Commit

Permalink
interim commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed May 17, 2024
1 parent afd52e5 commit d722c9b
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import PlatformRouting
import UIToolkits
import Utilities

open class TrackingViewController: NavigableViewController, TrackingViewProtocol {

open private(set) var navigationEvent: TrackableEvent?
open class TrackingViewController: NavigableViewController {

override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
Expand All @@ -25,8 +23,8 @@ open class TrackingViewController: NavigableViewController, TrackingViewProtocol
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if let navigationEvent {
Tracking.shared?.log(trackableEvent: navigationEvent)
if let self = self as? TrackingViewProtocol {
self.logScreenView()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,6 @@ open class MappedUIKitRouter: MappedRouter {
self?.actions.removeAll(where: { (actionInList) -> Bool in
actionReference === actionInList
})
if success, request.path?.hasPrefix("/action") ?? false {
Tracking.shared?.view(request.path, data: request.params, from: nil, time: nil)
}
completion?(data, success)
}
} else {
Expand Down
6 changes: 0 additions & 6 deletions Utilities/Utilities/_Tracker/_Shared/CompositeTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ open class CompositeTracking: NSObject & TrackingProtocol {
}
}

open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
for tracking: TrackingProtocol in trackings {
tracking.view(path, action: action, data: data, from: from, time: time, revenue: revenue, contextViewController: nil)
}
}

open func leave(_ path: String?) {
for tracking: TrackingProtocol in trackings {
tracking.leave(path)
Expand Down
44 changes: 26 additions & 18 deletions Utilities/Utilities/_Tracker/_Shared/Tracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import Foundation
public protocol TrackingProtocol: NSObjectProtocol {
var userInfo: [String: String?]? { get set }
var excluded: Bool { get set }
func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?)
// func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?)
func leave(_ path: String?)
func log(event: String, data: [String: Any]?, revenue: NSNumber?)
}

public extension TrackingProtocol {
func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
view(path, action: nil, data: data, from: from, time: time, revenue: revenue, contextViewController: contextViewController)
}
func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
view(path, action: nil, data: data, from: from, time: time, revenue: revenue, contextViewController: nil)
}
func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?) {
view(path, action: nil, data: data, from: from, time: time, revenue: nil, contextViewController: nil)
}
func view(_ path: String?, data: [String: Any]?, from: String?, contextViewController: UIViewController?) {
view(path, action: nil, data: data, from: from, time: nil, revenue: nil, contextViewController: nil)
}
func view(_ path: String?, data: [String: Any]?) {
view(path, action: nil, data: data, from: nil, time: nil, revenue: nil, contextViewController: nil)
}
// func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
// view(path, action: nil, data: data, from: from, time: time, revenue: revenue, contextViewController: contextViewController)
// }
// func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
// view(path, action: nil, data: data, from: from, time: time, revenue: revenue, contextViewController: nil)
// }
// func view(_ path: String?, data: [String: Any]?, from: String?, time: Date?) {
// view(path, action: nil, data: data, from: from, time: time, revenue: nil, contextViewController: nil)
// }
// func view(_ path: String?, data: [String: Any]?, from: String?, contextViewController: UIViewController?) {
// view(path, action: nil, data: data, from: from, time: nil, revenue: nil, contextViewController: nil)
// }
// func view(_ path: String?, data: [String: Any]?) {
// view(path, action: nil, data: data, from: nil, time: nil, revenue: nil, contextViewController: nil)
// }
func log(event: String, data: [String: Any]?) {
log(event: event, data: data, revenue: nil)
}
Expand All @@ -55,6 +55,14 @@ public protocol TrackableEvent {
var customParameters: [String: Any] { get }
}

public protocol TrackingViewProtocol {
var navigationEvent: TrackableEvent? { get }
public protocol TrackingViewProtocol: ScreenIdentifiable {
func logScreenView()
}

public protocol ScreenIdentifiable {
/// the path identifier specific to mobile
var mobilePath: String { get }
/// the web path identifier which corresponds to the mobile screen
var correspondingWebPath: String? { get }
var screenClass: String { get }
}
11 changes: 1 addition & 10 deletions dydx/dydx.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "975d00e29efb8d2ca017c5e61df90418ac01f7d7143e85a3f9ddb4eb982154e4",
"originHash" : "1c0055be4aba3ed4d97a2f62f05486877839310f65e2cbdd18b067bef06a04a3",
"pins" : [
{
"identity" : "bigint",
Expand Down Expand Up @@ -46,15 +46,6 @@
"revision" : "48134b5460435cc9d048223ad7560ee2e40f3d4a"
}
},
{
"identity" : "percy-xcui-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/percy/percy-xcui-swift",
"state" : {
"revision" : "a2e9a86dfc3f5b69ef53cbda28a0ea71098c9f77",
"version" : "1.0.0"
}
},
{
"identity" : "qrcode",
"kind" : "remoteSourceControl",
Expand Down
86 changes: 32 additions & 54 deletions dydx/dydxAnalytics/dydxAnalytics/AnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import Foundation
import PlatformParticles
import Utilities
import FirebaseAnalytics

//
// Events defined in the v4-web repo. Ideally, we should keep this in-sync with v4-web
//
Expand Down Expand Up @@ -47,48 +49,6 @@ public enum AnalyticsEvent: String {
case notificationAction = "NotificationAction"
}

public extension AnalyticsEventV2 {
// probably move this to like a dydxRouter, next to where `routing_swift.json` currently lives
enum Page {
case markets
case market(market: String)
case trade(market: String)
case addSlTp
case custom(path: String)

/// a path that uniquely identifies the mobile screen
var mobilePath: String {
switch self {
case .markets:
return "/markets"
case .trade(let market):
return "/trade/\(market)"
case .market(let market):
return "/market/\(market)"
case .addSlTp:
return "/trade/take_profit_stop_loss"
case .custom(let path):
return path
}
}

/// the web-equivalent web page (if there is a good match)
var correspondingWebPath: String? {
switch self {
case .addSlTp:
return nil // displayed as a modal on web
case .custom:
return nil
case .market(let market):
// web does not have the /market/ETH-USD path and routes back to `/trade/ETH-USD`
return Page.trade(market: market).correspondingWebPath
default:
return mobilePath
}
}
}
}

public extension AnalyticsEventV2 {
enum OnboardingStep: String {
case chooseWallet = "ChooseWallet"
Expand All @@ -108,47 +68,65 @@ public extension AnalyticsEventV2 {

public enum AnalyticsEventV2: TrackableEvent {
case appStart
case navigatePage(page: Page)
case navigateDialog(page: Page)
case navigateDialogClose(page: Page)
case navigatePage(screen: ScreenIdentifiable)
case deepLinkHandled(url: String, succeeded: Bool)
case notificationPermissionsChanged(isAuthorized: Bool)
case onboardingStepChanged(step: OnboardingStep, state: OnboardingState)

public var name: String {
switch self {
case .navigatePage:
return "NavigatePage"
case .navigateDialog:
return "NavigateDialog"
case .navigateDialogClose:
return "NavigateDialogClose"
case .deepLinkHandled:
return "DeeplinkHandled"
case .appStart:
return "AppStart"
case .onboardingStepChanged:
return "OnboardingStepChanged"
case .notificationPermissionsChanged:
return "NotificationPermissionsChanged"
}
}

public var customParameters: [String: Any] {
switch self {
case .appStart:
return [:]
case .navigatePage(let page), .navigateDialog(let page), .navigateDialogClose(let page):
case .navigatePage(let screen):
return [
"mobile_path": screen.mobilePath,
"path": screen.correspondingWebPath as Any,
// for firebase auto-generated dashboard(s)
"\(AnalyticsParameterScreenClass)": screen.screenClass,
"\(AnalyticsParameterScreenName)": screen.mobilePath
]
case .deepLinkHandled(let url, let succeeded):
return [
"mobile_path": page.mobilePath,
"path": page.correspondingWebPath as Any
"successfully_handled": succeeded,
"url": url
]
case .onboardingStepChanged(let step, let state):
return [
"step": step.rawValue,
"state": state.rawValue
]
case .notificationPermissionsChanged(let isAuthorized):
return [
"is_authorized": isAuthorized
]
}
}
}

public extension TrackingProtocol {
/// convenience wrapper of log(trackableEvent:)
func log(event: AnalyticsEventV2) {
Tracking.shared?.log(trackableEvent: event)
log(event: event.name, data: event.customParameters)
switch event {
case .navigatePage:
// for firebase auto-generated dashboard(s)
log(event: AnalyticsEventScreenView, data: event.customParameters)
default:
break
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ private class dydxMarketInfoViewController: HostingViewController<PlatformView,
history?.params?["market"] as? String ?? dydxSelectedMarketsStore.shared.lastSelectedMarket
}

override var navigationEvent: TrackableEvent? {
// only count navigation event if trade input is not immediately displayed
if history?.path == "/market" {
return AnalyticsEventV2.navigatePage(page: .market(market: selectedMarketId))
} else if history?.path == "/trade" {
return AnalyticsEventV2.navigatePage(page: .trade(market: selectedMarketId))
}
return nil
}

override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
if request?.path == "/trade" || request?.path == "/market", let presenter = presenter as? dydxMarketInfoViewPresenter {
dydxSelectedMarketsStore.shared.lastSelectedMarket = selectedMarketId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class dydxMarketsViewBuilder: NSObject, ObjectBuilderProtocol {
}

private class dydxMarketsViewController: HostingViewController<PlatformView, dydxMarketsViewModel> {

override var navigationEvent: TrackableEvent? { AnalyticsEventV2.navigatePage(page: .markets) }

override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
request?.path == "/markets"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class dydxTakeProfitStopLossViewBuilder: NSObject, ObjectBuilderProtocol
}

private class dydxTakeProfitStopLossViewController: HostingViewController<PlatformView, dydxTakeProfitStopLossViewModel> {
override var navigationEvent: TrackableEvent? { AnalyticsEventV2.navigatePage(page: .addSlTp) }

override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
if request?.path == "/trade/take_profit_stop_loss", let marketId = parser.asString(request?.params?["marketId"]), let presenter = presenter as? dydxTakeProfitStopLossViewPresenter {
AbacusStateManager.shared.setMarket(market: marketId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public struct HostingViewControllerConfiguration {

open class HostingViewController<V: View, VM: PlatformViewModel>: TrackingViewController, UIViewControllerEmbeddingProtocol {

open override var navigationEvent: TrackableEvent? {
guard let path = history?.path else { assertionFailure("no path?"); return nil }
return AnalyticsEventV2.navigatePage(page: .custom(path: path))
}

private var hostingController: UIHostingController<AnyView>?
private let presenterView = ObjectPresenterView()
private var configuration: HostingViewControllerConfiguration = .default
Expand Down
4 changes: 4 additions & 0 deletions dydxV4/dydxV4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
02FF092F29ADBD9F00781EDA /* dydxChart.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 029E11EB29ADB9BC00FE271C /* dydxChart.framework */; };
02FF093029ADBDA300781EDA /* dydxPresenters.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0293B66528CE94E200DDB103 /* dydxPresenters.framework */; };
274F43062BA4C0B400645059 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 274F43052BA4C0B400645059 /* PrivacyInfo.xcprivacy */; };
27968BA92BF7AC7A002F2C34 /* TrackingViewController+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27968BA82BF7AC7A002F2C34 /* TrackingViewController+Ext.swift */; };
27ADEE6C2BC4A23400B8F1DB /* dydxSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ADEE6B2BC4A23400B8F1DB /* dydxSettingsStore.swift */; };
27D41AF12A8E9214009A2F37 /* UIApplication+URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27D41AF02A8E9214009A2F37 /* UIApplication+URLHandler.swift */; };
27DBDD222A8FF5B2002383C6 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 27DBDCED2A8FF5B2002383C6 /* GoogleService-Info.plist */; };
Expand Down Expand Up @@ -798,6 +799,7 @@
02E7DD9A28CFB31000727949 /* dydxStateManager.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = dydxStateManager.xcodeproj; path = ../dydx/dydxStateManager/dydxStateManager.xcodeproj; sourceTree = "<group>"; };
171807B0CCAE5C86B5D65793 /* Pods_iOS_dydxV4.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iOS_dydxV4.framework; sourceTree = BUILT_PRODUCTS_DIR; };
274F43052BA4C0B400645059 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
27968BA82BF7AC7A002F2C34 /* TrackingViewController+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrackingViewController+Ext.swift"; sourceTree = "<group>"; };
27ADEE6B2BC4A23400B8F1DB /* dydxSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxSettingsStore.swift; sourceTree = "<group>"; };
27D41AF02A8E9214009A2F37 /* UIApplication+URLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+URLHandler.swift"; sourceTree = "<group>"; };
27DBDCED2A8FF5B2002383C6 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1292,6 +1294,7 @@
children = (
64AF4810281880B100EBFDC6 /* dydxAmplitudeTracking.swift */,
02C7262A29D793C90098AFBC /* dydxCompositeTracking.swift */,
27968BA82BF7AC7A002F2C34 /* TrackingViewController+Ext.swift */,
);
path = _Tracking;
sourceTree = "<group>";
Expand Down Expand Up @@ -2317,6 +2320,7 @@
27D41AF12A8E9214009A2F37 /* UIApplication+URLHandler.swift in Sources */,
02756A6A287CA33E00803741 /* dydxNotificationHandlerDelegate.swift in Sources */,
3112F463216BBF8400708927 /* AppDelegate.swift in Sources */,
27968BA92BF7AC7A002F2C34 /* TrackingViewController+Ext.swift in Sources */,
27ADEE6C2BC4A23400B8F1DB /* dydxSettingsStore.swift in Sources */,
3101FC582511508800AC4010 /* CommonAppDelegate.swift in Sources */,
0217A0A129D78BD5007F31C5 /* dydxBiometricsLocalAuthenticator.swift in Sources */,
Expand Down
11 changes: 2 additions & 9 deletions dydxV4/dydxV4/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import RoutingKit
import UIAppToolkits
import UIToolkits
import Utilities
import dydxAnalytics

#if _iOS
import FirebaseStaticInjections
Expand Down Expand Up @@ -143,15 +144,7 @@ class AppDelegate: CommonAppDelegate {
}

override func deepLinkHandled(deeplink: URL, successful: Bool) {
let data = ["url": deeplink.absoluteString]
if successful {
if let type = deeplink.params?["notification_type"] {
Tracking.shared?.view("/notification/deeplink/" + type, data: data)
}
Tracking.shared?.view("/notification/deeplink/success", data: data)
} else {
Tracking.shared?.view("/notification/deeplink/failure", data: data)
}
Tracking.shared?.log(event: .deepLinkHandled(url: deeplink.absoluteString, succeeded: successful))
}

/// Prioritized CoinbaseWalletSDK handling of the deeplink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Utilities
import FirebaseMessaging
import dydxAnalytics

final class dydxNotificationHandlerDelegate: NSObject, NotificationHandlerDelegate {

Expand Down Expand Up @@ -62,14 +63,14 @@ final class dydxNotificationHandlerDelegate: NSObject, NotificationHandlerDelega
if lastPermission != permission {
if permission == .denied {
if lastPermission == .notDetermined || lastPermission == .authorized {
Tracking.shared?.view("/notification/switch/denied", data: nil, from: nil, time: nil)
Tracking.shared?.log(event: .notificationPermissionsChanged(isAuthorized: false))
}
if lastPermission == .authorized {
// sendTokenDeletion()
}
} else if permission == .authorized {
if lastPermission == .notDetermined || lastPermission == .denied {
Tracking.shared?.view("/notification/switch/authorized", data: nil, from: nil, time: nil)
Tracking.shared?.log(event: .notificationPermissionsChanged(isAuthorized: true))
}
// sendTokenUpdate()
}
Expand Down
Loading

0 comments on commit d722c9b

Please sign in to comment.