Skip to content

Commit

Permalink
feat: [VAN-1081] - Set weekly goal and start course events via query …
Browse files Browse the repository at this point in the history
…param (#972)
  • Loading branch information
shafqatfarhan authored Sep 13, 2022
1 parent 5a897e4 commit b3841ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
22 changes: 20 additions & 2 deletions src/course-home/outline-tab/OutlineTab.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 (
<>
<div data-learner-type={learnerType} className="row w-100 mx-0 my-3 justify-content-between">
Expand Down
15 changes: 7 additions & 8 deletions src/course-home/outline-tab/OutlineTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ function WeeklyLearningGoalCard({
is_staff: administrator,
num_days: days,
reminder_selected: selectReminders,
triggeredFromEmail,
});
if (triggeredFromEmail) {
sendTrackEvent('welcome.email.clicked.setgoal', {});
}
}
}

Expand Down

0 comments on commit b3841ef

Please sign in to comment.