Skip to content

Commit

Permalink
♻️ (Analytics): Create logEventActivityStart/End methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 7, 2024
1 parent 173774f commit 05fe4f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class AnalyticsManager {
self.setDefaultEventParameters(nil)
}

// Recommended events methods

public func logEventLogin() {
Analytics.logEvent(AnalyticsEventLogin, parameters: nil)
}
Expand All @@ -55,4 +53,20 @@ public class AnalyticsManager {
public func logEventSignUp() {
Analytics.logEvent(AnalyticsEventSignUp, parameters: nil)
}

public func logEventActivityStart(id: String, name: String, carereceiverIDs: String) {
Analytics.logEvent("activity_start", parameters: [
"activity_id": id,
"activity_name": name,
"carereceiver_ids": carereceiverIDs,
])
}

public func logEventActivityEnd(id: String, name: String, carereceiverIDs: String) {
Analytics.logEvent("activity_end", parameters: [
"activity_id": id,
"activity_name": name,
"carereceiver_ids": carereceiverIDs,
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ public struct ActivityView: View {
.onAppear {
Robot.shared.stop()
UIApplication.shared.isIdleTimerDisabled = true
self.logActivityAnalytics(event: "activity_start")

AnalyticsManager.shared
.logEventActivityStart(
id: self.viewModel.currentActivity.id,
name: self.viewModel.currentActivity.name,
carereceiverIDs: self.carereceiverManager.currentCarereceivers.value.compactMap(\.id).joined(separator: ",")
)
}
.onDisappear {
Robot.shared.stop()
Expand Down Expand Up @@ -217,7 +223,13 @@ public struct ActivityView: View {
if self.viewModel.isLastExercise {
self.viewModel.scorePanelEnabled ? self.viewModel.moveToActivityEnd() : self.dismiss()
self.saveActivityCompletion()
self.logActivityAnalytics(event: "activity_end")

AnalyticsManager.shared
.logEventActivityEnd(
id: self.viewModel.currentActivity.id,
name: self.viewModel.currentActivity.name,
carereceiverIDs: self.carereceiverManager.currentCarereceivers.value.compactMap(\.id).joined(separator: ",")
)
} else {
self.viewModel.moveToNextExercise()
}
Expand Down Expand Up @@ -406,16 +418,6 @@ public struct ActivityView: View {
let carereceiverIDs = self.carereceiverManagerViewModel.currentCarereceivers.compactMap(\.id)
self.viewModel.saveActivityCompletion(caregiverID: caregiverID, carereceiverIDs: carereceiverIDs)
}

private func logActivityAnalytics(event: String) {
let carereceiverIDs = self.carereceiverManager.currentCarereceivers.value.compactMap(\.id)
let carereceiverIDsString = carereceiverIDs.joined(separator: ",")
AnalyticsManager.shared.logEvent(name: event, parameters: [
"activity_id": self.viewModel.currentActivity.id,
"activity_name": self.viewModel.currentActivity.name,
"carereceiver_ids": carereceiverIDsString,
])
}
}

// swiftlint:enable cyclomatic_complexity void_function_in_ternary function_body_length
Expand Down

0 comments on commit 05fe4f5

Please sign in to comment.