Skip to content

Commit

Permalink
📈 (LekaApp): Apply logEventScreenView, refactor selectContent
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 29, 2024
1 parent b135c35 commit 968d921
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension AccountCreationProcess {
self.selectedTab = .carereceiverCreation
}
})
.logEventScreenView(screenName: "caregiver_create", context: .context("account_creation_sheet"))
.navigationBarTitleDisplayMode(.inline)
.interactiveDismissDisabled()
}
Expand Down
101 changes: 29 additions & 72 deletions Apps/LekaApp/Sources/Views/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,69 +157,47 @@ struct MainView: View {
switch self.navigation.selectedCategory {
case .home:
CategoryHome()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_home")
}
.logEventScreenView(screenName: "home", context: .splitView)

case .search:
CategorySearchView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_search")
}
.logEventScreenView(screenName: "search", context: .splitView)

case .resourcesFirstSteps:
CategoryResourcesFirstStepsView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_resources_first_steps")
}
.logEventScreenView(screenName: "resources_first_steps", context: .splitView)

case .resourcesVideo:
CategoryResourcesVideosView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_resources_video")
}
.logEventScreenView(screenName: "resources_video", context: .splitView)

case .resourcesDeepDive:
CategoryResourcesDeepDiveView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_resources_deep_dive")
}
.logEventScreenView(screenName: "resources_deep_dive", context: .splitView)

case .curriculums:
CategoryCurriculumsView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_curriculums")
}
.logEventScreenView(screenName: "curriculums", context: .splitView)

case .educationalGames:
CategoryEducationalGamesView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_educational_games")
}
.logEventScreenView(screenName: "educational_games", context: .splitView)

case .stories:
CategoryStoriesView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_stories")
}
.logEventScreenView(screenName: "stories", context: .splitView)

case .gamepads:
CategoryGamepadsView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_gamepads")
}
.logEventScreenView(screenName: "gamepads", context: .splitView)

case .caregivers:
CaregiverList()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_caregivers")
}
.logEventScreenView(screenName: "caregivers", context: .splitView)

case .carereceivers:
CarereceiverList()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_carereceivers")
}
.logEventScreenView(screenName: "carereceivers", context: .splitView)

// ? DEVELOPER_MODE + TESTFLIGHT_BUILD
case .allPublishedActivities:
Expand Down Expand Up @@ -247,21 +225,15 @@ struct MainView: View {

case .libraryCurriculums:
CategoryLibraryView(category: .libraryCurriculums)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_library_curriculums")
}
.logEventScreenView(screenName: "library_curriculums", context: .splitView)

case .libraryActivities:
CategoryLibraryView(category: .libraryActivities)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_library_activities")
}
.logEventScreenView(screenName: "library_activities", context: .splitView)

case .libraryStories:
CategoryLibraryView(category: .libraryStories)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_category_library_stories")
}
.logEventScreenView(screenName: "library_stories", context: .splitView)

case .none:
Text(l10n.MainView.Sidebar.CategoryLabel.home)
Expand All @@ -279,19 +251,15 @@ struct MainView: View {
switch content {
case .welcomeView:
WelcomeView()
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_welcome")
}
.logEventScreenView(screenName: "welcome", context: .fullScreenCover)

case let .activityView(carereceivers):
ActivityView(activity: self.navigation.currentActivity!, reinforcer: carereceivers.first?.reinforcer ?? .rainbow)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_activity")
}
.logEventScreenView(screenName: "activity", context: .fullScreenCover)

case .storyView:
StoryView(story: self.navigation.currentStory!)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_story")
}
.logEventScreenView(screenName: "story", context: .fullScreenCover)
}
}
}
Expand All @@ -302,34 +270,28 @@ struct MainView: View {
switch content {
case .robotConnection:
RobotConnectionView(viewModel: RobotConnectionViewModel())
.logEventScreenView(screenName: "robot_connection", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_robot_connection")
}

case .settings:
SettingsView()
.logEventScreenView(screenName: "settings", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_settings")
}

case .editCaregiver:
EditCaregiverView(caregiver: self.caregiverManagerViewModel.currentCaregiver!)
.logEventScreenView(screenName: "caregiver_edit", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_edit_caregiver")
}

case .createCaregiver:
CreateCaregiverView()
.logEventScreenView(screenName: "caregiver_create", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_create_caregiver")
}

case .caregiverPicker:
CaregiverPicker()
.logEventScreenView(screenName: "caregiver_picker", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_caregiver_picker")
}
.onDisappear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
if case .appUpdateAvailable = UpdateManager.shared.appUpdateStatus {
Expand Down Expand Up @@ -361,10 +323,8 @@ struct MainView: View {
self.navigation.fullScreenCoverContent = .storyView(carereceivers: [])
}
})
.logEventScreenView(screenName: "carereceiver_picker", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_carereceiver_picker")
}
}
}
}
Expand All @@ -374,9 +334,6 @@ struct MainView: View {
}
self.persistentDataManager.checkInactivity()
}
.onAppear {
AnalyticsManager.logEventScreenView(screenName: "view_main_navigation_split_view")
}
.onChange(of: self.scenePhase) { newPhase in
guard self.authManagerViewModel.userAuthenticationState == .loggedIn else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct CarereceiverList: View {
.sheet(isPresented: self.$isCarereceiverCreationPresented) {
NavigationStack {
CreateCarereceiverView()
.logEventScreenView(screenName: "carereceiver_create", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct CarereceiverView: View {
.sheet(isPresented: self.$isEditCarereceiverViewPresented) {
NavigationStack {
EditCarereceiverView(modifiedCarereceiver: self.$carereceiver)
.logEventScreenView(screenName: "carereceiver_edit", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ extension l10n {
CreateCarereceiverView(onClose: {
print("Care receiver creation canceled")
})
// , onCreated: {
// print("Carereceiver \($0.username) created")
// })
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct CaregiverList: View {
.sheet(isPresented: self.$isCaregiverCreationPresented) {
NavigationStack {
CreateCaregiverView()
.logEventScreenView(screenName: "caregiver_create", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: Apache-2.0

import AccountKit
import AnalyticsKit
import DesignKit
import LocalizationKit
import SwiftUI
Expand Down Expand Up @@ -35,6 +34,7 @@ struct CaregiverPicker: View {
.sheet(isPresented: self.$isCaregiverCreationPresented) {
NavigationStack {
CreateCaregiverView()
.logEventScreenView(screenName: "caregiver_create", context: .sheet)
.navigationBarTitleDisplayMode(.inline)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import AnalyticsKit
import Combine
import Foundation
import LocalizationKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import AnalyticsKit
import Combine

public class RootAccountManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,21 @@ public extension AnalyticsManager {
case sheet
case fullScreenCover
case context(String)
case none
case additionalInfo(String)

// MARK: Internal

var description: String {
switch self {
case .splitView:
"main_splitview"
"splitview"
case .sheet:
"main_sheet"
"sheet"
case .fullScreenCover:
"main_fullscreen"
"fullscreen"
case let .context(value):
"\(value)"
case .none:
"none"
case let .additionalInfo(value):
"\(value)"
}
}

static func + (lhs: Self, rhs: Self) -> ScreenViewContext {
.additionalInfo("\(lhs.description)-\(rhs.description)")
}
}
}

Expand All @@ -57,8 +47,8 @@ struct AnalyticsLogScreenViewViewModifier: ViewModifier {
// MARK: Lifecycle

init(
screenName: String,
screenClass: String,
screenName: String,
context: AnalyticsManager.ScreenViewContext? = nil,
parameters: [String: Any] = [:]
) {
Expand All @@ -70,44 +60,41 @@ struct AnalyticsLogScreenViewViewModifier: ViewModifier {

// MARK: Internal

let screenName: String
let screenClass: String
let screenName: String
let context: AnalyticsManager.ScreenViewContext?
let parameters: [String: Any]

func body(content: Content) -> some View {
content
.onAppear {
let screenName = "\(screenName)"
let params: [String: Any] = [
"lk_context": context?.description ?? NSNull(),
].merging(self.parameters) { _, new in new }

AnalyticsManager.logEventScreenView(screenName: screenName, screenClass: self.screenClass, parameters: self.parameters)
AnalyticsManager.logEventScreenView(screenName: self.screenName, screenClass: self.screenClass, parameters: params)
}
}
}

public extension View {
func logEventScreenView(
screenName: String,
context: AnalyticsManager.ScreenViewContext?,
screenClass: String? = nil,
screenName: String,
context: AnalyticsManager.ScreenViewContext? = nil,
parameters: [String: Any] = [:]
) -> some View {
self.modifier(
AnalyticsLogScreenViewViewModifier(
screenName: screenName,
screenClass: screenClass ?? String(describing: type(of: self)),
screenName: screenName,
context: context,
parameters: parameters
)
)
}
}

// MARK: - MyCustomView

#Preview {
struct MyCustomView: View {
@State private var isPresented = true
Expand Down
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 ContentKit
import MarkdownUI
import SwiftUI
Expand All @@ -14,13 +15,23 @@ struct CurriculumListView: View {
var body: some View {
List {
ForEach(self.activities) { curriculum in
NavigationLink(destination: CurriculumDetailsView(curriculum: curriculum)) {
NavigationLink(destination:
CurriculumDetailsView(curriculum: curriculum)
) {
Image(uiImage: curriculum.details.iconImage)
.resizable()
.scaledToFit()
.frame(width: 44, height: 44)
Text(curriculum.details.title)
}
.simultaneousGesture(TapGesture().onEnded {
AnalyticsManager.logEventSelectContent(
type: .curriculum,
id: curriculum.id,
name: curriculum.name,
origin: .generalLibrary
)
})
}
}
.navigationTitle("Curriculums")
Expand Down
Loading

0 comments on commit 968d921

Please sign in to comment.