Skip to content

Commit

Permalink
📈 (GEK): LogEvents Activity_start & Activity_end
Browse files Browse the repository at this point in the history
  • Loading branch information
macteuts committed Nov 7, 2024
1 parent f5bc16f commit 3d70b8b
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public struct ActivityView: View {
.onAppear {
Robot.shared.stop()
UIApplication.shared.isIdleTimerDisabled = true
self.logActivityAnalytics(event: "activity_start")
}
.onDisappear {
Robot.shared.stop()
Expand All @@ -174,6 +175,8 @@ public struct ActivityView: View {
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()
@StateObject private var carereceiverManagerViewModel = CarereceiverManagerViewModel()

private var carereceiverManager: CarereceiverManager = .shared

@State private var isAlertPresented: Bool = false

@State private var opacity: Double = 1
Expand Down Expand Up @@ -214,6 +217,7 @@ public struct ActivityView: View {
if self.viewModel.isLastExercise {
self.viewModel.scorePanelEnabled ? self.viewModel.moveToActivityEnd() : self.dismiss()
self.saveActivityCompletion()
self.logActivityAnalytics(event: "activity_end")
} else {
self.viewModel.moveToNextExercise()
}
Expand Down Expand Up @@ -402,6 +406,16 @@ 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 3d70b8b

Please sign in to comment.