'Emits an event to explicitly track course enrollment and unenrollment.'

def emit_event(self, event_name):

    try:
        context = contexts.course_context_from_course_id(self.course_id)
        assert isinstance(self.course_id, CourseKey)
        data = {'user_id': self.user.id, 'course_id': self.course_id.to_deprecated_string(), 'mode': self.mode}
        with tracker.get_tracker().context(event_name, context):
            tracker.emit(event_name, data)
            if (hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY):
                tracking_context = tracker.get_tracker().resolve_context()
                analytics.track(self.user_id, event_name, {'category': 'conversion', 'label': self.course_id.to_deprecated_string(), 'org': self.course_id.org, 'course': self.course_id.course, 'run': self.course_id.run, 'mode': self.mode}, context={'ip': tracking_context.get('ip'), 'Google    Analytics': {'clientId': tracking_context.get('client_id')}})
    except:
        if (event_name and self.course_id):
            log.exception(u'Unable    to    emit    event    %s    for    user    %s    and    course    %s', event_name, self.user.username, self.course_id)
