Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix event names used to track notifications #25521

Merged
merged 12 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
},
Expand Down
31 changes: 9 additions & 22 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,18 @@ 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',
DisablingNotifications = 'Notifications Disabled',
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',
ExternalLinkClicked = 'External Link Clicked',
FeatureAnnouncementEnabled = 'Feature Announcement Enabled',
FeatureAnnouncementDisabled = 'Feature Announcement Disabled',
KeyExportSelected = 'Key Export Selected',
KeyExportRequested = 'Key Export Requested',
KeyExportFailed = 'Key Export Failed',
Expand All @@ -547,7 +542,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',
Expand All @@ -562,9 +557,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',
OnboardingWalletImportStarted = 'Wallet Import Started',
OnboardingWalletCreationAttempted = 'Wallet Password Created',
Expand All @@ -576,13 +568,8 @@ export enum MetaMetricsEventName {
OnboardingWalletSecurityPhraseWrittenDown = 'SRP Backup Confirm Display',
OnboardingWalletSecurityPhraseConfirmed = 'SRP Backup Confirmed',
OnboardingWalletCreationComplete = 'Wallet Created',
OnboardingWalletCreationCompleteWithAuthenticating = 'Wallet Created with Authenticating',
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',
OnboardingWalletImportAttempted = 'Wallet Import Attempted',
OnboardingWalletVideoPlay = 'SRP Intro Video Played',
OnboardingTwitterClick = 'External Link Clicked',
Expand Down Expand Up @@ -623,7 +610,6 @@ export enum MetaMetricsEventName {
SrpCopiedToClipboard = 'Copies SRP to clipboard',
SrpToConfirmBackup = 'SRP Backup Confirm Displayed',
StakingEntryPointClicked = 'Stake Button Clicked',
StartEnablingNotificationsFlow = 'Start Enabling Notifications Flow',
SupportLinkClicked = 'Support Link Clicked',
TermsOfUseShown = 'Terms of Use Shown',
TermsOfUseAccepted = 'Terms of Use Accepted',
Expand Down Expand Up @@ -715,13 +701,14 @@ 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',
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
};
Expand All @@ -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',
},
});
};
Expand Down
15 changes: 4 additions & 11 deletions ui/components/multichain/global-menu/global-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -157,14 +158,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();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions ui/pages/notifications/notifications-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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 } from '../../../selectors/metamask-notifications/authentication';
import { selectIsSignedIn } from '../../../selectors/metamask-notifications/authentication';

export default function CreationSuccessful() {
const history = useHistory();
Expand All @@ -36,7 +36,7 @@ export default function CreationSuccessful() {
const { createSession } = useCreateSession();

const isProfileSyncingEnabled = useSelector(selectIsProfileSyncingEnabled);
const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics);
const isSignedIn = useSelector(selectIsSignedIn);

return (
<div className="creation-successful" data-testid="creation-successful">
Expand Down Expand Up @@ -116,19 +116,10 @@ export default function CreationSuccessful() {
event: MetaMetricsEventName.OnboardingWalletCreationComplete,
properties: {
method: firstTimeFlowType,
is_signed_in: isSignedIn,
is_profile_syncing_enabled: isProfileSyncingEnabled,
},
});
if (isProfileSyncingEnabled || participateInMetaMetrics) {
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event:
MetaMetricsEventName.OnboardingWalletCreationCompleteWithAuthenticating,
properties: {
isProfileSyncingEnabled,
partedInMetaMetrics: participateInMetaMetrics,
},
});
}
createSession();
history.push(ONBOARDING_PIN_EXTENSION_ROUTE);
}}
Expand Down
26 changes: 6 additions & 20 deletions ui/pages/onboarding-flow/privacy-settings/privacy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -242,10 +228,10 @@ export default function PrivacySettings() {
profileSyncingProps.setIsProfileSyncingEnabled(false);
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event:
MetaMetricsEventName.OnboardingWalletAdvancedSettingsTurnOffProfileSyncing,
event: MetaMetricsEventName.ProfileSyncSettingsToggled,
properties: {
participateInMetaMetrics,
old_value: profileSyncingProps.isProfileSyncingEnabled,
new_value: false,
},
});
},
Expand All @@ -255,10 +241,10 @@ export default function PrivacySettings() {
profileSyncingProps.setIsProfileSyncingEnabled(true);
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event:
MetaMetricsEventName.OnboardingWalletAdvancedSettingsTurnOnProfileSyncing,
event: MetaMetricsEventName.ProfileSyncSettingsToggled,
properties: {
participateInMetaMetrics,
old_value: profileSyncingProps.isProfileSyncingEnabled,
new_value: true,
},
});
}
Expand Down
Loading