Browse Source

[web] track email notification settings interactions (#32719)

* send setting-changed event
* emit event for global mute notifications

GitOrigin-RevId: 0705ffc331185e0f49fa1103e856040548d4f8bf
Kristina 4 months ago
parent
commit
5c92f85d51

+ 9 - 1
services/web/frontend/js/features/settings/hooks/use-project-notification-preferences.ts

@@ -3,6 +3,8 @@ import { useProjectContext } from '@/shared/context/project-context'
 import { getJSON, postJSON } from '@/infrastructure/fetch-json'
 import { getJSON, postJSON } from '@/infrastructure/fetch-json'
 import { debugConsole } from '@/utils/debugging'
 import { debugConsole } from '@/utils/debugging'
 import type { NotificationPreferencesSchema } from '../../../../../modules/notifications/app/src/types.js'
 import type { NotificationPreferencesSchema } from '../../../../../modules/notifications/app/src/types.js'
+import { sendMB } from '@/infrastructure/event-tracking'
+import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
 
 
 export type NotificationLevel = 'all' | 'replies' | 'off'
 export type NotificationLevel = 'all' | 'replies' | 'off'
 
 
@@ -83,6 +85,7 @@ function preferencesToLevel(
 
 
 export function useProjectNotificationPreferences() {
 export function useProjectNotificationPreferences() {
   const { projectId } = useProjectContext()
   const { projectId } = useProjectContext()
+  const { permissionsLevel } = useIdeReactContext()
   const [notificationLevel, setNotificationLevel] =
   const [notificationLevel, setNotificationLevel] =
     useState<NotificationLevel>('all')
     useState<NotificationLevel>('all')
   const [isLoading, setIsLoading] = useState(true)
   const [isLoading, setIsLoading] = useState(true)
@@ -103,11 +106,16 @@ export function useProjectNotificationPreferences() {
     (level: NotificationLevel) => {
     (level: NotificationLevel) => {
       setNotificationLevel(level)
       setNotificationLevel(level)
       const preferences = levelToPreferences(level)
       const preferences = levelToPreferences(level)
+      sendMB('setting-changed', {
+        changedSetting: 'projectEmailNotifications',
+        changedSettingVal: level,
+        projectRole: permissionsLevel,
+      })
       postJSON(`/notifications/preferences/project/${projectId}`, {
       postJSON(`/notifications/preferences/project/${projectId}`, {
         body: preferences,
         body: preferences,
       }).catch(debugConsole.error)
       }).catch(debugConsole.error)
     },
     },
-    [projectId]
+    [projectId, permissionsLevel]
   )
   )
 
 
   return {
   return {