diff --git a/src/course-home/outline-tab/OutlineTab.jsx b/src/course-home/outline-tab/OutlineTab.jsx index f83b4a86df..cce754fff4 100644 --- a/src/course-home/outline-tab/OutlineTab.jsx +++ b/src/course-home/outline-tab/OutlineTab.jsx @@ -1,9 +1,10 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; +import { useLocation } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; +import { history } from '@edx/frontend-platform'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; - import { Button } from '@edx/paragon'; import { AlertList } from '../../generic/user-messages'; @@ -109,6 +110,23 @@ function OutlineTab({ intl }) { /** show post enrolment survey to only B2C learners */ const learnerType = isEnterpriseUser() ? 'enterprise_learner' : 'b2c_learner'; + const location = useLocation(); + + useEffect(() => { + const currentParams = new URLSearchParams(location.search); + const startCourse = currentParams.get('start_course'); + if (startCourse === '1') { + sendTrackEvent('welcome.email.clicked.startcourse', {}); + + // Deleting the course_start query param as it only needs to be set once + // whenever passed in query params. + currentParams.delete('start_course'); + history.replace({ + search: currentParams.toString(), + }); + } + }, [location.search]); + return ( <>
diff --git a/src/course-home/outline-tab/OutlineTab.test.jsx b/src/course-home/outline-tab/OutlineTab.test.jsx index f36ac523bd..719f60253f 100644 --- a/src/course-home/outline-tab/OutlineTab.test.jsx +++ b/src/course-home/outline-tab/OutlineTab.test.jsx @@ -355,14 +355,13 @@ describe('Outline Tab', () => { await fetchAndRender('http://localhost/?weekly_goal=3'); expect(spy).toHaveBeenCalledTimes(1); - expect(sendTrackEvent).toHaveBeenCalledWith('edx.ui.lms.goal.days-per-week.changed', { - org_key: 'edX', - courserun_key: courseId, - is_staff: false, - num_days: 3, - reminder_selected: true, - triggeredFromEmail: true, - }); + expect(sendTrackEvent).toHaveBeenCalledWith('welcome.email.clicked.setgoal', {}); + }); + + it('emit start course event via query param', async () => { + sendTrackEvent.mockClear(); + await fetchAndRender('http://localhost/?start_course=1'); + expect(sendTrackEvent).toHaveBeenCalledWith('welcome.email.clicked.startcourse', {}); }); describe('weekly learning goal is not set', () => { diff --git a/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx b/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx index fef6f46c08..a4fc8e6467 100644 --- a/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx +++ b/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx @@ -49,8 +49,10 @@ function WeeklyLearningGoalCard({ is_staff: administrator, num_days: days, reminder_selected: selectReminders, - triggeredFromEmail, }); + if (triggeredFromEmail) { + sendTrackEvent('welcome.email.clicked.setgoal', {}); + } } }