From 06d81a99ec9b016de5028eb192258288e8ae2ae3 Mon Sep 17 00:00:00 2001 From: "omer.habib" Date: Thu, 16 Jan 2025 22:54:54 +0500 Subject: [PATCH] fix: Added analytics --- .../java/org/openedx/app/di/ScreenModule.kt | 2 +- .../comments/DiscussionCommentsFragment.kt | 1 + .../presentation/NotificationsAnalytics.kt | 13 +++++- .../inbox/NotificationsInboxViewModel.kt | 44 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/openedx/app/di/ScreenModule.kt b/app/src/main/java/org/openedx/app/di/ScreenModule.kt index 3777e25dd..d592c510a 100644 --- a/app/src/main/java/org/openedx/app/di/ScreenModule.kt +++ b/app/src/main/java/org/openedx/app/di/ScreenModule.kt @@ -490,7 +490,7 @@ val screenModule = module { single { NotificationsRepository(get()) } factory { NotificationsInteractor(get()) } - viewModel { NotificationsInboxViewModel(get(), get(), get()) } + viewModel { NotificationsInboxViewModel(get(), get(), get(), get()) } viewModel { NotificationsSettingsViewModel(get(), get(), get()) } single { IAPRepository(get()) } diff --git a/discussion/src/main/java/org/openedx/discussion/presentation/comments/DiscussionCommentsFragment.kt b/discussion/src/main/java/org/openedx/discussion/presentation/comments/DiscussionCommentsFragment.kt index b491eee35..1b5528300 100644 --- a/discussion/src/main/java/org/openedx/discussion/presentation/comments/DiscussionCommentsFragment.kt +++ b/discussion/src/main/java/org/openedx/discussion/presentation/comments/DiscussionCommentsFragment.kt @@ -104,6 +104,7 @@ class DiscussionCommentsFragment : Fragment() { requireArguments().getString(ARG_COURSE_ID, ""), requireArguments().parcelable(ARG_THREAD)!!, requireArguments().getString(ARG_RESPONSE_ID, ""), + requireArguments().getString(ARG_COMMENT_ID, ""), ) } private val router by inject() diff --git a/notifications/src/main/java/org/openedx/notifications/presentation/NotificationsAnalytics.kt b/notifications/src/main/java/org/openedx/notifications/presentation/NotificationsAnalytics.kt index 65608fce6..a4e2dd776 100644 --- a/notifications/src/main/java/org/openedx/notifications/presentation/NotificationsAnalytics.kt +++ b/notifications/src/main/java/org/openedx/notifications/presentation/NotificationsAnalytics.kt @@ -9,7 +9,15 @@ enum class NotificationsAnalyticsEvent(val eventName: String, val biValue: Strin DISCUSSION_PERMISSION_TOGGLE( eventName = "Notification:Discussion Permission Toggle", biValue = "edx.bi.app.notification.discussion.permission.toggle" - ) + ), + NOTIFICATION_INBOX_VIEW( + eventName = "Notification:Notification Inbox", + biValue = "edx.bi.app.notification.inbox" + ), + NOTIFICATION_ITEM_TAPPED( + eventName = "Notification:Notification Tapped", + biValue = "edx.bi.app.notification.tapped" + ), } enum class NotificationsAnalyticsKey(val key: String) { @@ -17,4 +25,7 @@ enum class NotificationsAnalyticsKey(val key: String) { ACTION("action"), CATEGORY("category"), NOTIFICATIONS("notifications"), + NOTIFICATION_CATEGORY("notification_category"), + DISCUSSION("discussion"), + NOTIFICATION_TYPE("notification_type"), } diff --git a/notifications/src/main/java/org/openedx/notifications/presentation/inbox/NotificationsInboxViewModel.kt b/notifications/src/main/java/org/openedx/notifications/presentation/inbox/NotificationsInboxViewModel.kt index 71e6e5589..03d3a433a 100644 --- a/notifications/src/main/java/org/openedx/notifications/presentation/inbox/NotificationsInboxViewModel.kt +++ b/notifications/src/main/java/org/openedx/notifications/presentation/inbox/NotificationsInboxViewModel.kt @@ -15,6 +15,9 @@ import org.openedx.core.system.ResourceManager import org.openedx.notifications.domain.interactor.NotificationsInteractor import org.openedx.notifications.domain.model.InboxSection import org.openedx.notifications.domain.model.NotificationItem +import org.openedx.notifications.presentation.NotificationsAnalytics +import org.openedx.notifications.presentation.NotificationsAnalyticsEvent +import org.openedx.notifications.presentation.NotificationsAnalyticsKey import org.openedx.notifications.presentation.NotificationsRouter import java.util.Date import org.openedx.core.R as coreR @@ -23,6 +26,7 @@ class NotificationsInboxViewModel( private val interactor: NotificationsInteractor, private val notificationsRouter: NotificationsRouter, private val resourceManager: ResourceManager, + private val analytics: NotificationsAnalytics, ) : BaseViewModel() { private val _uiState = MutableStateFlow(InboxUIState.Loading) @@ -45,10 +49,23 @@ class NotificationsInboxViewModel( private var nextPage = 1 init { + logScreenViewEvent() getInboxNotifications() markNotificationsAsSeen() } + private fun logScreenViewEvent() { + analytics.logScreenEvent( + screenName = NotificationsAnalyticsEvent.NOTIFICATION_INBOX_VIEW.eventName, + params = buildMap { + put( + NotificationsAnalyticsKey.NAME.key, + NotificationsAnalyticsEvent.NOTIFICATION_INBOX_VIEW.biValue + ) + } + ) + } + private fun getInboxNotifications() { _uiState.value = InboxUIState.Loading internalLoadNotifications() @@ -134,6 +151,15 @@ class NotificationsInboxViewModel( notifications = notifications.toMap() ) } + logEvent( + event = NotificationsAnalyticsEvent.NOTIFICATION_ITEM_TAPPED, + params = buildMap { + put( + NotificationsAnalyticsKey.NOTIFICATION_TYPE.key, + notification.notificationType + ) + } + ) // Navigating the user to the related post or response in the Course Discussion Tab if(notification.courseId.isNotEmpty()) { @@ -192,4 +218,22 @@ class NotificationsInboxViewModel( ) } } + + private fun logEvent(event: NotificationsAnalyticsEvent, params: Map) { + analytics.logEvent( + event = event.eventName, + params = buildMap { + put(NotificationsAnalyticsKey.NAME.key, event.biValue) + put( + NotificationsAnalyticsKey.CATEGORY.key, + NotificationsAnalyticsKey.NOTIFICATIONS.key + ) + put( + NotificationsAnalyticsKey.NOTIFICATION_CATEGORY.key, + NotificationsAnalyticsKey.DISCUSSION.key + ) + putAll(params) + } + ) + } }