diff --git a/.swiftlint.yml b/.swiftlint.yml index 2ccde4dfa..2a3f16a1a 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -49,6 +49,7 @@ identifier_name: - rx - tag - tx + - uid - url - URL diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Activities.swift index 75b27010e..d03f0409f 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(.activityStart, parameters: params) + 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(.activityEnd, parameters: params) + logEvent(.activityEnd, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+App.swift index 31e5b8e82..183ea95de 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(.appUpdateSkip, parameters: params) + 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(.appUpdateOpenAppStore, parameters: params) + logEvent(.appUpdateOpenAppStore, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift index d09bf8f0e..7a4513d0e 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift @@ -8,34 +8,34 @@ public extension AnalyticsManager { static func logEventLogin(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.login, parameters: params) + logEvent(.login, parameters: params) } static func logEventLogout(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.logout, parameters: params) + logEvent(.logout, parameters: params) } static func logEventSignUp(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.signup, parameters: params) + logEvent(.signup, parameters: params) } static func logEventSkipAuthentication(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.skipAuthentication, parameters: params) + logEvent(.skipAuthentication, parameters: params) } static func logEventAccountDelete(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.accountDelete, parameters: params) + logEvent(.accountDelete, parameters: params) } static func setUserPropertyUserIsLoggedIn(value: Bool) { - Self.setUserProperty(value: value.description, name: "user_is_logged_in") + setUserProperty(value: value.description, name: "user_is_logged_in") } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+DefaultParameters.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+DefaultParameters.swift index 066e45331..bdf8caf37 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+DefaultParameters.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+DefaultParameters.swift @@ -5,21 +5,15 @@ import FirebaseAnalytics public extension AnalyticsManager { - static func setDefaultEventParameterRootOwnerUid(_ id: String?) { - self.setDefaultEventParameters(["lk_default_root_owner_uid": id ?? "(lk_not_set)"]) + static func setDefaultEventParameterRootOwnerUid(_ uid: String?) { + setDefaultEventParameter(for: .rootOwnerUid(uid)) } - static func setDefaultEventParameterCaregiverUid(_ id: String?) { - self.setDefaultEventParameters(["lk_default_caregiver_uid": id ?? "(lk_not_set)"]) + static func setDefaultEventParameterCaregiverUid(_ uid: String?) { + setDefaultEventParameter(for: .caregiverUid(uid)) } static func clearDefaultEventParameters() { - self.setDefaultEventParameters(nil) - } - - // MARK: Private - - private static func setDefaultEventParameters(_ parameters: [String: Any]?) { - Analytics.setDefaultEventParameters(parameters) + Analytics.setDefaultEventParameters(nil) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift index 6c4deb625..de9624e2d 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift @@ -21,7 +21,7 @@ public extension AnalyticsManager { "lk_battery_level": batteryLevel, ].merging(parameters) { _, new in new } - Self.logEvent(.robotConnect, parameters: params) + logEvent(.robotConnect, parameters: params) } static func logEventRobotDisconnect( @@ -40,7 +40,7 @@ public extension AnalyticsManager { "lk_battery_level": batteryLevel, ].merging(parameters) { _, new in new } - Self.logEvent(.robotDisconnect, parameters: params) + logEvent(.robotDisconnect, parameters: params) } // swiftlint:disable:next function_parameter_count @@ -62,10 +62,10 @@ public extension AnalyticsManager { "lk_battery_level": batteryLevel, ].merging(parameters) { _, new in new } - Self.logEvent(.robotRename, parameters: params) + logEvent(.robotRename, parameters: params) } static func setUserPropertyUserRobotIsConnected(value: Bool) { - Self.setUserProperty(value: value.description, name: "robot_is_connected") + setUserProperty(value: value.description, name: "robot_is_connected") } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+ScreenView.swift index f9a6d507c..288328614 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(.screenView, parameters: params) + logEvent(.screenView, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift index cf087a479..4e6845fab 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(.selectContent, parameters: params) + logEvent(.selectContent, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift index 45adaf357..403de3060 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Users.swift @@ -11,18 +11,18 @@ public extension AnalyticsManager { "lk_caregiver_id": id ?? "(lk_not_set)", ].merging(parameters) { _, new in new } - Self.logEvent(.caregiverSelect, parameters: params) + logEvent(.caregiverSelect, parameters: params) } static func logEventCarereceiverSkipSelect(parameters: [String: Any] = [:]) { let params: [String: Any] = [:].merging(parameters) { _, new in new } - Self.logEvent(.carereceiverSkipSelect, parameters: params) + logEvent(.carereceiverSkipSelect, parameters: params) } static func setUserPropertyCaregiverProfessions(values: [String]) { let professions = values.joined(separator: ",") - Self.setUserProperty(value: professions, name: "caregiver_professions") + setUserProperty(value: professions, name: "caregiver_professions") } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift index 6a519f557..b40fff64d 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift @@ -14,6 +14,11 @@ public class AnalyticsManager { // MARK: Internal + enum DefaultEventParamters { + case rootOwnerUid(String?) + case caregiverUid(String?) + } + enum Event { case activityStart case activityEnd @@ -91,4 +96,13 @@ public class AnalyticsManager { static func setUserProperty(value: String, name: String) { Analytics.setUserProperty(value, forName: name) } + + static func setDefaultEventParameter(for parameter: DefaultEventParamters) { + switch parameter { + case let .rootOwnerUid(uid): + Analytics.setDefaultEventParameters(["root_owner_uid": uid ?? "(lk_not_set)"]) + case let .caregiverUid(uid): + Analytics.setDefaultEventParameters(["caregiver_uid": uid ?? "(lk_not_set)"]) + } + } }