Skip to content

Commit

Permalink
fix: Added analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Jan 17, 2025
1 parent 0a272b5 commit fa14fa1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiscussionRouter>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ 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) {
NAME("name"),
ACTION("action"),
CATEGORY("category"),
NOTIFICATIONS("notifications"),
NOTIFICATION_CATEGORY("notification_category"),
DISCUSSION("discussion"),
NOTIFICATION_TYPE("notification_type"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>(InboxUIState.Loading)
Expand All @@ -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()
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -192,4 +218,22 @@ class NotificationsInboxViewModel(
)
}
}

private fun logEvent(event: NotificationsAnalyticsEvent, params: Map<String, Any?>) {
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)
}
)
}
}

0 comments on commit fa14fa1

Please sign in to comment.