Skip to content

Commit

Permalink
feat: added snowflake events for email digest unsubscribe (#35329)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul authored Aug 26, 2024
1 parent 5fbcc79 commit 71f410e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/notifications/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
15 changes: 15 additions & 0 deletions openedx/core/djangoapps/notifications/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 71f410e

Please sign in to comment.