diff --git a/openedx/features/course_bookmarks/plugins.py b/openedx/features/course_bookmarks/plugins.py
index 95e73f0af8..bb8921823c 100644
--- a/openedx/features/course_bookmarks/plugins.py
+++ b/openedx/features/course_bookmarks/plugins.py
@@ -13,6 +13,13 @@ class CourseBookmarksTool(CourseTool):
"""
The course bookmarks tool.
"""
+ @classmethod
+ def analytics_id(cls):
+ """
+ Returns an id to uniquely identify this tool in analytics events.
+ """
+ return 'edx.bookmarks'
+
@classmethod
def is_enabled(cls, request, course_key):
"""
diff --git a/openedx/features/course_experience/course_tools.py b/openedx/features/course_experience/course_tools.py
index 82fe4be708..3be140ecc3 100644
--- a/openedx/features/course_experience/course_tools.py
+++ b/openedx/features/course_experience/course_tools.py
@@ -16,6 +16,14 @@ class CourseTool(object):
not a requirement, and plugin implementations outside of this repo should
simply follow the contract defined below.
"""
+ @classmethod
+ def analytics_id(cls):
+ """
+ Returns an id to uniquely identify this tool in analytics events.
+
+ For example, 'edx.bookmarks'. New tools may warrant doc updates for the new id.
+ """
+ raise NotImplementedError("Must specify an id to enable course tool eventing.")
@classmethod
def is_enabled(cls, request, course_key):
diff --git a/openedx/features/course_experience/plugins.py b/openedx/features/course_experience/plugins.py
index e2aa0fe2bf..a47cf7eb4d 100644
--- a/openedx/features/course_experience/plugins.py
+++ b/openedx/features/course_experience/plugins.py
@@ -19,6 +19,13 @@ class CourseUpdatesTool(CourseTool):
"""
The course updates tool.
"""
+ @classmethod
+ def analytics_id(cls):
+ """
+ Returns an analytics id for this tool, used for eventing.
+ """
+ return 'edx.updates'
+
@classmethod
def title(cls):
"""
@@ -57,6 +64,13 @@ class CourseReviewsTool(CourseTool):
"""
The course reviews tool.
"""
+ @classmethod
+ def analytics_id(cls):
+ """
+ Returns an id to uniquely identify this tool in analytics events.
+ """
+ return 'edx.reviews'
+
@classmethod
def title(cls):
"""
diff --git a/openedx/features/course_experience/static/course_experience/fixtures/course-home-fragment.html b/openedx/features/course_experience/static/course_experience/fixtures/course-home-fragment.html
index 42fdd71c75..f4a255ec87 100644
--- a/openedx/features/course_experience/static/course_experience/fixtures/course-home-fragment.html
+++ b/openedx/features/course_experience/static/course_experience/fixtures/course-home-fragment.html
@@ -67,19 +67,19 @@
Course Tools
-
-
+
Bookmarks
-
-
+
Reviews
-
-
+
Updates
diff --git a/openedx/features/course_experience/static/course_experience/js/CourseHome.js b/openedx/features/course_experience/static/course_experience/js/CourseHome.js
index cedc8701b8..274bddda50 100644
--- a/openedx/features/course_experience/static/course_experience/js/CourseHome.js
+++ b/openedx/features/course_experience/static/course_experience/js/CourseHome.js
@@ -4,13 +4,12 @@ export class CourseHome { // eslint-disable-line import/prefer-default-export
constructor(options) {
// Logging for course tool click events
const $courseToolLink = $(options.courseToolLink);
- $courseToolLink.on('click', () => {
- const courseToolName = document.querySelector('.course-tool-link').text.trim().toLowerCase();
+ $courseToolLink.on('click', (event) => {
+ const courseToolName = event.srcElement.dataset['analytics-id']; // eslint-disable-line dot-notation
Logger.log(
'edx.course.tool.accessed',
{
tool_name: courseToolName,
- page: 'course_home',
},
);
});
diff --git a/openedx/features/course_experience/static/course_experience/js/spec/CourseHome_spec.js b/openedx/features/course_experience/static/course_experience/js/spec/CourseHome_spec.js
index d9af744bee..1fb00e1e4f 100644
--- a/openedx/features/course_experience/static/course_experience/js/spec/CourseHome_spec.js
+++ b/openedx/features/course_experience/static/course_experience/js/spec/CourseHome_spec.js
@@ -15,15 +15,19 @@ describe('Course Home factory', () => {
});
it('sends an event when an course tool is clicked', () => {
- document.querySelector('.course-tool-link').dispatchEvent(new Event('click'));
- const courseToolName = document.querySelector('.course-tool-link').text.trim().toLowerCase();
- expect(Logger.log).toHaveBeenCalledWith(
- 'edx.course.tool.accessed',
- {
- tool_name: courseToolName,
- page: 'course_home',
- },
- );
+ const courseToolNames = document.querySelectorAll('.course-tool-link');
+ for (let i = 0; i < courseToolNames.length; i += 1) {
+ const courseToolName = courseToolNames[i].dataset['analytics-id']; // eslint-disable-line dot-notation
+ const event = new CustomEvent('click');
+ event.srcElement = { dataset: { 'analytics-id': courseToolName } };
+ courseToolNames[i].dispatchEvent(event);
+ expect(Logger.log).toHaveBeenCalledWith(
+ 'edx.course.tool.accessed',
+ {
+ tool_name: courseToolName,
+ },
+ );
+ }
});
});
});
diff --git a/openedx/features/course_experience/templates/course_experience/course-home-fragment.html b/openedx/features/course_experience/templates/course_experience/course-home-fragment.html
index d68617a2d0..42b4c8d27a 100644
--- a/openedx/features/course_experience/templates/course_experience/course-home-fragment.html
+++ b/openedx/features/course_experience/templates/course_experience/course-home-fragment.html
@@ -74,7 +74,7 @@ from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, SHOW_REV