Skip to content

Commit

Permalink
🔀️ Merge branch 'mathieu/feature/Create-AnalyticsManager-and-demonstr…
Browse files Browse the repository at this point in the history
…ate-basic-usage' into develop
  • Loading branch information
ladislas committed Oct 31, 2024
2 parents 812994a + f77a16b commit ed48ed8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Apps/LekaApp/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ let kLekaAppIconName: String = if Environment.productionBuild.getBoolean(default
"AppIconBeta"
}

let kLekaAppLaunchArguments: [LaunchArgument] = if Environment.productionBuild.getBoolean(default: false) {
[
.launchArgument(name: "-FIRDebugEnabled", isEnabled: false),
.launchArgument(name: "-FIRDebugDisabled", isEnabled: true),
.launchArgument(name: "-FIRAnalyticsDebugEnabled", isEnabled: false),
.launchArgument(name: "-FIRAnalyticsDebugDisabled", isEnabled: true),
]
} else {
[
.launchArgument(name: "-FIRDebugEnabled", isEnabled: true),
.launchArgument(name: "-FIRDebugDisabled", isEnabled: false),
.launchArgument(name: "-FIRAnalyticsDebugEnabled", isEnabled: true),
.launchArgument(name: "-FIRAnalyticsDebugDisabled", isEnabled: false),
]
}

let project = Project.app(
name: "LekaApp",
version: kLekaAppVersion,
Expand All @@ -60,6 +76,7 @@ let project = Project.app(
settings: SettingsDictionary.extendingBase(with: [
"ASSETCATALOG_COMPILER_APPICON_NAME": "\(kLekaAppIconName)",
]),
launchArguments: kLekaAppLaunchArguments,
dependencies: [
.project(target: "AccountKit", path: Path("../../Modules/AccountKit")),
.project(target: "ContentKit", path: Path("../../Modules/ContentKit")),
Expand Down
42 changes: 42 additions & 0 deletions Apps/LekaApp/Sources/Views/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,69 @@ struct MainView: View {
switch self.navigation.selectedCategory {
case .home:
CategoryHome()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_home")
}

case .search:
CategorySearchView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_search")
}

case .resourcesFirstSteps:
CategoryResourcesFirstStepsView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_resources_first_steps")
}

case .resourcesVideo:
CategoryResourcesVideosView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_resources_video")
}

case .resourcesDeepDive:
CategoryResourcesDeepDiveView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_resources_deep_dive")
}

case .curriculums:
CategoryCurriculumsView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_catergory_curriculums")
}

case .educationalGames:
CategoryEducationalGamesView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_educational_games")
}

case .stories:
CategoryStoriesView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_stories")
}

case .gamepads:
CategoryGamepadsView()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_gamepads")
}

case .caregivers:
CaregiverList()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_caregivers")
}

case .carereceivers:
CarereceiverList()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_carereceivers")
}

// ? DEVELOPER_MODE + TESTFLIGHT_BUILD
case .allPublishedActivities:
Expand Down Expand Up @@ -183,12 +216,21 @@ struct MainView: View {

case .libraryCurriculums:
CategoryLibraryView(category: .libraryCurriculums)
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_library_curriculums")
}

case .libraryActivities:
CategoryLibraryView(category: .libraryActivities)
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_library_activities")
}

case .libraryStories:
CategoryLibraryView(category: .libraryStories)
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_library_stories")
}

case .none:
Text(l10n.MainView.Sidebar.CategoryLabel.home)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Leka - iOS Monorepo
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import Combine
import FirebaseAnalytics

public class AnalyticsManager {
// MARK: Lifecycle

private init() {
// Nothing to do
}

// MARK: Public

public static let shared = AnalyticsManager()

// MARK: Public Methods

public func logEvent(name: String, parameters: [String: Any]? = nil) {
Analytics.logEvent(name, parameters: parameters)
}

public func setUserProperty(value: String, forName name: String) {
Analytics.setUserProperty(value, forName: name)
}

public func logScreenView(screenName: String, screenClass: String? = nil) {
Analytics.logEvent(AnalyticsEventScreenView, parameters: [
AnalyticsParameterScreenName: screenName,
AnalyticsParameterScreenClass: screenClass ?? screenName,
])
}
}
4 changes: 3 additions & 1 deletion Tuist/ProjectDescriptionHelpers/Project+App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public extension Project {
destinations: Destinations = [.iPad, .macWithiPadDesign],
infoPlist: [String: Plist.Value] = [:],
settings: SettingsDictionary = [:],
launchArguments: [LaunchArgument] = [],
options: Options = .options(),
dependencies: [TargetDependency] = [],
schemes: [Scheme] = []
Expand All @@ -33,7 +34,8 @@ public extension Project {
settings: .settings(base: .extendingBase(with: settings)),
environmentVariables: [
"IDEPreferLogStreaming": "YES",
]
],
launchArguments: launchArguments
)

let testTarget = Target.target(
Expand Down

0 comments on commit ed48ed8

Please sign in to comment.