diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index a101e749ad..08d1e2cc2c 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -1495,6 +1495,10 @@ class CourseEnrollment(models.Model): segment_traits = dict(segment_properties) # Add course_title to the traits, as it is used by Hubspot filters segment_traits['course_title'] = self.course_overview.display_name if self.course_overview else None + # Hubspot requires all incoming events have an email address to link it + # to a Contact object. + segment_traits['email'] = self.user.email + if event_name == EVENT_NAME_ENROLLMENT_ACTIVATED: segment_properties['email'] = self.user.email # This next property is for an experiment, see method's comments for more information diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index 1b6e074746..483aa39f46 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -174,6 +174,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase): traits = mock_segment.track.call_args[1]['traits'] assert traits['course_title'] == self.course.display_name assert traits['mode'] == 'audit' + assert traits['email'] == self.EMAIL with patch('common.djangoapps.student.models.segment') as mock_segment: enrollment.update_enrollment(mode='verified') @@ -182,6 +183,7 @@ class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase): traits = mock_segment.track.call_args[1]['traits'] assert traits['course_title'] == self.course.display_name assert traits['mode'] == 'verified' + assert traits['email'] == self.EMAIL @patch.dict(settings.FEATURES, {'ENABLE_MKTG_EMAIL_OPT_IN': True}) @patch('openedx.core.djangoapps.user_api.preferences.api.update_email_opt_in')