Skip to content

Commit

Permalink
šŸ”€ļø Merge branch 'ladislaas/feature/analytics-events-add-enum' into deā€¦
Browse files Browse the repository at this point in the history
ā€¦velop
  • Loading branch information
ladislas committed Nov 22, 2024
2 parents af0841a + cd34925 commit db73950
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public extension AnalyticsManager {
"lk_carereceiver_ids": carereceiverIDs,
].merging(parameters) { _, new in new }

Self.logEvent(name: "activity_start", parameters: params)
Self.logEvent(.activityStart, parameters: params)
}

static func logEventActivityEnd(
Expand All @@ -32,6 +32,6 @@ public extension AnalyticsManager {
"lk_activity_end_reason": reason.rawValue,
].merging(parameters) { _, new in new }

Self.logEvent(name: "activity_end", parameters: params)
Self.logEvent(.activityEnd, parameters: params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public extension AnalyticsManager {
"new_version": newVersion,
].merging(parameters) { _, new in new }

Self.logEvent(name: "app_update_skip", parameters: params)
Self.logEvent(.appUpdateSkip, parameters: params)
}

// TODO: (@ladislas) add real versions
Expand All @@ -22,6 +22,6 @@ public extension AnalyticsManager {
"new_version": newVersion,
].merging(parameters) { _, new in new }

Self.logEvent(name: "app_update_open_app_store", parameters: params)
Self.logEvent(.appUpdateOpenAppStore, parameters: params)
}
}
10 changes: 5 additions & 5 deletions Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ public extension AnalyticsManager {
static func logEventLogin(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: AnalyticsEventLogin, parameters: params)
Self.logEvent(.login, parameters: params)
}

static func logEventLogout(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: "logout", parameters: params)
Self.logEvent(.logout, parameters: params)
}

static func logEventSignUp(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: AnalyticsEventSignUp, parameters: params)
Self.logEvent(.signup, parameters: params)
}

static func logEventSkipAuthentication(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: "skip_authentication", parameters: params)
Self.logEvent(.skipAuthentication, parameters: params)
}

static func logEventAccountDelete(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: "account_delete", parameters: params)
Self.logEvent(.accountDelete, parameters: params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
import FirebaseAnalytics

public extension AnalyticsManager {
enum RobotEvent: String {
case connect = "robot_connect"
case disconnect = "robot_disconnect"
case rename = "robot_rename"
}

static func logEventRobotConnect(
robotName: String,
serialNumber: String,
Expand All @@ -27,7 +21,7 @@ public extension AnalyticsManager {
"lk_battery_level": batteryLevel,
].merging(parameters) { _, new in new }

Self.logEvent(name: RobotEvent.connect.rawValue, parameters: params)
Self.logEvent(.robotConnect, parameters: params)
}

static func logEventRobotDisconnect(
Expand All @@ -46,7 +40,7 @@ public extension AnalyticsManager {
"lk_battery_level": batteryLevel,
].merging(parameters) { _, new in new }

Self.logEvent(name: RobotEvent.disconnect.rawValue, parameters: params)
Self.logEvent(.robotDisconnect, parameters: params)
}

// swiftlint:disable:next function_parameter_count
Expand All @@ -68,6 +62,6 @@ public extension AnalyticsManager {
"lk_battery_level": batteryLevel,
].merging(parameters) { _, new in new }

Self.logEvent(name: RobotEvent.rename.rawValue, parameters: params)
Self.logEvent(.robotRename, parameters: params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension AnalyticsManager {
params[AnalyticsParameterScreenClass] = screenClass
}

Self.logEvent(name: AnalyticsEventScreenView, parameters: params)
Self.logEvent(.screenView, parameters: params)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public extension AnalyticsManager {
"lk_content_origin": origin.rawValue,
].merging(parameters) { _, new in new }

Self.logEvent(name: AnalyticsEventSelectContent, parameters: params)
Self.logEvent(.selectContent, parameters: params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public extension AnalyticsManager {
"lk_caregiver_id": id ?? "(lk_not_set)",
].merging(parameters) { _, new in new }

Self.logEvent(name: "caregiver_select", parameters: params)
Self.logEvent(.caregiverSelect, parameters: params)
}

static func logEventCarereceiverSkipSelect(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Self.logEvent(name: "carereceiver_skip_select", parameters: params)
Self.logEvent(.carereceiverSkipSelect, parameters: params)
}
}
74 changes: 72 additions & 2 deletions Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,77 @@ public class AnalyticsManager {

// MARK: Internal

static func logEvent(name: String, parameters: [String: Any] = [:]) {
Analytics.logEvent(name, parameters: parameters)
enum Event {
case activityStart
case activityEnd

case appUpdateSkip
case appUpdateOpenAppStore

case login
case logout
case signup
case skipAuthentication
case accountDelete

case screenView

case robotConnect
case robotDisconnect
case robotRename

case selectContent

case caregiverSelect
case carereceiverSkipSelect

// MARK: Internal

var name: String {
switch self {
case .activityStart:
"activity_start"
case .activityEnd:
"activity_end"

case .appUpdateSkip:
"app_update_skip"
case .appUpdateOpenAppStore:
"app_update_open_app_store"

case .login:
AnalyticsEventLogin // ? "login"
case .logout:
"logout"
case .signup:
AnalyticsEventSignUp // ? "sign_up"
case .skipAuthentication:
"skip_authentication"
case .accountDelete:
"account_delete"

case .screenView:
AnalyticsEventScreenView // ? "screen_view"

case .robotConnect:
"robot_connect"
case .robotDisconnect:
"robot_disconnect"
case .robotRename:
"robot_rename"

case .selectContent:
AnalyticsEventSelectContent // ? "select_content"

case .caregiverSelect:
"caregiver_select"
case .carereceiverSkipSelect:
"carereceiver_skip_select"
}
}
}

static func logEvent(_ event: Event, parameters: [String: Any] = [:]) {
Analytics.logEvent(event.name, parameters: parameters)
}
}

0 comments on commit db73950

Please sign in to comment.