Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mathieu/feature/Add Analytics recommanded logEvents #1548

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct AccountCreationView: View {
Alert(title: Text(l10n.AccountCreationView.EmailVerificationAlert.title),
message: Text(l10n.AccountCreationView.EmailVerificationAlert.message),
dismissButton: .default(Text(l10n.AccountCreationView.EmailVerificationAlert.dismissButton)) {
AnalyticsManager.shared.logEventSignUp()
self.navigation.navigateToAccountCreationProcess = true
})
}
Expand Down
1 change: 1 addition & 0 deletions Apps/LekaApp/Sources/Views/ConnectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct ConnectionView: View {
self.caregiverManager.initializeCaregiversListener()
self.carereceiverManager.initializeCarereceiversListener()
self.rootAccountManager.initializeRootAccountListener()
AnalyticsManager.shared.logEventLogin()
self.authManagerViewModel.userAction = .none
self.navigation.fullScreenCoverContent = nil
}
Expand Down
28 changes: 14 additions & 14 deletions Apps/LekaApp/Sources/Views/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,67 +127,67 @@ struct MainView: View {
case .home:
CategoryHome()
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_home")
AnalyticsManager.shared.logEventScreenView(screenName: "view_category_home")
}

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

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

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

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

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

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

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

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

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

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

// ? DEVELOPER_MODE + TESTFLIGHT_BUILD
Expand Down Expand Up @@ -217,19 +217,19 @@ struct MainView: View {
case .libraryCurriculums:
CategoryLibraryView(category: .libraryCurriculums)
.onAppear {
AnalyticsManager.shared.logScreenView(screenName: "view_category_library_curriculums")
AnalyticsManager.shared.logEventScreenView(screenName: "view_category_library_curriculums")
}

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

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

case .none:
Expand Down
2 changes: 2 additions & 0 deletions Apps/LekaApp/Sources/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct SettingsView: View {
self.authManager.signOut()
self.persistentDataManager.clearUserData()
self.reset()
AnalyticsManager.shared.logEventLogout()
} label: {
Text(l10n.SettingsView.AccountSection.LogOut.alertButtonLabel)
}
Expand Down Expand Up @@ -220,6 +221,7 @@ struct SettingsView: View {
self.rootAccountViewModel.resetData()
self.styleManager.accentColor = DesignKitAsset.Colors.lekaDarkBlue.swiftUIColor
self.styleManager.colorScheme = .light
AnalyticsManager.shared.clearDefaultEventParameters()
}

private var errorAlertTitle: String {
Expand Down
1 change: 1 addition & 0 deletions Apps/LekaApp/Sources/Views/WelcomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct WelcomeView: View {
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(String(l10n.WelcomeView.skipStepButton.characters)) {
AnalyticsManager.shared.logEvent(name: "skip_authentication")
self.dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,37 @@ public class AnalyticsManager {
Analytics.logEvent(name, parameters: parameters)
}

public func setUserProperty(value: String, forName name: String) {
Analytics.setUserProperty(value, forName: name)
public func logEventScreenView(screenName: String, screenClass: String? = nil) {
var params: [String: Any] = [
AnalyticsParameterScreenName: screenName,
]

if let screenClass {
params[AnalyticsParameterScreenClass] = screenClass
}

Analytics.logEvent(AnalyticsEventScreenView, parameters: params)
}

public func logScreenView(screenName: String, screenClass: String? = nil) {
Analytics.logEvent(AnalyticsEventScreenView, parameters: [
AnalyticsParameterScreenName: screenName,
AnalyticsParameterScreenClass: screenClass ?? screenName,
])
public func setDefaultEventParameters(_ parameters: [String: Any]?) {
Analytics.setDefaultEventParameters(parameters)
}

public func clearDefaultEventParameters() {
self.setDefaultEventParameters(nil)
}

// Recommended events methods

public func logEventLogin() {
Analytics.logEvent(AnalyticsEventLogin, parameters: nil)
}

public func logEventLogout() {
Analytics.logEvent("logout", parameters: nil)
}

public func logEventSignUp() {
Analytics.logEvent(AnalyticsEventSignUp, parameters: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,21 @@ public class CaregiverManager {

public func setCurrentCaregiver(to caregiver: Caregiver) {
self.currentCaregiver.send(caregiver)
AnalyticsManager.shared.setDefaultEventParameters(
["caregiver_id": caregiver.id ?? "no_id"]
)
}

public func setCurrentCaregiver(byID id: String) {
self.currentCaregiver.send(self.caregiverList.value.first { $0.id == id })
AnalyticsManager.shared.setDefaultEventParameters(
["caregiver_id": id]
)
}

public func resetCurrentCaregiver() {
self.currentCaregiver.send(nil)
AnalyticsManager.shared.setDefaultEventParameters(["caregiver_id": "no_id"])
}

public func resetData() {
Expand All @@ -109,6 +116,7 @@ public class CaregiverManager {
self.dbOps.clearAllListeners()
self.cancellables.forEach { $0.cancel() }
self.cancellables.removeAll()
AnalyticsManager.shared.setDefaultEventParameters(["caregiver_id": "no_id"])
}

// MARK: Private
Expand Down
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Views/ActivityDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public struct ActivityDetailsView: View {
.markdownTheme(.gitHub)
}
}
.onAppear {
AnalyticsManager.shared.logEventScreenView(screenName: "view_activity_details_view")
}
.toolbar {
#if DEVELOPER_MODE || TESTFLIGHT_BUILD
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
Expand Down
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Views/CurriculumDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public struct CurriculumDetailsView: View {
}
}
}
.onAppear {
AnalyticsManager.shared.logEventScreenView(screenName: "view_curriculum_details_view")
}
.toolbar {
#if DEVELOPER_MODE || TESTFLIGHT_BUILD
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
Expand Down
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Views/StoryDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public struct StoryDetailsView: View {
.markdownTheme(.gitHub)
}
}
.onAppear {
AnalyticsManager.shared.logEventScreenView(screenName: "view_story_details_view")
}
.toolbar {
#if DEVELOPER_MODE || TESTFLIGHT_BUILD
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
Expand Down
Loading