diff --git a/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift b/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift index 50f656d14..8a1865060 100644 --- a/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift +++ b/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift @@ -172,6 +172,7 @@ struct SettingsView: View { ) { self.dismiss() self.authManager.deleteCurrentUser() + AnalyticsManager.logEventAccountDelete() } } message: { Text(l10n.SettingsView.AccountSection.DeleteAccount.alertMessage) diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift index b15d92774..99ee074b7 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+Auth.swift @@ -28,4 +28,10 @@ public extension AnalyticsManager { Self.logEvent(name: "skip_authentication", parameters: params) } + + static func logEventAccountDelete(parameters: [String: Any] = [:]) { + let params: [String: Any] = [:].merging(parameters) { _, new in new } + + Self.logEvent(name: "account_delete", parameters: params) + } } diff --git a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift index 30d4b6a12..074b73efb 100644 --- a/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift +++ b/Modules/AnalyticsKit/Sources/Manager/AnalyticsManager+SelectContent.swift @@ -11,16 +11,15 @@ public extension AnalyticsManager { case educationalGame = "educational_game" case story case gamepad - case resource + case resourceFile + case resourceVideo } enum ContentOrigin: String { case generalLibrary = "general_library" case personalLibrary = "personal_library" case searchResults = "search_results" - case resourcesFirstSteps = "resources_first_steps" - case resourcesVideos = "resources_videos" - case resourcesDeepDive = "resources_deep_dive" + case resources } } diff --git a/Modules/ContentKit/Sources/Categories/Category+Resources.swift b/Modules/ContentKit/Sources/Categories/Category+Resources.swift index d5d4bcc67..649bf0777 100644 --- a/Modules/ContentKit/Sources/Categories/Category+Resources.swift +++ b/Modules/ContentKit/Sources/Categories/Category+Resources.swift @@ -140,7 +140,6 @@ public extension Category { enum ResourceType: String, Codable { case file case video - case link } struct ResourcePayload: Codable { diff --git a/Modules/ContentKit/Sources/Views/ResourceFileView.swift b/Modules/ContentKit/Sources/Views/ResourceFileView.swift index 058aa399e..2e872e373 100644 --- a/Modules/ContentKit/Sources/Views/ResourceFileView.swift +++ b/Modules/ContentKit/Sources/Views/ResourceFileView.swift @@ -2,6 +2,7 @@ // Copyright APF France handicap // SPDX-License-Identifier: Apache-2.0 +import AnalyticsKit import QuickLook import SwiftUI @@ -37,6 +38,12 @@ public struct ResourceFileView: View { } .onTapGesture { self.url = ContentKitResources.bundle.url(forResource: self.resource.value, withExtension: "resource.pdf") + AnalyticsManager.logEventSelectContent( + type: .resourceFile, + id: self.resource.id.uuidString, + name: self.resource.title, + origin: .resources + ) } .quickLookPreview(self.$url) .padding() diff --git a/Modules/ContentKit/Sources/Views/ResourceVideoView.swift b/Modules/ContentKit/Sources/Views/ResourceVideoView.swift index 7132c2e1d..8cd265c66 100644 --- a/Modules/ContentKit/Sources/Views/ResourceVideoView.swift +++ b/Modules/ContentKit/Sources/Views/ResourceVideoView.swift @@ -2,6 +2,8 @@ // Copyright APF France handicap // SPDX-License-Identifier: Apache-2.0 +import AnalyticsKit +import Combine import DesignKit import LocalizationKit import SwiftUI @@ -20,9 +22,27 @@ public struct ResourceVideoView: View { public var body: some View { GroupBox(label: Label(self.resource.title, systemImage: self.resource.icon)) { - YouTubePlayerView(YouTubePlayer(stringLiteral: self.resource.value)) + let player = YouTubePlayer(stringLiteral: self.resource.value) + + YouTubePlayerView(player) .aspectRatio(16 / 9, contentMode: .fit) .frame(maxWidth: .infinity, maxHeight: .infinity) + .onAppear { + self.cancellable = player.playbackStatePublisher + .sink { state in + if state == .playing { + AnalyticsManager.logEventSelectContent( + type: .resourceVideo, + id: self.resource.id.uuidString, + name: self.resource.title, + origin: .resources + ) + } + } + } + .onDisappear { + self.cancellable?.cancel() + } } .padding() } @@ -30,6 +50,10 @@ public struct ResourceVideoView: View { // MARK: Internal let resource: Category.Resource + + // MARK: Private + + @State private var cancellable: AnyCancellable? } #Preview {