From 51de0e4e3e91cfe15faba4777d4e38f2fd1c3352 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Wed, 26 Jun 2024 12:39:56 +0200 Subject: [PATCH 1/7] refactor: :recycle: fix the event names used to track notifications --- shared/constants/metametrics.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/shared/constants/metametrics.ts b/shared/constants/metametrics.ts index 82c6a557be4f..b74162362838 100644 --- a/shared/constants/metametrics.ts +++ b/shared/constants/metametrics.ts @@ -516,17 +516,17 @@ export enum MetaMetricsEventName { DecryptionApproved = 'Decryption Approved', DecryptionRejected = 'Decryption Rejected', DecryptionRequested = 'Decryption Requested', - DisablingAccountNotifications = 'Disabling Account Notifications', - EnablingAccountNotifications = 'Enabling Account Notifications', - DisablingNotifications = 'Disabling Notifications', - DismissEnablingNotificationsFlow = 'Dismiss Enabling Notifications Flow', + DisablingAccountNotifications = 'Account Notifications Disabled', + EnablingAccountNotifications = 'Account Notifications Enabled', + DisablingNotifications = 'Notifications Disabled', + DismissEnablingNotificationsFlow = 'Notifications Enabling Flow Dismissed', EmptyBuyBannerDisplayed = 'Empty Buy Banner Displayed', EmptyBuyBannerClicked = 'Empty Buy Banner Clicked', EmptyReceiveBannerDisplayed = 'Empty Receive Banner Displayed', EmptyReceiveBannerClicked = 'Empty Receive Banner Clicked', EmptyNftsBannerDisplayed = 'Empty NFTs Banner Displayed', EmptyNftsBannerClicked = 'Empty NFTs Banner Clicked', - EnablingNotifications = 'Enabling Notifications', + EnablingNotifications = 'Notifications Enabled', EncryptionPublicKeyApproved = 'Encryption Approved', EncryptionPublicKeyRejected = 'Encryption Rejected', EncryptionPublicKeyRequested = 'Encryption Requested', @@ -545,7 +545,7 @@ export enum MetaMetricsEventName { KeyGasFeeEstimationBuySwapTokens = 'Key Show Gas Fee Estimation, Buy Crypto and Swap Tokens', KeyAutoDetectTokens = 'Key Autodetect tokens', KeyBatchAccountBalanceRequests = 'Key Batch account balance requests', - MarkAllNotificationsRead = 'Mark All Notifications Read', + MarkAllNotificationsRead = 'Notifications Marked All as Read', MetricsOptIn = 'Metrics Opt In', MetricsOptOut = 'Metrics Opt Out', NavAccountMenuOpened = 'Account Menu Opened', @@ -574,13 +574,13 @@ export enum MetaMetricsEventName { OnboardingWalletSecurityPhraseWrittenDown = 'SRP Backup Confirm Display', OnboardingWalletSecurityPhraseConfirmed = 'SRP Backup Confirmed', OnboardingWalletCreationComplete = 'Wallet Created', - OnboardingWalletCreationCompleteWithAuthenticating = 'Wallet Created with Authenticating', + OnboardingWalletCreationCompleteWithAuthenticating = 'Wallet with Authentication Created', OnboardingWalletSetupComplete = 'Application Opened', OnboardingWalletAdvancedSettings = 'Settings Updated', OnboardingWalletAdvancedSettingsWithAuthenticating = 'Settings Updated with Authenticating', OnboardingWalletAdvancedSettingsWithoutAuthenticating = 'Settings Updated without Authenticating', - OnboardingWalletAdvancedSettingsTurnOffProfileSyncing = 'Turn Off Profile Syncing', - OnboardingWalletAdvancedSettingsTurnOnProfileSyncing = 'Turn On Profile Syncing', + OnboardingWalletAdvancedSettingsTurnOffProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned Off', + OnboardingWalletAdvancedSettingsTurnOnProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned On', OnboardingWalletImportAttempted = 'Wallet Import Attempted', OnboardingWalletVideoPlay = 'SRP Intro Video Played', OnboardingTwitterClick = 'External Link Clicked', @@ -621,7 +621,7 @@ export enum MetaMetricsEventName { SrpCopiedToClipboard = 'Copies SRP to clipboard', SrpToConfirmBackup = 'SRP Backup Confirm Displayed', StakingEntryPointClicked = 'Stake Button Clicked', - StartEnablingNotificationsFlow = 'Start Enabling Notifications Flow', + StartEnablingNotificationsFlow = 'Notifications Enabling Flow Started', SupportLinkClicked = 'Support Link Clicked', TermsOfUseShown = 'Terms of Use Shown', TermsOfUseAccepted = 'Terms of Use Accepted', From 998e137e2f3ac0a43b078305e2d234ba11d5ba76 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Fri, 28 Jun 2024 16:54:41 +0200 Subject: [PATCH 2/7] refactor: :recycle: remove unused events and update event names --- shared/constants/metametrics.ts | 12 ++++------- .../multichain/global-menu/global-menu.js | 8 -------- .../creation-successful.js | 20 ++++++++----------- .../privacy-settings/privacy-settings.js | 14 ------------- 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/shared/constants/metametrics.ts b/shared/constants/metametrics.ts index b74162362838..f11a6fd4a394 100644 --- a/shared/constants/metametrics.ts +++ b/shared/constants/metametrics.ts @@ -560,7 +560,6 @@ export enum MetaMetricsEventName { NavSendButtonClicked = 'Send Button Clicked', NavSwapButtonClicked = 'Swap Button Clicked', NftAdded = 'NFT Added', - NotificationPageOpened = 'Notification Page Opened', NotificationItemClicked = 'Notification Item Clicked', NotificationDetailClicked = 'Notification Detail Clicked', OnboardingWalletCreationStarted = 'Wallet Setup Selected', @@ -574,11 +573,8 @@ export enum MetaMetricsEventName { OnboardingWalletSecurityPhraseWrittenDown = 'SRP Backup Confirm Display', OnboardingWalletSecurityPhraseConfirmed = 'SRP Backup Confirmed', OnboardingWalletCreationComplete = 'Wallet Created', - OnboardingWalletCreationCompleteWithAuthenticating = 'Wallet with Authentication Created', OnboardingWalletSetupComplete = 'Application Opened', OnboardingWalletAdvancedSettings = 'Settings Updated', - OnboardingWalletAdvancedSettingsWithAuthenticating = 'Settings Updated with Authenticating', - OnboardingWalletAdvancedSettingsWithoutAuthenticating = 'Settings Updated without Authenticating', OnboardingWalletAdvancedSettingsTurnOffProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned Off', OnboardingWalletAdvancedSettingsTurnOnProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned On', OnboardingWalletImportAttempted = 'Wallet Import Attempted', @@ -715,10 +711,10 @@ export enum MetaMetricsEventName { TokenAutoDetectionEnableModal = 'Token Autodetection Enabled from modal', TokenAutoDetectionDisableModal = 'Token Autodetection Disabled from modal', ///: END:ONLY_INCLUDE_IF - TurnOffProfileSyncing = 'Turn Off Profile Syncing', - TurnOnProfileSyncing = 'Turn On Profile Syncing', - TurnOnMetaMetrics = 'Turn On MetaMetrics', - TurnOffMetaMetrics = 'Turn Off MetaMetrics', + TurnOffProfileSyncing = 'Profile Sync Turned Off', + TurnOnProfileSyncing = 'Profile Sync Turned On', + TurnOnMetaMetrics = 'MetaMetrics Turned On', + TurnOffMetaMetrics = 'MetaMetrics Turned Off', // Notifications PushNotificationReceived = 'Push Notification Received', PushNotificationClicked = 'Push Notification Clicked', diff --git a/ui/components/multichain/global-menu/global-menu.js b/ui/components/multichain/global-menu/global-menu.js index 7a60390f7a98..6595938d3089 100644 --- a/ui/components/multichain/global-menu/global-menu.js +++ b/ui/components/multichain/global-menu/global-menu.js @@ -165,14 +165,6 @@ export const GlobalMenu = ({ closeMenu, anchorElement, isOpen }) => { } // Otherwise we can navigate to the notifications page - trackEvent({ - category: MetaMetricsEventCategory.NotificationInteraction, - event: MetaMetricsEventName.NotificationPageOpened, - properties: { - isProfileSyncingEnabled, - isMetamaskNotificationsEnabled, - }, - }); history.push(NOTIFICATIONS_ROUTE); closeMenu(); }; diff --git a/ui/pages/onboarding-flow/creation-successful/creation-successful.js b/ui/pages/onboarding-flow/creation-successful/creation-successful.js index c645b93078dc..46d9f7a55e1e 100644 --- a/ui/pages/onboarding-flow/creation-successful/creation-successful.js +++ b/ui/pages/onboarding-flow/creation-successful/creation-successful.js @@ -25,7 +25,10 @@ import { import { MetaMetricsContext } from '../../../contexts/metametrics'; import { useCreateSession } from '../../../hooks/metamask-notifications/useCreateSession'; import { selectIsProfileSyncingEnabled } from '../../../selectors/metamask-notifications/profile-syncing'; -import { selectParticipateInMetaMetrics } from '../../../selectors/metamask-notifications/authentication'; +import { + selectParticipateInMetaMetrics, + selectIsSignedIn, +} from '../../../selectors/metamask-notifications/authentication'; export default function CreationSuccessful() { const history = useHistory(); @@ -37,6 +40,7 @@ export default function CreationSuccessful() { const isProfileSyncingEnabled = useSelector(selectIsProfileSyncingEnabled); const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics); + const isSignedIn = useSelector(selectIsSignedIn); return (
@@ -116,19 +120,11 @@ export default function CreationSuccessful() { event: MetaMetricsEventName.OnboardingWalletCreationComplete, properties: { method: firstTimeFlowType, + isSignedIn, + isProfileSyncingEnabled, + participateInMetaMetrics, }, }); - if (isProfileSyncingEnabled || participateInMetaMetrics) { - trackEvent({ - category: MetaMetricsEventCategory.Onboarding, - event: - MetaMetricsEventName.OnboardingWalletCreationCompleteWithAuthenticating, - properties: { - isProfileSyncingEnabled, - partedInMetaMetrics: participateInMetaMetrics, - }, - }); - } createSession(); history.push(ONBOARDING_PIN_EXTENSION_ROUTE); }} diff --git a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js index ea15950451c5..9e9e27052888 100644 --- a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js +++ b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js @@ -216,20 +216,6 @@ export default function PrivacySettings() { }, }); - const eventName = - profileSyncingProps.isProfileSyncingEnabled || participateInMetaMetrics - ? MetaMetricsEventName.OnboardingWalletAdvancedSettingsWithAuthenticating - : MetaMetricsEventName.OnboardingWalletAdvancedSettingsWithoutAuthenticating; - - trackEvent({ - category: MetaMetricsEventCategory.Onboarding, - event: eventName, - properties: { - isProfileSyncingEnabled: profileSyncingProps.isProfileSyncingEnabled, - participateInMetaMetrics, - }, - }); - history.push(ONBOARDING_PIN_EXTENSION_ROUTE); }; From 7da98de60470ea47f66db1cd9e52a7ed9aaa1e64 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Fri, 28 Jun 2024 16:55:21 +0200 Subject: [PATCH 3/7] refactor: :recycle: remove unused events --- shared/constants/metametrics.ts | 2 -- .../onboarding-flow/privacy-settings/privacy-settings.js | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/shared/constants/metametrics.ts b/shared/constants/metametrics.ts index f11a6fd4a394..2b3ad9a6d6b6 100644 --- a/shared/constants/metametrics.ts +++ b/shared/constants/metametrics.ts @@ -575,8 +575,6 @@ export enum MetaMetricsEventName { OnboardingWalletCreationComplete = 'Wallet Created', OnboardingWalletSetupComplete = 'Application Opened', OnboardingWalletAdvancedSettings = 'Settings Updated', - OnboardingWalletAdvancedSettingsTurnOffProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned Off', - OnboardingWalletAdvancedSettingsTurnOnProfileSyncing = 'Wallet Advanced Settings Profile Syncing Turned On', OnboardingWalletImportAttempted = 'Wallet Import Attempted', OnboardingWalletVideoPlay = 'SRP Intro Video Played', OnboardingTwitterClick = 'External Link Clicked', diff --git a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js index 9e9e27052888..51b6142800f3 100644 --- a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js +++ b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js @@ -228,8 +228,7 @@ export default function PrivacySettings() { profileSyncingProps.setIsProfileSyncingEnabled(false); trackEvent({ category: MetaMetricsEventCategory.Onboarding, - event: - MetaMetricsEventName.OnboardingWalletAdvancedSettingsTurnOffProfileSyncing, + event: MetaMetricsEventName.TurnOffProfileSyncing, properties: { participateInMetaMetrics, }, @@ -241,8 +240,7 @@ export default function PrivacySettings() { profileSyncingProps.setIsProfileSyncingEnabled(true); trackEvent({ category: MetaMetricsEventCategory.Onboarding, - event: - MetaMetricsEventName.OnboardingWalletAdvancedSettingsTurnOnProfileSyncing, + event: MetaMetricsEventName.TurnOnProfileSyncing, properties: { participateInMetaMetrics, }, From 74691b4358d421b7b90baa58a62e640b57b6834a Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Tue, 23 Jul 2024 18:59:47 +0200 Subject: [PATCH 4/7] fix: :bug: update notifications events schema --- app/scripts/metamask-controller.js | 5 ++++- shared/constants/metametrics.ts | 15 ++++----------- .../turn-on-metamask-notifications.tsx | 12 ++++++++---- .../multichain/global-menu/global-menu.js | 7 ++++--- .../notification-detail-button.tsx | 12 +++++++++--- ...notifications-settings-allow-notifications.tsx | 15 ++++++++++++--- .../notifications-settings-per-account.tsx | 7 ++++--- .../notifications-settings-types.tsx | 11 +++++++---- .../notifications/notifications-list-item.tsx | 13 +++++++++---- .../creation-successful/creation-successful.js | 11 +++-------- .../privacy-settings/privacy-settings.js | 10 ++++++---- .../profile-sync-toggle/profile-sync-toggle.tsx | 13 ++++++------- 12 files changed, 76 insertions(+), 55 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 44dc9a67fbeb..b6def5b68f1d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1471,11 +1471,14 @@ export default class MetamaskController extends EventEmitter { 'PushPlatformNotificationsController:pushNotificationClicked', (notification) => { this.metaMetricsController.trackEvent({ - event: MetaMetricsEventName.PushNotificationClicked, category: MetaMetricsEventCategory.PushNotifications, + event: MetaMetricsEventName.NotificationClicked, properties: { + notification_id: notification.id, notification_type: notification.type, chain_id: notification?.chain_id, + notification_is_read: notification.isRead, + click_type: 'push_notification', }, }); }, diff --git a/shared/constants/metametrics.ts b/shared/constants/metametrics.ts index dbc217bfec41..b7e740fc4527 100644 --- a/shared/constants/metametrics.ts +++ b/shared/constants/metametrics.ts @@ -518,10 +518,7 @@ export enum MetaMetricsEventName { DecryptionApproved = 'Decryption Approved', DecryptionRejected = 'Decryption Rejected', DecryptionRequested = 'Decryption Requested', - DisablingAccountNotifications = 'Account Notifications Disabled', - EnablingAccountNotifications = 'Account Notifications Enabled', DisablingNotifications = 'Notifications Disabled', - DismissEnablingNotificationsFlow = 'Notifications Enabling Flow Dismissed', EmptyBuyBannerDisplayed = 'Empty Buy Banner Displayed', EmptyBuyBannerClicked = 'Empty Buy Banner Clicked', EmptyReceiveBannerDisplayed = 'Empty Receive Banner Displayed', @@ -533,8 +530,6 @@ export enum MetaMetricsEventName { EncryptionPublicKeyRejected = 'Encryption Rejected', EncryptionPublicKeyRequested = 'Encryption Requested', ExternalLinkClicked = 'External Link Clicked', - FeatureAnnouncementEnabled = 'Feature Announcement Enabled', - FeatureAnnouncementDisabled = 'Feature Announcement Disabled', KeyExportSelected = 'Key Export Selected', KeyExportRequested = 'Key Export Requested', KeyExportFailed = 'Key Export Failed', @@ -562,8 +557,6 @@ export enum MetaMetricsEventName { NavSendButtonClicked = 'Send Button Clicked', NavSwapButtonClicked = 'Swap Button Clicked', NftAdded = 'NFT Added', - NotificationItemClicked = 'Notification Item Clicked', - NotificationDetailClicked = 'Notification Detail Clicked', OnboardingWalletCreationStarted = 'Wallet Setup Selected', OnboardingWalletImportStarted = 'Wallet Import Started', OnboardingWalletCreationAttempted = 'Wallet Password Created', @@ -617,7 +610,6 @@ export enum MetaMetricsEventName { SrpCopiedToClipboard = 'Copies SRP to clipboard', SrpToConfirmBackup = 'SRP Backup Confirm Displayed', StakingEntryPointClicked = 'Stake Button Clicked', - StartEnablingNotificationsFlow = 'Notifications Enabling Flow Started', SupportLinkClicked = 'Support Link Clicked', TermsOfUseShown = 'Terms of Use Shown', TermsOfUseAccepted = 'Terms of Use Accepted', @@ -709,13 +701,14 @@ export enum MetaMetricsEventName { TokenAutoDetectionEnableModal = 'Token Autodetection Enabled from modal', TokenAutoDetectionDisableModal = 'Token Autodetection Disabled from modal', ///: END:ONLY_INCLUDE_IF - TurnOffProfileSyncing = 'Profile Sync Turned Off', - TurnOnProfileSyncing = 'Profile Sync Turned On', + ProfileSyncSettingsToggled = 'Profile Sync Settings Toggled', TurnOnMetaMetrics = 'MetaMetrics Turned On', TurnOffMetaMetrics = 'MetaMetrics Turned Off', // Notifications PushNotificationReceived = 'Push Notification Received', - PushNotificationClicked = 'Push Notification Clicked', + NotificationsSettingsUpdated = 'Notifications Settings Updated', + NotificationClicked = 'Notification Clicked', + NotificationsEnablingFlowHandled = 'Notifications Enabling Flow Handled', NftAutoDetectionEnableModal = 'Nft Autodetection Enabled from modal', NftAutoDetectionDisableModal = 'Nft Autodetection Disabled from modal', diff --git a/ui/components/app/modals/turn-on-metamask-notifications/turn-on-metamask-notifications.tsx b/ui/components/app/modals/turn-on-metamask-notifications/turn-on-metamask-notifications.tsx index 2cb2437cc665..46510d0584fb 100644 --- a/ui/components/app/modals/turn-on-metamask-notifications/turn-on-metamask-notifications.tsx +++ b/ui/components/app/modals/turn-on-metamask-notifications/turn-on-metamask-notifications.tsx @@ -62,9 +62,11 @@ export default function TurnOnMetamaskNotifications() { await createNotifications(); trackEvent({ category: MetaMetricsEventCategory.EnableNotifications, - event: MetaMetricsEventName.EnablingNotifications, + event: MetaMetricsEventName.NotificationsEnablingFlowHandled, properties: { - isProfileSyncingEnabled, + is_profile_syncing_enabled: isProfileSyncingEnabled, + is_notifications_enabled: isNotificationEnabled, + action_type: 'enabled', }, }); }; @@ -73,9 +75,11 @@ export default function TurnOnMetamaskNotifications() { hideModal(); trackEvent({ category: MetaMetricsEventCategory.EnableNotifications, - event: MetaMetricsEventName.DismissEnablingNotificationsFlow, + event: MetaMetricsEventName.NotificationsEnablingFlowHandled, properties: { - isProfileSyncingEnabled, + is_profile_syncing_enabled: isProfileSyncingEnabled, + is_notifications_enabled: isNotificationEnabled, + action_type: 'dismissed', }, }); }; diff --git a/ui/components/multichain/global-menu/global-menu.js b/ui/components/multichain/global-menu/global-menu.js index 9ed8ad8a3a9a..b8a251dd373a 100644 --- a/ui/components/multichain/global-menu/global-menu.js +++ b/ui/components/multichain/global-menu/global-menu.js @@ -145,10 +145,11 @@ export const GlobalMenu = ({ closeMenu, anchorElement, isOpen }) => { if (shouldShowEnableModal) { trackEvent({ category: MetaMetricsEventCategory.EnableNotifications, - event: MetaMetricsEventName.StartEnablingNotificationsFlow, + event: MetaMetricsEventName.NotificationsEnablingFlowHandled, properties: { - isProfileSyncingEnabled, - isMetamaskNotificationsEnabled, + is_profile_syncing_enabled: isProfileSyncingEnabled, + is_notifications_enabled: isMetamaskNotificationsEnabled, + action_type: 'started', }, }); dispatch(showConfirmTurnOnMetamaskNotifications()); diff --git a/ui/components/multichain/notification-detail-button/notification-detail-button.tsx b/ui/components/multichain/notification-detail-button/notification-detail-button.tsx index 190b5cc4fa51..ea8f1d0559ec 100644 --- a/ui/components/multichain/notification-detail-button/notification-detail-button.tsx +++ b/ui/components/multichain/notification-detail-button/notification-detail-button.tsx @@ -5,6 +5,7 @@ import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; +import { TRIGGER_TYPES } from '../../../../app/scripts/controllers/metamask-notifications/constants/notification-schema'; import { Button, ButtonVariant, @@ -37,10 +38,15 @@ export const NotificationDetailButton = ({ const onClick = () => { trackEvent({ category: MetaMetricsEventCategory.NotificationInteraction, - event: MetaMetricsEventName.NotificationDetailClicked, + event: MetaMetricsEventName.NotificationClicked, properties: { - notificationId: notification.id, - notificationType: notification.type, + notification_id: notification.id, + notification_type: notification.type, + ...(notification.type !== TRIGGER_TYPES.FEATURES_ANNOUNCEMENT && { + chain_id: notification?.chain_id, + }), + notification_is_read: notification.isRead, + click_type: 'detail', }, }); }; diff --git a/ui/pages/notifications-settings/notifications-settings-allow-notifications.tsx b/ui/pages/notifications-settings/notifications-settings-allow-notifications.tsx index 4214eccc656b..ffe7c6e99d33 100644 --- a/ui/pages/notifications-settings/notifications-settings-allow-notifications.tsx +++ b/ui/pages/notifications-settings/notifications-settings-allow-notifications.tsx @@ -85,15 +85,24 @@ export function NotificationsSettingsAllowNotifications({ await disableNotifications(); trackEvent({ category: MetaMetricsEventCategory.NotificationSettings, - event: MetaMetricsEventName.DisablingNotifications, + event: MetaMetricsEventName.NotificationsSettingsUpdated, + properties: { + setting_type: 'notifications', + is_profile_syncing_enabled: isProfileSyncingEnabled, + old_value: true, + new_value: false, + }, }); } else { await enableNotifications(); trackEvent({ category: MetaMetricsEventCategory.NotificationSettings, - event: MetaMetricsEventName.EnablingNotifications, + event: MetaMetricsEventName.NotificationsSettingsUpdated, properties: { - isProfileSyncingEnabled, + setting_type: 'notifications', + is_profile_syncing_enabled: isProfileSyncingEnabled, + old_value: false, + new_value: true, }, }); } diff --git a/ui/pages/notifications-settings/notifications-settings-per-account.tsx b/ui/pages/notifications-settings/notifications-settings-per-account.tsx index 6ebfcdad5f0f..f4a4d67858cf 100644 --- a/ui/pages/notifications-settings/notifications-settings-per-account.tsx +++ b/ui/pages/notifications-settings/notifications-settings-per-account.tsx @@ -72,10 +72,11 @@ export const NotificationsSettingsPerAccount = ({ const handleToggleAccountNotifications = useCallback(async () => { trackEvent({ category: MetaMetricsEventCategory.NotificationSettings, - event: isEnabled - ? MetaMetricsEventName.DisablingAccountNotifications - : MetaMetricsEventName.EnablingAccountNotifications, + event: MetaMetricsEventName.NotificationsSettingsUpdated, properties: { + setting_type: 'account_notifications', + old_value: isEnabled, + new_value: !isEnabled, address, }, }); diff --git a/ui/pages/notifications-settings/notifications-settings-types.tsx b/ui/pages/notifications-settings/notifications-settings-types.tsx index 8225bd14ec24..b00390e1cc46 100644 --- a/ui/pages/notifications-settings/notifications-settings-types.tsx +++ b/ui/pages/notifications-settings/notifications-settings-types.tsx @@ -55,10 +55,13 @@ export function NotificationsSettingsTypes({ try { onChangeFeatureAnnouncements(!featureAnnouncementsEnabled); trackEvent({ - category: MetaMetricsEventCategory.NotificationInteraction, - event: featureAnnouncementsEnabled - ? MetaMetricsEventName.FeatureAnnouncementDisabled - : MetaMetricsEventName.FeatureAnnouncementEnabled, + category: MetaMetricsEventCategory.NotificationSettings, + event: MetaMetricsEventName.NotificationsSettingsUpdated, + properties: { + setting_type: 'feature_announcements', + old_value: featureAnnouncementsEnabled, + new_value: !featureAnnouncementsEnabled, + }, }); listNotifications(); } catch (error) { diff --git a/ui/pages/notifications/notifications-list-item.tsx b/ui/pages/notifications/notifications-list-item.tsx index fd8e628d9869..b3ffba845ebf 100644 --- a/ui/pages/notifications/notifications-list-item.tsx +++ b/ui/pages/notifications/notifications-list-item.tsx @@ -14,6 +14,7 @@ import { } from '../../helpers/constants/design-system'; import { NOTIFICATIONS_ROUTE } from '../../helpers/constants/routes'; import { useMarkNotificationAsRead } from '../../hooks/metamask-notifications/useNotifications'; +import { TRIGGER_TYPES } from '../../../app/scripts/controllers/metamask-notifications/constants/notification-schema'; import { NotificationComponents, hasNotificationComponents, @@ -32,11 +33,15 @@ export function NotificationsListItem({ const handleNotificationClick = useCallback(() => { trackEvent({ category: MetaMetricsEventCategory.NotificationInteraction, - event: MetaMetricsEventName.NotificationItemClicked, + event: MetaMetricsEventName.NotificationClicked, properties: { - notificationId: notification.id, - notificationType: notification.type, - notificationIsRead: notification.isRead, + notification_id: notification.id, + notification_type: notification.type, + notification_is_read: notification.isRead, + ...(notification.type !== TRIGGER_TYPES.FEATURES_ANNOUNCEMENT && { + chain_id: notification?.chain_id, + }), + click_type: 'item', }, }); markNotificationAsRead([ diff --git a/ui/pages/onboarding-flow/creation-successful/creation-successful.js b/ui/pages/onboarding-flow/creation-successful/creation-successful.js index 46d9f7a55e1e..515637e79ccd 100644 --- a/ui/pages/onboarding-flow/creation-successful/creation-successful.js +++ b/ui/pages/onboarding-flow/creation-successful/creation-successful.js @@ -25,10 +25,7 @@ import { import { MetaMetricsContext } from '../../../contexts/metametrics'; import { useCreateSession } from '../../../hooks/metamask-notifications/useCreateSession'; import { selectIsProfileSyncingEnabled } from '../../../selectors/metamask-notifications/profile-syncing'; -import { - selectParticipateInMetaMetrics, - selectIsSignedIn, -} from '../../../selectors/metamask-notifications/authentication'; +import { selectIsSignedIn } from '../../../selectors/metamask-notifications/authentication'; export default function CreationSuccessful() { const history = useHistory(); @@ -39,7 +36,6 @@ export default function CreationSuccessful() { const { createSession } = useCreateSession(); const isProfileSyncingEnabled = useSelector(selectIsProfileSyncingEnabled); - const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics); const isSignedIn = useSelector(selectIsSignedIn); return ( @@ -120,9 +116,8 @@ export default function CreationSuccessful() { event: MetaMetricsEventName.OnboardingWalletCreationComplete, properties: { method: firstTimeFlowType, - isSignedIn, - isProfileSyncingEnabled, - participateInMetaMetrics, + is_signed_in: isSignedIn, + is_profile_syncing_enabled: isProfileSyncingEnabled, }, }); createSession(); diff --git a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js index 51b6142800f3..20915d3ff78f 100644 --- a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js +++ b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js @@ -228,9 +228,10 @@ export default function PrivacySettings() { profileSyncingProps.setIsProfileSyncingEnabled(false); trackEvent({ category: MetaMetricsEventCategory.Onboarding, - event: MetaMetricsEventName.TurnOffProfileSyncing, + event: MetaMetricsEventName.ProfileSyncSettingsToggled, properties: { - participateInMetaMetrics, + old_value: profileSyncingProps.isProfileSyncingEnabled, + new_value: false, }, }); }, @@ -240,9 +241,10 @@ export default function PrivacySettings() { profileSyncingProps.setIsProfileSyncingEnabled(true); trackEvent({ category: MetaMetricsEventCategory.Onboarding, - event: MetaMetricsEventName.TurnOnProfileSyncing, + event: MetaMetricsEventName.ProfileSyncSettingsToggled, properties: { - participateInMetaMetrics, + old_value: profileSyncingProps.isProfileSyncingEnabled, + new_value: true, }, }); } diff --git a/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx b/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx index a0661635797d..4c7b4e7159c9 100644 --- a/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx +++ b/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx @@ -11,7 +11,6 @@ import { selectIsProfileSyncingEnabled, selectIsProfileSyncingUpdateLoading, } from '../../../../selectors/metamask-notifications/profile-syncing'; -import { selectParticipateInMetaMetrics } from '../../../../selectors/metamask-notifications/authentication'; import { showModal } from '../../../../store/actions'; import { MetaMetricsEventCategory, @@ -59,7 +58,6 @@ const ProfileSyncToggle = () => { const error = enableProfileSyncingError || disableProfileSyncingError; const isProfileSyncingEnabled = useSelector(selectIsProfileSyncingEnabled); - const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics); const isProfileSyncingUpdateLoading = useSelector( selectIsProfileSyncingUpdateLoading, ); @@ -73,9 +71,10 @@ const ProfileSyncToggle = () => { disableProfileSyncing(); trackEvent({ category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.TurnOffProfileSyncing, + event: MetaMetricsEventName.ProfileSyncSettingsToggled, properties: { - participateInMetaMetrics, + old_value: isProfileSyncingEnabled, + new_value: false, }, }); }, @@ -85,10 +84,10 @@ const ProfileSyncToggle = () => { await enableProfileSyncing(); trackEvent({ category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.TurnOnProfileSyncing, + event: MetaMetricsEventName.ProfileSyncSettingsToggled, properties: { - isProfileSyncingEnabled, - participateInMetaMetrics, + old_value: isProfileSyncingEnabled, + new_value: true, }, }); } From 2e43d763de7b5e3458263c8e5c914815f2581b0b Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Wed, 24 Jul 2024 10:24:30 +0200 Subject: [PATCH 5/7] fix: :bug: update events --- app/scripts/metamask-controller.js | 3 ++- shared/constants/metametrics.ts | 3 +-- .../notifications-settings-per-account.tsx | 1 - .../privacy-settings/privacy-settings.js | 16 ------------- .../profile-sync-toggle.tsx | 24 +------------------ 5 files changed, 4 insertions(+), 43 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5b0fa7aaf7aa..900c4fa00b04 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1458,9 +1458,10 @@ export default class MetamaskController extends EventEmitter { 'PushPlatformNotificationsController:onNewNotifications', (notification) => { this.metaMetricsController.trackEvent({ - event: MetaMetricsEventName.PushNotificationReceived, category: MetaMetricsEventCategory.PushNotifications, + event: MetaMetricsEventName.NotificationReceived, properties: { + notification_channel: 'push', notification_type: notification.type, chain_id: notification?.chain_id, }, diff --git a/shared/constants/metametrics.ts b/shared/constants/metametrics.ts index 0b7b4fd026ca..d72e450401e8 100644 --- a/shared/constants/metametrics.ts +++ b/shared/constants/metametrics.ts @@ -702,11 +702,10 @@ export enum MetaMetricsEventName { TokenAutoDetectionEnableModal = 'Token Autodetection Enabled from modal', TokenAutoDetectionDisableModal = 'Token Autodetection Disabled from modal', ///: END:ONLY_INCLUDE_IF - ProfileSyncSettingsToggled = 'Profile Sync Settings Toggled', TurnOnMetaMetrics = 'MetaMetrics Turned On', TurnOffMetaMetrics = 'MetaMetrics Turned Off', // Notifications - PushNotificationReceived = 'Push Notification Received', + NotificationReceived = 'Notification Received', NotificationsSettingsUpdated = 'Notifications Settings Updated', NotificationClicked = 'Notification Clicked', NotificationsEnablingFlowHandled = 'Notifications Enabling Flow Handled', diff --git a/ui/pages/notifications-settings/notifications-settings-per-account.tsx b/ui/pages/notifications-settings/notifications-settings-per-account.tsx index f4a4d67858cf..e73d6807feff 100644 --- a/ui/pages/notifications-settings/notifications-settings-per-account.tsx +++ b/ui/pages/notifications-settings/notifications-settings-per-account.tsx @@ -77,7 +77,6 @@ export const NotificationsSettingsPerAccount = ({ setting_type: 'account_notifications', old_value: isEnabled, new_value: !isEnabled, - address, }, }); await toggleAccount(!isEnabled); diff --git a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js index 20915d3ff78f..754ed1dd6dc0 100644 --- a/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js +++ b/ui/pages/onboarding-flow/privacy-settings/privacy-settings.js @@ -226,27 +226,11 @@ export default function PrivacySettings() { name: 'CONFIRM_TURN_OFF_PROFILE_SYNCING', turnOffProfileSyncing: () => { profileSyncingProps.setIsProfileSyncingEnabled(false); - trackEvent({ - category: MetaMetricsEventCategory.Onboarding, - event: MetaMetricsEventName.ProfileSyncSettingsToggled, - properties: { - old_value: profileSyncingProps.isProfileSyncingEnabled, - new_value: false, - }, - }); }, }), ); } else { profileSyncingProps.setIsProfileSyncingEnabled(true); - trackEvent({ - category: MetaMetricsEventCategory.Onboarding, - event: MetaMetricsEventName.ProfileSyncSettingsToggled, - properties: { - old_value: profileSyncingProps.isProfileSyncingEnabled, - new_value: true, - }, - }); } }; diff --git a/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx b/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx index 4c7b4e7159c9..7d1d8d66a48a 100644 --- a/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx +++ b/ui/pages/settings/security-tab/profile-sync-toggle/profile-sync-toggle.tsx @@ -1,7 +1,6 @@ -import React, { useContext, useEffect } from 'react'; +import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useI18nContext } from '../../../../hooks/useI18nContext'; -import { MetaMetricsContext } from '../../../../contexts/metametrics'; import { useEnableProfileSyncing, useDisableProfileSyncing, @@ -12,10 +11,6 @@ import { selectIsProfileSyncingUpdateLoading, } from '../../../../selectors/metamask-notifications/profile-syncing'; import { showModal } from '../../../../store/actions'; -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../../../shared/constants/metametrics'; import { Box, Text } from '../../../../components/component-library'; import ToggleButton from '../../../../components/ui/toggle-button'; import { @@ -46,7 +41,6 @@ function ProfileSyncBasicFunctionalitySetting() { const ProfileSyncToggle = () => { const t = useI18nContext(); - const trackEvent = useContext(MetaMetricsContext); const dispatch = useDispatch(); const { enableProfileSyncing, error: enableProfileSyncingError } = useEnableProfileSyncing(); @@ -69,27 +63,11 @@ const ProfileSyncToggle = () => { name: 'CONFIRM_TURN_OFF_PROFILE_SYNCING', turnOffProfileSyncing: () => { disableProfileSyncing(); - trackEvent({ - category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.ProfileSyncSettingsToggled, - properties: { - old_value: isProfileSyncingEnabled, - new_value: false, - }, - }); }, }), ); } else { await enableProfileSyncing(); - trackEvent({ - category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.ProfileSyncSettingsToggled, - properties: { - old_value: isProfileSyncingEnabled, - new_value: true, - }, - }); } }; From 601930bdf4bc199d874bcce7ccc74afdc127fa43 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Fri, 26 Jul 2024 07:26:35 +0200 Subject: [PATCH 6/7] fix: :bug: update snap events --- .../notification-components/snap/snap.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ui/pages/notifications/notification-components/snap/snap.tsx b/ui/pages/notifications/notification-components/snap/snap.tsx index bdd7b4576694..beb9151af10d 100644 --- a/ui/pages/notifications/notification-components/snap/snap.tsx +++ b/ui/pages/notifications/notification-components/snap/snap.tsx @@ -29,11 +29,12 @@ export const SnapComponent = ({ snapNotification }: SnapComponentProps) => { dispatch(markNotificationsAsRead([snapNotification.id])); trackEvent({ category: MetaMetricsEventCategory.NotificationInteraction, - event: MetaMetricsEventName.NotificationDetailClicked, + event: MetaMetricsEventName.NotificationClicked, properties: { - notificationId: snapNotification.id, - notificationType: snapNotification.type, - notificationIsRead: snapNotification.isRead, + notification_id: snapNotification.id, + notification_type: snapNotification.type, + notification_is_read: snapNotification.isRead, + click_type: 'item', }, }); }; @@ -42,11 +43,12 @@ export const SnapComponent = ({ snapNotification }: SnapComponentProps) => { dispatch(markNotificationsAsRead([snapNotification.id])); trackEvent({ category: MetaMetricsEventCategory.NotificationInteraction, - event: MetaMetricsEventName.NotificationItemClicked, + event: MetaMetricsEventName.NotificationClicked, properties: { - notificationId: snapNotification.id, - notificationType: snapNotification.type, - notificationIsRead: snapNotification.isRead, + notification_id: snapNotification.id, + notification_type: snapNotification.type, + notification_is_read: snapNotification.isRead, + click_type: 'item', }, }); history.push(getSnapRoute(snapNotification.data.origin)); From d7c77cddb277ec143c4de98ea829f2aadb6611c1 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Fri, 26 Jul 2024 10:55:38 +0100 Subject: [PATCH 7/7] test: update e2e tests add the missing segment events for onboarding snapshots --- test/e2e/tests/metrics/nft-detection-metrics.spec.js | 2 ++ test/e2e/tests/metrics/token-detection-metrics.spec.js | 2 ++ test/e2e/tests/metrics/wallet-created.spec.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/test/e2e/tests/metrics/nft-detection-metrics.spec.js b/test/e2e/tests/metrics/nft-detection-metrics.spec.js index dfd22ff0a79f..5b635a725e20 100644 --- a/test/e2e/tests/metrics/nft-detection-metrics.spec.js +++ b/test/e2e/tests/metrics/nft-detection-metrics.spec.js @@ -101,6 +101,8 @@ describe('Nft detection event @no-mmi', function () { locale: 'en', chain_id: '0x539', environment_type: 'fullscreen', + is_profile_syncing_enabled: null, + is_signed_in: false, }); assert.deepStrictEqual(events[2].properties, { nft_autodetection_enabled: true, diff --git a/test/e2e/tests/metrics/token-detection-metrics.spec.js b/test/e2e/tests/metrics/token-detection-metrics.spec.js index 467a305effa7..5115343f5a39 100644 --- a/test/e2e/tests/metrics/token-detection-metrics.spec.js +++ b/test/e2e/tests/metrics/token-detection-metrics.spec.js @@ -98,6 +98,8 @@ describe('Token detection event @no-mmi', function () { locale: 'en', chain_id: '0x539', environment_type: 'fullscreen', + is_profile_syncing_enabled: null, + is_signed_in: false, }); assert.deepStrictEqual(events[2].properties, { token_detection_enabled: true, diff --git a/test/e2e/tests/metrics/wallet-created.spec.js b/test/e2e/tests/metrics/wallet-created.spec.js index cff720062818..bc07cfdeea75 100644 --- a/test/e2e/tests/metrics/wallet-created.spec.js +++ b/test/e2e/tests/metrics/wallet-created.spec.js @@ -87,6 +87,8 @@ describe('Wallet Created Events @no-mmi', function () { locale: 'en', chain_id: '0x539', environment_type: 'fullscreen', + is_profile_syncing_enabled: null, + is_signed_in: false, }); }, );