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

analyticsv2 PoC #169

merged 13 commits into from
May 21, 2024

Conversation

mike-dydx
Copy link
Contributor

@mike-dydx mike-dydx commented May 16, 2024

Description / Intuition

note this is a proof of concept, serves as a starting point to replace all events in the app with a more organized, enumerated set of events.

  • introduces dydxAnalytics module
  • introduces AnalyticsEventV2 which is a more prescribed way to log events with metadata.
  • removes view functions across the project in favor of logging new navigatePage(screen:) event (see comments)
  • replaces notification/deeplink event with an event name that more closely follows other non-screen view event standards
  • adds default mobile_path to navigatePage events so that all view controller navigations have at least that. path is reserved for the case when there is a directly corresponding web url path.

Before/After Screenshots or Videos

Before After
rec.mov

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • [x[ New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring or Technical Debt
  • Documentation update
  • Other (please describe: )

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from bae30e4 to dad49a5 Compare May 16, 2024 20:16
@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from 6814a5a to d722c9b Compare May 17, 2024 15:51
Comment on lines -33 to -35
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
}
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

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from 140e99f to 48a7ca2 Compare May 17, 2024 18:31
@@ -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)

Comment on lines -454 to -456
if success, request.path?.hasPrefix("/action") ?? false {
Tracking.shared?.view(request.path, data: request.params, from: nil, time: nil)
}
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

Comment on lines -475 to -481
override open func previousTracking() -> TrackingData? {
if let vc = UIViewController.topmost() as? TrackingViewProtocol {
return vc.trackingData
} else {
return nil
}
}
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

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

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch 2 times, most recently from a713e01 to 774547b Compare May 17, 2024 18:39
Comment on lines 72 to 76
case appStart
case navigatePage(screen: ScreenIdentifiable)
case deepLinkHandled(url: String, succeeded: Bool)
case notificationPermissionsChanged(isAuthorized: Bool)
case onboardingStepChanged(step: OnboardingStep, state: OnboardingState)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note these 5 events are just a proof of concept for how this enum would work for all events. see the TODO on ln 71

@@ -0,0 +1,35 @@
//
// OnboardingAnalytics.swift
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file was just moved from dydxPresenters to here

@@ -9,12 +9,15 @@ import Foundation
import Abacus
import Utilities

final class TransferAnalytics {
func logDeposit(transferInput: TransferInput) {
public final class TransferAnalytics {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file was also just moved from dydxPresenters to here

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch 2 times, most recently from da1a058 to b04643f Compare May 17, 2024 18:43
Comment on lines -107 to -117
if let transformed = transform(events: onboardingEvents, path: path), let event = parser.asString(transformed["event"]) {
var info = parser.asDictionary(transformed["info"]) ?? data ?? [String: Any]()
if event == "OnboardingStepChanged" {
if let time = time, let previous = transform(events: onboardingEvents, path: from), parser.asString(transformed["event"]) == "OnboardingStepChanged" {
let seconds = Int(Date().timeIntervalSince(time))
info["secondsOnPreviousStep"] = NSNumber(value: seconds)
info["previousStep"] = (previous["info"] as? [String: Any])?["currentStep"]
}
}
log(event: event, data: info, revenue: revenue)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this functionality was not doing anything, the custom data is nowhere to be found in bigquery. OnboardingStepChanged event is still logged in other files though via the OnboardingAnalytics class. That functionality did not change

Comment on lines -101 to -104
log(event: AnalyticsEventScreenView,
data: [
AnalyticsParameterScreenName: path as Any,
AnalyticsParameterScreenClass: String(describing: type(of: contextViewController))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this logic was moved to AnalyticsEvent.swift

@@ -0,0 +1,59 @@
//
// TrackingViewController+Ext.swift
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this files serves the purpose of creating paths to identify the screen based on RoutingRequest data.

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

Choose a reason for hiding this comment

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

condensed into a single event with an event name instead of a path. Lmk if u disagree with this decision

@@ -13,6 +13,7 @@ import RoutingKit
import ParticlesKit
import PlatformUI
import dydxCartera
import dydxAnalytics
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these import statements are necessary because some classes were moved into dydxAnalytics

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from b04643f to 33cdd69 Compare May 17, 2024 18:53
@mike-dydx mike-dydx requested a review from ruixhuang May 17, 2024 18:57
@mike-dydx mike-dydx marked this pull request as ready for review May 17, 2024 18:57
case notificationPermissionsChanged(isAuthorized: Bool)
case onboardingStepChanged(step: OnboardingStep, state: OnboardingState)

public var name: String {
Copy link
Contributor

Choose a reason for hiding this comment

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

The long switch statement can be messy when more events are added. Maybe it's cleaner to define each event as a separate struct, e.g.,

struct NavigatePageEvent:  TrackableEvent {
  let screen: ScreenIdentifiable
  
  override var name: String ...
  
}

ruixhuang
ruixhuang previously approved these changes May 20, 2024
@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from 8e2dbc4 to 6bb5c99 Compare May 21, 2024 00:57
return "OnboardingStepChanged"
case .notificationPermissionsChanged:
return "NotificationPermissionsChanged"
public enum AnalyticsEventV2 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ruixhuang note I am nesting them in AnalyticsEventV2 so that we can use Xcode's autofill after typing AnalyticsEventV2., also to keep them contained. Lmk if u think this is not worth it and I can put them at the global level.

Comment on lines 22 to 24
// func log(trackableEvent: TrackableEvent) {
// log(event: trackableEvent.name, data: trackableEvent.customParameters, revenue: nil)
// }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted this in another commit 😓

@mike-dydx mike-dydx force-pushed the mike/fix-analytics-paths branch from e785940 to fd4206b Compare May 21, 2024 01:02
@mike-dydx mike-dydx merged commit 3740d9a into develop May 21, 2024
2 checks passed
@mike-dydx mike-dydx deleted the mike/fix-analytics-paths branch May 21, 2024 17:28
mike-dydx added a commit that referenced this pull request Aug 20, 2024
* 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
mike-dydx added a commit that referenced this pull request Aug 21, 2024
* 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
mike-dydx added a commit that referenced this pull request Aug 21, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants