From 73b8bd45c15c5e85c59e482df0cee952a24aea49 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 22 Nov 2024 16:39:28 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=88=20(Analytics):=20Add=20event?= =?UTF-8?q?=20enum=20with=20all=20our=20tracked=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Manager/AnalyticsManager.swift | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift index 64ec52199..91e94c267 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift @@ -18,6 +18,76 @@ public class AnalyticsManager { // MARK: Internal + 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(name: String, parameters: [String: Any] = [:]) { Analytics.logEvent(name, parameters: parameters) } From cd3492551568a84cc812c0b53320ff798f4500cb Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 22 Nov 2024 16:46:23 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(Analytics):=20Use=20E?= =?UTF-8?q?vent=20enum=20in=20logEven(,)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Manager/AnalyticsManager+Activities.swift | 4 ++-- .../Sources/Manager/AnalyticsManager+App.swift | 4 ++-- .../Sources/Manager/AnalyticsManager+Auth.swift | 10 +++++----- .../Sources/Manager/AnalyticsManager+Robot.swift | 12 +++--------- .../Manager/AnalyticsManager+ScreenView.swift | 2 +- .../Manager/AnalyticsManager+SelectContent.swift | 2 +- .../Sources/Manager/AnalyticsManager+Users.swift | 4 ++-- .../Sources/Manager/AnalyticsManager.swift | 4 ++-- 8 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift index ca0b890a1..75b27010e 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift @@ -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( @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift index c66b7861c..31e5b8e82 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift @@ -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 @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift index 99ee074b7..1293abe7c 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift index b3a9e8515..476b1fb47 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift @@ -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, @@ -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( @@ -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 @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift index 6ed6900b8..f9a6d507c 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift @@ -15,7 +15,7 @@ public extension AnalyticsManager { params[AnalyticsParameterScreenClass] = screenClass } - Self.logEvent(name: AnalyticsEventScreenView, parameters: params) + Self.logEvent(.screenView, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift index 074b73efb..cf087a479 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift index 7ca5abdf5..7c1701a42 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift @@ -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) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift index 91e94c267..880b7f957 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift @@ -88,7 +88,7 @@ public class AnalyticsManager { } } - static func logEvent(name: String, parameters: [String: Any] = [:]) { - Analytics.logEvent(name, parameters: parameters) + static func logEvent(_ event: Event, parameters: [String: Any] = [:]) { + Analytics.logEvent(event.name, parameters: parameters) } }