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

mathieu/feature/Add Analytics UserProperties #1587

Merged
merged 3 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 @@ -2,6 +2,7 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import AnalyticsKit
import Combine
import Foundation
import LocalizationKit
Expand Down Expand Up @@ -100,10 +101,12 @@ public class AuthManagerViewModel: ObservableObject {
self.showActionRequestAlert = true
}
self.resetErrorMessage()
AnalyticsManager.setUserPropertyUserIsLoggedIn(value: true)
case .loggedOut:
self.resetState()
AnalyticsManager.setUserPropertyUserIsLoggedIn(value: false)
case .unknown:
break
AnalyticsManager.setUserPropertyUserIsLoggedIn(value: false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class CaregiverManager {
public func setCurrentCaregiver(to caregiver: Caregiver) {
self.currentCaregiver.send(caregiver)
AnalyticsManager.setDefaultEventParameterCaregiverUid(caregiver.id)
AnalyticsManager.setUserPropertyCaregiverProfessions(values: caregiver.professions)
}

public func setCurrentCaregiver(byID id: String) {
Expand All @@ -103,20 +104,21 @@ public class CaregiverManager {
}
self.currentCaregiver.send(currentCaregiver)
AnalyticsManager.setDefaultEventParameterCaregiverUid(currentCaregiver.id)
AnalyticsManager.setUserPropertyCaregiverProfessions(values: currentCaregiver.professions)
}

public func resetCurrentCaregiver() {
self.currentCaregiver.send(nil)
AnalyticsManager.setDefaultEventParameterCaregiverUid(nil)
AnalyticsManager.setUserPropertyCaregiverProfessions(values: [])
}

public func resetData() {
self.currentCaregiver.send(nil)
self.resetCurrentCaregiver()
self.caregiverList.send([])
self.dbOps.clearAllListeners()
self.cancellables.forEach { $0.cancel() }
self.cancellables.removeAll()
AnalyticsManager.setDefaultEventParameterCaregiverUid(nil)
}

// MARK: Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@

Self.logEvent(.accountDelete, parameters: params)
}

static func setUserPropertyUserIsLoggedIn(value: Bool) {
Self.setUserProperty(value: value.description, name: "user_is_logged_in")

Check warning on line 39 in Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Remove explicit Self where applicable. (redundantStaticSelf)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@

Self.logEvent(.robotRename, parameters: params)
}

static func setUserPropertyUserRobotIsConnected(value: Bool) {
Self.setUserProperty(value: value.description, name: "robot_is_connected")

Check warning on line 69 in Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Robot.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Remove explicit Self where applicable. (redundantStaticSelf)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import FirebaseAnalytics
import Foundation

public extension AnalyticsManager {
static func logEventCaregiverSelect(id: String?, parameters: [String: Any] = [:]) {
Expand All @@ -18,4 +19,10 @@ public extension AnalyticsManager {

Self.logEvent(.carereceiverSkipSelect, parameters: params)
}

static func setUserPropertyCaregiverProfessions(values: [String]) {
let professions = values.joined(separator: ",")

Self.setUserProperty(value: professions, name: "caregiver_professions")
}
}
4 changes: 4 additions & 0 deletions Modules/AnalyticsKit/Sources/Manager/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public class AnalyticsManager {
static func logEvent(_ event: Event, parameters: [String: Any] = [:]) {
Analytics.logEvent(event.name, parameters: parameters)
}

static func setUserProperty(value: String, name: String) {
Analytics.setUserProperty(value, forName: name)
}
}
2 changes: 2 additions & 0 deletions Modules/RobotKit/Sources/Robot+BLE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extension Robot {
isCharging: self.isCharging.value,
batteryLevel: self.battery.value
)
AnalyticsManager.setUserPropertyUserRobotIsConnected(value: false)
}
.store(in: &cancellables)
}
Expand All @@ -56,6 +57,7 @@ extension Robot {
isCharging: self.isCharging.value,
batteryLevel: self.battery.value
)
AnalyticsManager.setUserPropertyUserRobotIsConnected(value: true)
}
.store(in: &self.cancellables)
}
Expand Down
Loading