From 3d70b8b1525db302189c5c2af92852d85f7d99a4 Mon Sep 17 00:00:00 2001 From: "mathieu J." Date: Thu, 7 Nov 2024 10:52:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20(GEK):=20LogEvents=20Activity=5F?= =?UTF-8?q?start=20&=20Activity=5Fend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OldSystem/Views/Activity/ActivityView.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift b/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift index 2dd61f498f..cc94246685 100644 --- a/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift +++ b/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift @@ -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() @@ -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 @@ -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() } @@ -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