diff --git a/src/components/Disclosure/index.jsx b/src/components/Disclosure/index.jsx index 68e284de..c617627a 100644 --- a/src/components/Disclosure/index.jsx +++ b/src/components/Disclosure/index.jsx @@ -14,7 +14,7 @@ const Disclosure = ({ children }) => { const { upgradeable, upgradeUrl, auditTrialLengthDays } = useCourseUpgrade(); const { track } = useTrackEvent(); - const handleClick = () => track('edx.ui.lms.learning_assistant.message'); + const handleClick = () => track('edx.ui.lms.learning_assistant.disclosure_upgrade_click'); const freeDays = auditTrialLengthDays === 1 ? '1 day' : `${auditTrialLengthDays} days`; return ( diff --git a/src/components/Disclosure/index.test.jsx b/src/components/Disclosure/index.test.jsx index a08d3f7d..f40b4380 100644 --- a/src/components/Disclosure/index.test.jsx +++ b/src/components/Disclosure/index.test.jsx @@ -85,7 +85,7 @@ describe('', () => { fireEvent.click(upgradeCta); - expect(mockedTrackEvent).toHaveBeenCalledWith('edx.ui.lms.learning_assistant.message'); + expect(mockedTrackEvent).toHaveBeenCalledWith('edx.ui.lms.learning_assistant.disclosure_upgrade_click'); }); it('should match snapshot', () => { diff --git a/src/hooks/use-course-upgrade.js b/src/hooks/use-course-upgrade.js index 8870dc5a..7247a7ad 100644 --- a/src/hooks/use-course-upgrade.js +++ b/src/hooks/use-course-upgrade.js @@ -5,6 +5,29 @@ import { CourseInfoContext } from '../context'; const millisecondsInOneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds +/** + * @typedef AuditTrial + * @type {object} + * @property {string} startDate Date String with the Trial start date. + * @property {string} expirationDate Date String with the Trial expiration date. + */ + +/** + * @typedef CourseUpgradeInfo + * @type {object} + * @property {boolean} upgradeable Should this user see a trial/upgrade option?. + * @property {number} [auditTrialLengthDays] Audit Trial full length in days. + * @property {number} [auditTrialDaysRemaining] Remaining day for the current trial (if any). + * @property {boolean} [auditTrialExpired] True means that the audit has been taken and expired. + * @property {AuditTrial} [auditTrial] The Audit trial information. Undefined if there's no trial for this user. + * @property {string} [upgradeUrl] URL to redirect the user in case there's intention to upgrade. + */ + +/** + * This hook returns related data for the Course Upgrade. + * + * @returns {CourseUpgradeInfo} + */ export default function useCourseUpgrade() { const { courseId, isUpgradeEligible } = useContext(CourseInfoContext); const { offer } = useModel('coursewareMeta', courseId); diff --git a/src/hooks/use-track-event.js b/src/hooks/use-track-event.js index 7205326c..6993577c 100644 --- a/src/hooks/use-track-event.js +++ b/src/hooks/use-track-event.js @@ -3,6 +3,17 @@ import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { CourseInfoContext } from '../context'; +/** + * @typedef Tracker + * @type {object} + * @property {(eventName: string, details?: object)} track Calls sendTrackEvent with user and course context. + */ + +/** + * This hook returns a track method to track events. + * + * @returns {Tracker} + */ export default function useTrackEvent() { const { courseId, moduleId } = useContext(CourseInfoContext); const { userId } = getAuthenticatedUser();