Skip to content

Commit

Permalink
📈 (Analytics): Improve log event caregiver select with previous, new
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 25, 2024
1 parent 9eb365c commit c9e4c78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ struct CaregiverPicker: View {

self.caregiverManager.setCurrentCaregiver(to: selectedCaregiver)

AnalyticsManager.logEventCaregiverSelect(id: selectedCaregiver.id)

self.dismiss()
} label: {
Text(l10n.CaregiverPicker.selectButtonLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ public class CaregiverManager {
}

public func setCurrentCaregiver(to caregiver: Caregiver) {
let previousCaregiverID: String? = self.currentCaregiver.value?.id
self.currentCaregiver.send(caregiver)
AnalyticsManager.setDefaultEventParameterCaregiverUid(caregiver.id)

guard let caregiverID = caregiver.id else {
log.error("Caregiver ID is nil")
return
}

AnalyticsManager.logEventCaregiverSelect(from: previousCaregiverID, to: caregiverID)
AnalyticsManager.setDefaultEventParameterCaregiverUid(caregiverID)
AnalyticsManager.setUserPropertyCaregiverProfessions(values: caregiver.professions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import FirebaseAnalytics
import Foundation

public extension AnalyticsManager {
static func logEventCaregiverSelect(id: String?, parameters: [String: Any] = [:]) {
static func logEventCaregiverSelect(from previous: String?, to new: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_caregiver_id": id ?? "(lk_not_set)",
"lk_caregiver_id_previous": previous ?? NSNull(),
"lk_caregiver_id_new": new,
].merging(parameters) { _, new in new }

logEvent(.caregiverSelect, parameters: params)
Expand Down

0 comments on commit c9e4c78

Please sign in to comment.