Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyticsv2 PoC #169

Merged
merged 13 commits into from
May 21, 2024
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 @@ -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
}
Comment on lines -33 to -35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all view functions were removed in favor of navigatePage analytics v2 event


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?
Copy link
Contributor Author

@mike-dydx mike-dydx May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracking data moved into ScreenIdentifiable (effectively)

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)
}
Comment on lines -454 to -456
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions should not be view events, should be dedicated action events. Did not make scope for this PR

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
}
}
Comment on lines -475 to -481
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrackingData was removed in this PR, functionality was replaced


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)
}
Comment on lines -290 to -300
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were logging a view event both here and in the viewDidAppear lifecycle method which resulted in double logging. Removed logging from within Routing Kit in favor of TrackingViewController lmk if u disagree with this decision or if i am missing something

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
Loading