Skip to content

Commit

Permalink
♻️ (Analytics): Refactor setDefaultEventParameter to use enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 22, 2024
1 parent 640fa9e commit 24749c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +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)
}

static func setDefaultEventParameters(_ parameters: [String: Any]?) {
Analytics.setDefaultEventParameters(parameters)
Analytics.setDefaultEventParameters(nil)
}
}
14 changes: 14 additions & 0 deletions Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class AnalyticsManager {

// MARK: Internal

enum DefaultEventParamters {
case rootOwnerUid(String?)
case caregiverUid(String?)
}

enum Event {
case activityStart
case activityEnd
Expand Down Expand Up @@ -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)"])
}
}
}

0 comments on commit 24749c7

Please sign in to comment.