Skip to content

Commit

Permalink
add screen_view event for better firebase analytics integration (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Mar 6, 2024
1 parent 04b2381 commit f054cc2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AppsFlyerTracking: TransformerTracker {
}
}

override open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ParticlesKit
import Utilities

open class TransformerTracker: NSObject & TrackingProtocol {

open var userInfo: [String: String?]?

public var excluded: Bool = false
Expand All @@ -25,7 +26,7 @@ open class TransformerTracker: NSObject & TrackingProtocol {
}
}

open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class TrackingViewController: NavigableViewController, TrackingViewProtocol
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)
Tracking.shared?.view(path, data: data, from: from, time: time, revenue: nil, contextViewController: self)
}
}
}
4 changes: 2 additions & 2 deletions Utilities/Utilities/_Tracker/_Shared/CompositeTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ open class CompositeTracking: NSObject & TrackingProtocol {
}
}

open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
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)
tracking.view(path, action: action, data: data, from: from, time: time, revenue: revenue, contextViewController: nil)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Utilities/Utilities/_Tracker/_Shared/DebugTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DebugTracking: NSObject & TrackingProtocol {

public var excluded: Bool = false

public func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
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 ?? ""
Expand Down
15 changes: 9 additions & 6 deletions Utilities/Utilities/_Tracker/_Shared/Tracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ 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?)
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)
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)
view(path, action: nil, data: data, from: from, time: time, revenue: nil, contextViewController: nil)
}
func view(_ path: String?, data: [String: Any]?, from: String?) {
view(path, action: nil, data: data, from: from, time: nil, revenue: 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)
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 Down
3 changes: 2 additions & 1 deletion dydxV4/dydxV4/_Tracking/dydxAmplitudeTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
//

import AmplitudeInjections
import UIKit

public class dydxAmplitudeTracking: AmplitudeTracking {
override open func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
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
}

Expand Down
15 changes: 12 additions & 3 deletions dydxV4/dydxV4/_Tracking/dydxCompositeTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Utilities
import dydxStateManager
import Combine
import Cartera
import FirebaseAnalytics

enum UserProperty: String {
case walletAddress
Expand Down Expand Up @@ -79,13 +80,21 @@ public class dydxCompositeTracking: CompositeTracking {



override public func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?) {
override public func view(_ path: String?, action: String?, data: [String: Any]?, from: String?, time: Date?, revenue: NSNumber?, contextViewController: UIViewController?) {
if let transformed = transform(events: viewEvents, path: path), let event = parser.asString(transformed["event"]) {
super.view(path, action: action, data: data, from: from, time: time, revenue: nil)
super.view(path, action: action, data: data, from: from, time: time, revenue: nil, contextViewController: contextViewController)
let info = parser.asDictionary(transformed["info"]) ?? data ?? [String: Any]()
log(event: event, data: info, revenue: revenue)
} else {
super.view(path, action: action, data: data, from: from, time: time, revenue: revenue)
super.view(path, action: action, data: data, from: from, time: time, revenue: revenue, contextViewController: contextViewController)
}
if let contextViewController {

log(event: AnalyticsEventScreenView,
data: [
AnalyticsParameterScreenName: path as Any,
AnalyticsParameterScreenClass: String(describing: type(of: contextViewController))
])
}
if let transformed = transform(events: onboardingEvents, path: path), let event = parser.asString(transformed["event"]) {
var info = parser.asDictionary(transformed["info"]) ?? data ?? [String: Any]()
Expand Down

0 comments on commit f054cc2

Please sign in to comment.