Skip to content

Commit

Permalink
🔀️ Merge branch 'mathieu/analytics/LogEvents-create-select-edit-for-C…
Browse files Browse the repository at this point in the history
…aregivers-and-Carereceivers' into develop
  • Loading branch information
ladislas committed Nov 29, 2024
2 parents 6376105 + 550348b commit b265947
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Modules/AccountKit/Sources/Database/DatabaseOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public class DatabaseOperations {
self.listenerRegistrations.removeAll()
}

public func update(data: some DatabaseDocument, in collection: DatabaseCollection) -> AnyPublisher<Void, Error> {
Future<Void, Error> { promise in
public func update<T: DatabaseDocument>(data: T, in collection: DatabaseCollection) -> AnyPublisher<T, Error> {
Future<T, Error> { promise in
let docRef = self.database.collection(collection.rawValue).document(data.id!)

do {
Expand All @@ -154,7 +154,7 @@ public class DatabaseOperations {
promise(.failure(DatabaseError.customError(error.localizedDescription)))
} else {
log.info("Document \(String(describing: data.id!)) updated successfully in \(collection.rawValue). 🎉")
promise(.success(()))
promise(.success(data))
}
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import AnalyticsKit
import Combine
import Foundation

public class CaregiverManager {
// MARK: Lifecycle
Expand Down Expand Up @@ -61,8 +62,9 @@ public class CaregiverManager {
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
.handleEvents(receiveOutput: { [weak self] _ in
.handleEvents(receiveOutput: { [weak self] newCaregiver in
self?.initializeCaregiversListener()
AnalyticsManager.logEventCaregiverCreate(id: newCaregiver.id!)
})
.eraseToAnyPublisher()
}
Expand All @@ -74,8 +76,12 @@ public class CaregiverManager {
if case let .failure(error) = completion {
self.fetchError.send(error)
}
}, receiveValue: { _ in
// Nothing to do
}, receiveValue: { [weak self] updatedCaregiver in
guard let self else { return }
guard updatedCaregiver.id == self.currentCaregiver.value?.id else { return }
self.setCurrentCaregiver(to: updatedCaregiver)
AnalyticsManager.logEventCaregiverEdit(caregiver: updatedCaregiver.id!)
log.info("Caregiver successfully updated.")
})
.store(in: &self.cancellables)
}
Expand Down Expand Up @@ -107,10 +113,13 @@ public class CaregiverManager {
}

public func setCurrentCaregiver(byID id: String) {
let previousCaregiverID: String? = self.currentCaregiver.value?.id
guard let currentCaregiver = self.caregiverList.value.first(where: { $0.id == id }) else {
return
}
self.currentCaregiver.send(currentCaregiver)

AnalyticsManager.logEventCaregiverSelect(from: previousCaregiverID, to: currentCaregiver.id!)
AnalyticsManager.setDefaultEventParameterCaregiverUid(currentCaregiver.id)
AnalyticsManager.setUserPropertyCaregiverProfessions(values: currentCaregiver.professions)
}
Expand Down
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

public class CarereceiverManager {
Expand Down Expand Up @@ -42,8 +43,10 @@ public class CarereceiverManager {
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
.handleEvents(receiveOutput: { [weak self] _ in
.handleEvents(receiveOutput: { [weak self] newCarereceiver in
self?.initializeCarereceiversListener()
AnalyticsManager.logEventCarereceiverCreate(id: newCarereceiver.id!)
log.info("Carereceiver \(newCarereceiver.id!) successfully created.")
})
.eraseToAnyPublisher()
}
Expand All @@ -55,8 +58,10 @@ public class CarereceiverManager {
if case let .failure(error) = completion {
self.fetchError.send(error)
}
}, receiveValue: {
// Nothing to do
}, receiveValue: { [weak self] updatedCarereceiver in
guard let self else { return }

Check warning on line 62 in Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift

View workflow job for this annotation

GitHub Actions / build (true)

value 'self' was defined but never used; consider replacing with boolean test

Check warning on line 62 in Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift

View workflow job for this annotation

GitHub Actions / build (false)

value 'self' was defined but never used; consider replacing with boolean test
AnalyticsManager.logEventCarereceiverEdit(carereceivers: updatedCarereceiver.id!)
log.info("Carereceiver \(updatedCarereceiver.id!) successfully updated.")
})
.store(in: &self.cancellables)
}
Expand All @@ -75,6 +80,8 @@ public class CarereceiverManager {

public func setCurrentCarereceivers(to carereceivers: [Carereceiver]) {
self.currentCarereceivers.send(carereceivers)
let carereceiverIDs = carereceivers.compactMap(\.id)
AnalyticsManager.logEventCarereceiversSelect(carereceivers: carereceiverIDs)
}

public func resetData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,61 @@ import FirebaseAnalytics
import Foundation

public extension AnalyticsManager {
// MARK: - Caregiver

static func logEventCaregiverCreate(id: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_caregiver_id_created": id,
].merging(parameters) { _, new in new }

logEvent(.caregiverCreate, parameters: params)
}

static func logEventCaregiverEdit(caregiver: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_caregiver_id_edited": caregiver,
].merging(parameters) { _, new in new }

logEvent(.caregiverEdit, parameters: params)
}

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

logEvent(.caregiverSelect, parameters: params)
}

// MARK: - Carereceiver

static func logEventCarereceiverCreate(id: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_carereceiver_id_created": id,
].merging(parameters) { _, new in new }

logEvent(.carereceiverCreate, parameters: params)
}

static func logEventCarereceiverEdit(carereceivers: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_carereceiver_id_edited": carereceivers,
].merging(parameters) { _, new in new }

logEvent(.carereceiverEdit, parameters: params)
}

static func logEventCarereceiversSelect(carereceivers: [String], parameters: [String: Any] = [:]) {
let carereceiversString = carereceivers.joined(separator: ",")

let params: [String: Any] = [
"lk_carereceivers_ids_selected": carereceiversString,
].merging(parameters) { _, new in new }

logEvent(.carereceiversSelect, parameters: params)
}

static func logEventCarereceiverSkipSelect(parameters: [String: Any] = [:]) {
let params: [String: Any] = [:].merging(parameters) { _, new in new }

Expand Down
17 changes: 17 additions & 0 deletions Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public class AnalyticsManager {

case selectContent

case caregiverCreate
case caregiverSelect
case caregiverEdit

case carereceiverCreate
case carereceiverEdit
case carereceiversSelect
case carereceiverSkipSelect

// MARK: Internal
Expand Down Expand Up @@ -83,8 +89,19 @@ public class AnalyticsManager {
case .selectContent:
AnalyticsEventSelectContent // ? "select_content"

case .caregiverCreate:
"caregiver_create"
case .caregiverSelect:
"caregiver_select"
case .caregiverEdit:
"caregiver_edit"

case .carereceiverCreate:
"carereceiver_create"
case .carereceiverEdit:
"carereceiver_edit"
case .carereceiversSelect:
"carereceivers_select"
case .carereceiverSkipSelect:
"carereceiver_skip_select"
}
Expand Down

0 comments on commit b265947

Please sign in to comment.