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

ladislaas/feature/analytics events add enum #1589

Merged
merged 2 commits into from
Nov 22, 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 @@ -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 @@ -5,23 +5,23 @@
import FirebaseAnalytics

public extension AnalyticsManager {
// TODO: (@ladislas) add real versions

Check warning on line 8 in Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) add real versions) (todo)
static func logEventAppUpdateSkip(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"current_version": currentVersion,
"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

Check warning on line 18 in Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) add real versions) (todo)
static func logEventAppUpdateOpenAppStore(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"current_version": currentVersion,
"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)
}
}
Loading