diff --git a/openedx/core/djangoapps/notifications/email/utils.py b/openedx/core/djangoapps/notifications/email/utils.py index da288750bb7d..e36c435e8ac0 100644 --- a/openedx/core/djangoapps/notifications/email/utils.py +++ b/openedx/core/djangoapps/notifications/email/utils.py @@ -19,6 +19,7 @@ ) from openedx.core.djangoapps.notifications.config.waffle import ENABLE_EMAIL_NOTIFICATIONS from openedx.core.djangoapps.notifications.email_notifications import EmailCadence +from openedx.core.djangoapps.notifications.events import notification_preference_unsubscribe_event from openedx.core.djangoapps.notifications.models import ( CourseNotificationPreference, get_course_notification_preference_config_version @@ -395,3 +396,4 @@ def get_updated_preference(pref): if pref_value else EmailCadence.NEVER type_prefs['email_cadence'] = cadence_value preference.save() + notification_preference_unsubscribe_event(user) diff --git a/openedx/core/djangoapps/notifications/events.py b/openedx/core/djangoapps/notifications/events.py index fb50e134941b..91b12075a8a1 100644 --- a/openedx/core/djangoapps/notifications/events.py +++ b/openedx/core/djangoapps/notifications/events.py @@ -10,6 +10,7 @@ NOTIFICATION_APP_ALL_READ = 'edx.notifications.app_all_read' NOTIFICATION_PREFERENCES_UPDATED = 'edx.notifications.preferences.updated' NOTIFICATION_TRAY_OPENED = 'edx.notifications.tray_opened' +NOTIFICATION_PREFERENCE_UNSUBSCRIBE = 'edx.notifications.preferences.one_click_unsubscribe' def get_user_forums_roles(user, course_id): @@ -155,3 +156,17 @@ def notification_tray_opened_event(user, unseen_notifications_count): 'unseen_notifications_count': unseen_notifications_count, } ) + + +def notification_preference_unsubscribe_event(user): + """ + Emits an event when user clicks on one-click-unsubscribe url + """ + event_data = { + 'user_id': user.id, + 'username': user.username, + 'event_type': 'email_digest_unsubscribe' + } + with tracker.get_tracker().context(NOTIFICATION_PREFERENCE_UNSUBSCRIBE, event_data): + tracker.emit(NOTIFICATION_PREFERENCE_UNSUBSCRIBE, event_data) + segment.track(user.id, NOTIFICATION_PREFERENCE_UNSUBSCRIBE, event_data)