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/analytics/Log events Carereceiver create and edit and select #1608

Closed
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

public class CarereceiverManager {
Expand Down Expand Up @@ -42,8 +43,10 @@
.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 @@
if case let .failure(error) = completion {
self.fetchError.send(error)
}
}, receiveValue: { _ in
// 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 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,6 +6,24 @@ import FirebaseAnalytics
import Foundation

public extension AnalyticsManager {
// MARK: - Caregiver

static func logEventCaregiverCreate(id: String, parameters: [String: Any] = [:]) {
let params: [String: Any] = [
"lk_caregiver_id_new": 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(),
Expand All @@ -15,20 +33,32 @@ public extension AnalyticsManager {
logEvent(.caregiverSelect, parameters: params)
}

static func logEventCaregiverCreate(id: String, parameters: [String: Any] = [:]) {
// MARK: - Carereceiver

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

logEvent(.caregiverCreate, parameters: params)
logEvent(.carereceiverCreate, parameters: params)
}

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

logEvent(.caregiverEdit, parameters: params)
logEvent(.carereceiverEdit, parameters: params)
}

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

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

logEvent(.carereceiversSelect, parameters: params)
}

static func logEventCarereceiverSkipSelect(parameters: [String: Any] = [:]) {
Expand Down
9 changes: 9 additions & 0 deletions Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class AnalyticsManager {
case caregiverSelect
case caregiverEdit

case carereceiverCreate
case carereceiverEdit
case carereceiversSelect
case carereceiverSkipSelect

// MARK: Internal
Expand Down Expand Up @@ -91,6 +94,12 @@ public class AnalyticsManager {
case .caregiverEdit:
"caregiver_edit"

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