Skip to content

Commit

Permalink
analyticsv2 PoC (#169)
Browse files Browse the repository at this point in the history
* analyticsv2 example

* added dydxAnalytics

* move files into dydxAnalytics

* add default events

* remove duplicative tracking

* example replacement of app start event

* add firebase to dydxAnalytics

* interim commit

* remove view(...) functions

* sorting by name

* clean up

* address comment, make events unique structs

* clean up
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent 5a57fd1 commit 8ef5c01
Show file tree
Hide file tree
Showing 83 changed files with 24,600 additions and 15,290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public class AppsFlyerTracking: TransformerTracker {
}
}

override open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
// Only track the ones required by growth
}

override public func log(event: String, data: [String: Any]?, revenue: NSNumber?) {
if !excluded {
var data = data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ open class TransformerTracker: NSObject & TrackingProtocol {
}
}

open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
if !excluded {
if let path = transform(path: path)?.trim() {
if let action = action {
log(event: "\(path)_\(action)", data: data, revenue: revenue)
} else {
log(event: path, data: data, revenue: revenue)
}
}
}
}

open func leave(_ path: String?) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,25 @@ import PlatformRouting
import UIToolkits
import Utilities

open class TrackingViewController: NavigableViewController, TrackingViewProtocol {
public var trackingData: TrackingData?
open class TrackingViewController: NavigableViewController {

override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
navigationController?.navigationBar.setNeedsLayout()
}
}

override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

logView(path: history?.path, data: history?.params, from: nil, time: nil)
}


override open func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
Tracking.shared?.leave(trackingData?.path)
trackingData = nil
Tracking.shared?.leave(history?.path)
}

open func logView(path: String?, data: [String: Any]?, from: String?, time: Date?) {
if let path = path, trackingData?.path != path {
trackingData = TrackingData(path: path, data: data)
Tracking.shared?.view(path, data: data, from: from, time: time, revenue: nil, contextViewController: self)
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if let self = self as? TrackingViewProtocol {
self.logScreenView()
}
}
}
11 changes: 0 additions & 11 deletions PlatformRouting/PlatformRouting/_iOS/_App/MappedUIKitRouter.swift
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 All @@ -471,14 +468,6 @@ open class MappedUIKitRouter: MappedRouter {
completion(nil)
}
}

override open func previousTracking() -> TrackingData? {
if let vc = UIViewController.topmost() as? TrackingViewProtocol {
return vc.trackingData
} else {
return nil
}
}

private func loadViewController(from map: RoutingMap, completion: @escaping ((UIViewController?) -> Void)) {
if let builder = map.builder {
Expand Down
11 changes: 0 additions & 11 deletions RoutingKit/RoutingKit/_Router/MappedRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
}
}

open func previousTracking() -> TrackingData? {
return nil
}

open func reallyNavigate(to request: RoutingRequest, presentation: RoutingPresentation?, animated: Bool, completion: RoutingCompletionBlock?) {
if let path = request.path {
Console.shared.log("Route to \(path)")
Expand All @@ -284,20 +280,13 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser
} else {
let transformed = transform(request: request)
if let map = self.map(for: transformed) {
let previousTracking = previousTracking()
backtrack(request: transformed, animated: animated) { [weak self] data, completed in
if completed {
if let viewController = data as? TrackingViewProtocol {
viewController.logView(path: transformed.path, data: nil, from: previousTracking?.path, time: previousTracking?.startTime)
}
completion?(nil, true)
} else {
self?.route(dependencies: map, request: transformed, completion: { [weak self] _, successful in
if successful {
self?.navigate(to: map, request: transformed, presentation: presentation ?? transformed.presentation, animated: animated, completion: { /* [weak self] */ data, successful in
if successful, let viewController = data as? TrackingViewProtocol {
viewController.logView(path: transformed.path, data: nil, from: previousTracking?.path, time: previousTracking?.startTime)
}
completion?(data, successful)
})
} else {
Expand Down
3 changes: 2 additions & 1 deletion Shared/CommonAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AppsFlyerStaticInjections
import FirebaseStaticInjections
import dydxStateManager
import dydxViews
import dydxAnalytics

open class CommonAppDelegate: ParticlesAppDelegate {
open var notificationTag: String {
Expand Down Expand Up @@ -169,7 +170,7 @@ open class CommonAppDelegate: ParticlesAppDelegate {

open override func applicationDidBecomeActive(_ application: UIApplication) {
super.applicationDidBecomeActive(application)
Tracking.shared?.log(event: "AppStart", data: nil)
Tracking.shared?.log(event: AnalyticsEventV2.AppStart())
dydxRatingService.shared?.launchedApp()
}

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
12 changes: 0 additions & 12 deletions Utilities/Utilities/_Tracker/_Shared/DebugTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ public class DebugTracking: NSObject & TrackingProtocol {
public var userInfo: [String: String?]?

public var excluded: Bool = false

public func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
if let path = path {
let action = action ?? ""
let from = from ?? ""
if excluded {
Console.shared.log("Debug Tracking: View Excluded Path:\(path) Action:\(action) From:\(from)", data ?? "")
} else {
Console.shared.log("Debug Tracking: View Path:\(path) Action:\(action) From:\(from)", data ?? "")
}
}
}

public func leave(_ path: String?) {
if let path = path {
Expand Down
45 changes: 18 additions & 27 deletions Utilities/Utilities/_Tracker/_Shared/Tracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,11 @@ 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 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 log(event: String, data: [String: Any]?) {
log(event: event, data: data, revenue: nil)
}
Expand All @@ -47,19 +31,26 @@ public class Tracking {
public static var shared: TrackingProtocol?
}

public class TrackingData {
public var path: String
public var data: [String: Any]?
public var startTime: Date
public protocol TrackableEvent: CustomStringConvertible {
var name: String { get }
var customParameters: [String: Any] { get }
}

public init(path: String, data: [String: Any]?) {
self.path = path
self.data = data
startTime = Date()
public extension TrackableEvent {
var description: String {
let sorted = customParameters.sorted { $0.key < $1.key }
return "dydxAnalytics event \(name) with data: \(sorted)"
}
}

public protocol TrackingViewProtocol {
var trackingData: TrackingData? { get }
func logView(path: String?, data: [String: Any]?, from: String?, time: Date?)
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 }
}
7 changes: 7 additions & 0 deletions dydx/PodFile
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ abstract_target 'iOS' do
ios_ui_pods
swifiui_pods
end

target 'dydxAnalytics' do
project '../dydx/dydxAnalytics/dydxAnalytics'
firebase_core_pods
ios_util_pods
abacus_pods
end

target 'dydxPresenters' do
project '../dydx/dydxPresenters/dydxPresenters'
Expand Down
2 changes: 1 addition & 1 deletion dydx/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,6 @@ SPEC CHECKSUMS:
Validator: 80a6f567220c962dfd2d9928ae98a8c1d164f6f4
ZSWTappableLabel: 92f11d677bb395a8294df48482316c4981783ca0

PODFILE CHECKSUM: e6f17a3740fec78173732202f4a12a9dd7ed9e8e
PODFILE CHECKSUM: f1277090c844566f744195caf9d281564bb8957c

COCOAPODS: 1.15.2
41 changes: 0 additions & 41 deletions dydx/Pods/Local Podspecs/MagicSDK.podspec.json

This file was deleted.

Loading

0 comments on commit 8ef5c01

Please sign in to comment.