feat: added snowflake events for email digest unsubscribe (#35329)

This commit is contained in:
Muhammad Adeel Tajamul
2024-08-25 23:24:05 -07:00
committed by GitHub
parent 5fbcc794cf
commit 71f410eb40
2 changed files with 17 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ from openedx.core.djangoapps.notifications.base_notification import (
)
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 update_user_preferences_from_patch(encrypted_username, encrypted_patch):
if pref_value else EmailCadence.NEVER
type_prefs['email_cadence'] = cadence_value
preference.save()
notification_preference_unsubscribe_event(user)

View File

@@ -10,6 +10,7 @@ NOTIFICATION_READ = 'edx.notifications.read'
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)