Skip to content

Commit 133f489

Browse files
feat: course home analytic
1 parent 05fc280 commit 133f489

File tree

3 files changed

+164
-66
lines changed

3 files changed

+164
-66
lines changed

course/src/main/java/org/openedx/course/presentation/CourseAnalytics.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ enum class CourseAnalyticsEvent(val eventName: String, val biValue: String) {
178178
"Course:Assignment Tab.Assignment Clicked",
179179
"edx.bi.app.course.assignment_tab.assignment.clicked"
180180
),
181+
COURSE_HOME_SECTION_SUBSECTION_CLICK(
182+
"Course Home.Section/Subsection Click",
183+
"edx.bi.app.course.home.section_subsection.clicked"
184+
),
185+
COURSE_HOME_VIEW_ALL_CONTENT(
186+
"Course Home.View All Content",
187+
"edx.bi.app.course.home.view_all_content.clicked"
188+
),
189+
COURSE_HOME_VIEW_ALL_VIDEOS(
190+
"Course Home.View All Videos",
191+
"edx.bi.app.course.home.view_all_videos.clicked"
192+
),
193+
COURSE_HOME_VIEW_ALL_ASSIGNMENTS(
194+
"Course Home.View All Assignments",
195+
"edx.bi.app.course.home.view_all_assignments.clicked"
196+
),
197+
COURSE_HOME_GRADES_VIEW_PROGRESS(
198+
"Course Home.Grades.View Progress",
199+
"edx.bi.app.course.home.grades.view_progress.clicked"
200+
),
181201
}
182202

183203
enum class CourseAnalyticsKey(val key: String) {

course/src/main/java/org/openedx/course/presentation/home/CourseHomeScreen.kt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ fun CourseHomeScreen(
9999
uiMessage = uiMessage,
100100
homePagerState = homePagerState,
101101
onSubSectionClick = { subSectionBlock ->
102+
// Log section/subsection click event
103+
viewModel.logSectionSubsectionClick(
104+
subSectionBlock.blockId,
105+
subSectionBlock.displayName
106+
)
102107
if (viewModel.isCourseDropdownNavigationEnabled) {
103108
viewModel.courseSubSectionUnit[subSectionBlock.id]?.let { unit ->
104-
viewModel.logUnitDetailViewedEvent(
105-
unit.blockId,
106-
unit.displayName
107-
)
108109
viewModel.courseRouter.navigateToCourseContainer(
109110
fragmentManager,
110111
courseId = viewModel.courseId,
@@ -113,10 +114,6 @@ fun CourseHomeScreen(
113114
)
114115
}
115116
} else {
116-
viewModel.sequentialClickedEvent(
117-
subSectionBlock.blockId,
118-
subSectionBlock.displayName
119-
)
120117
viewModel.courseRouter.navigateToCourseSubsections(
121118
fm = fragmentManager,
122119
courseId = viewModel.courseId,
@@ -169,7 +166,11 @@ fun CourseHomeScreen(
169166
},
170167
onNavigateToContent = onNavigateToContent,
171168
onNavigateToProgress = onNavigateToProgress,
172-
getBlockParent = viewModel::getBlockParent
169+
getBlockParent = viewModel::getBlockParent,
170+
onViewAllContentClick = viewModel::logViewAllContentClick,
171+
onViewAllVideosClick = viewModel::logViewAllVideosClick,
172+
onViewAllAssignmentsClick = viewModel::logViewAllAssignmentsClick,
173+
onViewProgressClick = viewModel::logViewProgressClick
173174
)
174175
}
175176

@@ -189,6 +190,10 @@ private fun CourseHomeUI(
189190
onNavigateToContent: (CourseContentTab) -> Unit,
190191
onNavigateToProgress: () -> Unit,
191192
getBlockParent: (blockId: String) -> Block?,
193+
onViewAllContentClick: () -> Unit,
194+
onViewAllVideosClick: () -> Unit,
195+
onViewAllAssignmentsClick: () -> Unit,
196+
onViewProgressClick: () -> Unit,
192197
) {
193198
val scaffoldState = rememberScaffoldState()
194199

@@ -299,6 +304,7 @@ private fun CourseHomeUI(
299304
CourseCompletionHomePagerCardContent(
300305
uiState = uiState,
301306
onViewAllContentClick = {
307+
onViewAllContentClick()
302308
onNavigateToContent(CourseContentTab.ALL)
303309
},
304310
onDownloadClick = onDownloadClick,
@@ -311,6 +317,7 @@ private fun CourseHomeUI(
311317
uiState = uiState,
312318
onVideoClick = onVideoClick,
313319
onViewAllVideosClick = {
320+
onViewAllVideosClick()
314321
onNavigateToContent(CourseContentTab.VIDEOS)
315322
}
316323
)
@@ -322,6 +329,7 @@ private fun CourseHomeUI(
322329
onAssignmentClick = onAssignmentClick,
323330
getBlockParent = getBlockParent,
324331
onViewAllAssignmentsClick = {
332+
onViewAllAssignmentsClick()
325333
onNavigateToContent(CourseContentTab.ASSIGNMENTS)
326334
}
327335
)
@@ -330,7 +338,10 @@ private fun CourseHomeUI(
330338
CourseHomePagerTab.GRADES -> {
331339
GradesHomePagerCardContent(
332340
uiState = uiState,
333-
onViewProgressClick = onNavigateToProgress
341+
onViewProgressClick = {
342+
onViewProgressClick()
343+
onNavigateToProgress()
344+
}
334345
)
335346
}
336347
}
@@ -458,6 +469,10 @@ private fun CourseHomeScreenPreview() {
458469
onNavigateToContent = { _ -> },
459470
onNavigateToProgress = {},
460471
getBlockParent = { null },
472+
onViewAllContentClick = {},
473+
onViewAllVideosClick = {},
474+
onViewAllAssignmentsClick = {},
475+
onViewProgressClick = {},
461476
)
462477
}
463478
}
@@ -507,6 +522,10 @@ private fun CourseHomeScreenTabletPreview() {
507522
onNavigateToContent = { _ -> },
508523
onNavigateToProgress = { },
509524
getBlockParent = { null },
525+
onViewAllContentClick = {},
526+
onViewAllVideosClick = {},
527+
onViewAllAssignmentsClick = {},
528+
onViewProgressClick = {},
510529
)
511530
}
512531
}

course/src/main/java/org/openedx/course/presentation/home/CourseHomeViewModel.kt

Lines changed: 115 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -417,62 +417,6 @@ class CourseHomeViewModel(
417417
}
418418
}
419419

420-
fun viewCertificateTappedEvent() {
421-
analytics.logEvent(
422-
CourseAnalyticsEvent.VIEW_CERTIFICATE.eventName,
423-
buildMap {
424-
put(CourseAnalyticsKey.NAME.key, CourseAnalyticsEvent.VIEW_CERTIFICATE.biValue)
425-
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
426-
}
427-
)
428-
}
429-
430-
private fun resumeCourseTappedEvent(blockId: String) {
431-
val currentState = uiState.value
432-
if (currentState is CourseHomeUIState.CourseData) {
433-
analytics.logEvent(
434-
CourseAnalyticsEvent.RESUME_COURSE_CLICKED.eventName,
435-
buildMap {
436-
put(
437-
CourseAnalyticsKey.NAME.key,
438-
CourseAnalyticsEvent.RESUME_COURSE_CLICKED.biValue
439-
)
440-
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
441-
put(CourseAnalyticsKey.COURSE_NAME.key, courseTitle)
442-
put(CourseAnalyticsKey.BLOCK_ID.key, blockId)
443-
}
444-
)
445-
}
446-
}
447-
448-
fun sequentialClickedEvent(blockId: String, blockName: String) {
449-
val currentState = uiState.value
450-
if (currentState is CourseHomeUIState.CourseData) {
451-
analytics.sequentialClickedEvent(
452-
courseId,
453-
currentState.courseStructure.name,
454-
blockId,
455-
blockName
456-
)
457-
}
458-
}
459-
460-
fun logUnitDetailViewedEvent(blockId: String, blockName: String) {
461-
val currentState = uiState.value
462-
if (currentState is CourseHomeUIState.CourseData) {
463-
analytics.logEvent(
464-
CourseAnalyticsEvent.UNIT_DETAIL.eventName,
465-
buildMap {
466-
put(CourseAnalyticsKey.NAME.key, CourseAnalyticsEvent.UNIT_DETAIL.biValue)
467-
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
468-
put(CourseAnalyticsKey.COURSE_NAME.key, courseTitle)
469-
put(CourseAnalyticsKey.BLOCK_ID.key, blockId)
470-
put(CourseAnalyticsKey.BLOCK_NAME.key, blockName)
471-
}
472-
)
473-
}
474-
}
475-
476420
fun downloadBlocks(blocksIds: List<String>, fragmentManager: FragmentManager) {
477421
viewModelScope.launch {
478422
val courseData = _uiState.value as? CourseHomeUIState.CourseData ?: return@launch
@@ -589,4 +533,119 @@ class CourseHomeViewModel(
589533
)
590534
}
591535
}
536+
537+
fun viewCertificateTappedEvent() {
538+
analytics.logEvent(
539+
CourseAnalyticsEvent.VIEW_CERTIFICATE.eventName,
540+
buildMap {
541+
put(CourseAnalyticsKey.NAME.key, CourseAnalyticsEvent.VIEW_CERTIFICATE.biValue)
542+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
543+
}
544+
)
545+
}
546+
547+
private fun resumeCourseTappedEvent(blockId: String) {
548+
val currentState = uiState.value
549+
if (currentState is CourseHomeUIState.CourseData) {
550+
analytics.logEvent(
551+
CourseAnalyticsEvent.RESUME_COURSE_CLICKED.eventName,
552+
buildMap {
553+
put(
554+
CourseAnalyticsKey.NAME.key,
555+
CourseAnalyticsEvent.RESUME_COURSE_CLICKED.biValue
556+
)
557+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
558+
put(CourseAnalyticsKey.COURSE_NAME.key, courseTitle)
559+
put(CourseAnalyticsKey.BLOCK_ID.key, blockId)
560+
}
561+
)
562+
}
563+
}
564+
565+
fun logSectionSubsectionClick(blockId: String, blockName: String) {
566+
val currentState = uiState.value
567+
if (currentState is CourseHomeUIState.CourseData) {
568+
analytics.logEvent(
569+
CourseAnalyticsEvent.COURSE_HOME_SECTION_SUBSECTION_CLICK.eventName,
570+
buildMap {
571+
put(
572+
CourseAnalyticsKey.NAME.key,
573+
CourseAnalyticsEvent.COURSE_HOME_SECTION_SUBSECTION_CLICK.biValue
574+
)
575+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
576+
put(CourseAnalyticsKey.COURSE_NAME.key, currentState.courseStructure.name)
577+
put(CourseAnalyticsKey.BLOCK_ID.key, blockId)
578+
put(CourseAnalyticsKey.BLOCK_NAME.key, blockName)
579+
}
580+
)
581+
}
582+
}
583+
584+
fun logViewAllContentClick() {
585+
val currentState = uiState.value
586+
if (currentState is CourseHomeUIState.CourseData) {
587+
analytics.logEvent(
588+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_CONTENT.eventName,
589+
buildMap {
590+
put(
591+
CourseAnalyticsKey.NAME.key,
592+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_CONTENT.biValue
593+
)
594+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
595+
put(CourseAnalyticsKey.COURSE_NAME.key, currentState.courseStructure.name)
596+
}
597+
)
598+
}
599+
}
600+
601+
fun logViewAllVideosClick() {
602+
val currentState = uiState.value
603+
if (currentState is CourseHomeUIState.CourseData) {
604+
analytics.logEvent(
605+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_VIDEOS.eventName,
606+
buildMap {
607+
put(
608+
CourseAnalyticsKey.NAME.key,
609+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_VIDEOS.biValue
610+
)
611+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
612+
put(CourseAnalyticsKey.COURSE_NAME.key, currentState.courseStructure.name)
613+
}
614+
)
615+
}
616+
}
617+
618+
fun logViewAllAssignmentsClick() {
619+
val currentState = uiState.value
620+
if (currentState is CourseHomeUIState.CourseData) {
621+
analytics.logEvent(
622+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_ASSIGNMENTS.eventName,
623+
buildMap {
624+
put(
625+
CourseAnalyticsKey.NAME.key,
626+
CourseAnalyticsEvent.COURSE_HOME_VIEW_ALL_ASSIGNMENTS.biValue
627+
)
628+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
629+
put(CourseAnalyticsKey.COURSE_NAME.key, currentState.courseStructure.name)
630+
}
631+
)
632+
}
633+
}
634+
635+
fun logViewProgressClick() {
636+
val currentState = uiState.value
637+
if (currentState is CourseHomeUIState.CourseData) {
638+
analytics.logEvent(
639+
CourseAnalyticsEvent.COURSE_HOME_GRADES_VIEW_PROGRESS.eventName,
640+
buildMap {
641+
put(
642+
CourseAnalyticsKey.NAME.key,
643+
CourseAnalyticsEvent.COURSE_HOME_GRADES_VIEW_PROGRESS.biValue
644+
)
645+
put(CourseAnalyticsKey.COURSE_ID.key, courseId)
646+
put(CourseAnalyticsKey.COURSE_NAME.key, currentState.courseStructure.name)
647+
}
648+
)
649+
}
650+
}
592651
}

0 commit comments

Comments
 (0)