Skip to content

Commit

Permalink
fix: notifications use better events (#26410)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This PR updates and introduces some events necessary for the
notifications team to track user interaction with notifications.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26410?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

## **Screenshots/Recordings**

### **Before**

### **After**

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
matteoscurati authored Aug 14, 2024
1 parent 0a03bd8 commit 92eb990
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
3 changes: 1 addition & 2 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export enum MetaMetricsEventName {
NotificationReceived = 'Notification Received',
NotificationsSettingsUpdated = 'Notifications Settings Updated',
NotificationClicked = 'Notification Clicked',
NotificationsEnablingFlowHandled = 'Notifications Enabling Flow Handled',
NotificationMenuOpened = 'Notification Menu Opened',

NftAutoDetectionEnableModal = 'Nft Autodetection Enabled from modal',
NftAutoDetectionDisableModal = 'Nft Autodetection Disabled from modal',
Expand Down Expand Up @@ -756,7 +756,6 @@ export enum MetaMetricsEventCategory {
Messages = 'Messages',
Navigation = 'Navigation',
Network = 'Network',
EnableNotifications = 'Enable Notifications',
Onboarding = 'Onboarding',
NotificationInteraction = 'Notification Interaction',
NotificationSettings = 'Notification Settings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default function TurnOnMetamaskNotifications() {
setButtonState(true);
await createNotifications();
trackEvent({
category: MetaMetricsEventCategory.EnableNotifications,
event: MetaMetricsEventName.NotificationsEnablingFlowHandled,
category: MetaMetricsEventCategory.NotificationInteraction,
event: MetaMetricsEventName.NotificationMenuOpened,
properties: {
is_profile_syncing_enabled: isProfileSyncingEnabled,
is_notifications_enabled: isNotificationEnabled,
Expand All @@ -74,8 +74,8 @@ export default function TurnOnMetamaskNotifications() {
const handleHideModal = () => {
hideModal();
trackEvent({
category: MetaMetricsEventCategory.EnableNotifications,
event: MetaMetricsEventName.NotificationsEnablingFlowHandled,
category: MetaMetricsEventCategory.NotificationInteraction,
event: MetaMetricsEventName.NotificationMenuOpened,
properties: {
is_profile_syncing_enabled: isProfileSyncingEnabled,
is_notifications_enabled: isNotificationEnabled,
Expand Down
13 changes: 11 additions & 2 deletions ui/components/multichain/global-menu/global-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,24 @@ export const GlobalMenu = ({ closeMenu, anchorElement, isOpen }) => {

if (shouldShowEnableModal) {
trackEvent({
category: MetaMetricsEventCategory.EnableNotifications,
event: MetaMetricsEventName.NotificationsEnablingFlowHandled,
category: MetaMetricsEventCategory.NotificationInteraction,
event: MetaMetricsEventName.NotificationMenuOpened,
properties: {
is_profile_syncing_enabled: isProfileSyncingEnabled,
is_notifications_enabled: isMetamaskNotificationsEnabled,
action_type: 'started',
},
});
trackEvent({
category: MetaMetricsEventCategory.NotificationInteraction,
event: MetaMetricsEventName.NotificationMenuOpened,
properties: {
is_profile_syncing_enabled: isProfileSyncingEnabled,
is_notifications_enabled: isMetamaskNotificationsEnabled,
},
});
dispatch(showConfirmTurnOnMetamaskNotifications());

closeMenu();
return;
}
Expand Down
22 changes: 22 additions & 0 deletions ui/pages/onboarding-flow/privacy-settings/privacy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ export default function PrivacySettings() {
category: MetaMetricsEventCategory.Onboarding,
event: MetaMetricsEventName.OnboardingWalletAdvancedSettings,
properties: {
is_profile_syncing_enabled: profileSyncingProps.isProfileSyncingEnabled,
show_incoming_tx: incomingTransactionsPreferences,
use_phising_detection: usePhishingDetection,
turnon_token_detection: turnOnTokenDetection,
settings_group: 'advanced',
},
});

Expand All @@ -226,11 +228,31 @@ export default function PrivacySettings() {
name: 'CONFIRM_TURN_OFF_PROFILE_SYNCING',
turnOffProfileSyncing: () => {
profileSyncingProps.setIsProfileSyncingEnabled(false);
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event: MetaMetricsEventName.OnboardingWalletAdvancedSettings,
properties: {
settings_group: 'advanced',
settings_type: 'profile_syncing',
old_value: true,
new_value: false,
},
});
},
}),
);
} else {
profileSyncingProps.setIsProfileSyncingEnabled(true);
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event: MetaMetricsEventName.OnboardingWalletAdvancedSettings,
properties: {
settings_group: 'advanced',
settings_type: 'profile_syncing',
old_value: false,
new_value: true,
},
});
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, { useEffect } from 'react';
import React, { useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { MetaMetricsContext } from '../../../../contexts/metametrics';
import {
useEnableProfileSyncing,
useDisableProfileSyncing,
useSetIsProfileSyncingEnabled,
} from '../../../../hooks/metamask-notifications/useProfileSyncing';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../../shared/constants/metametrics';
import {
selectIsProfileSyncingEnabled,
selectIsProfileSyncingUpdateLoading,
Expand Down Expand Up @@ -40,6 +45,7 @@ function ProfileSyncBasicFunctionalitySetting() {
}

const ProfileSyncToggle = () => {
const trackEvent = useContext(MetaMetricsContext);
const t = useI18nContext();
const dispatch = useDispatch();
const { enableProfileSyncing, error: enableProfileSyncingError } =
Expand All @@ -63,11 +69,31 @@ const ProfileSyncToggle = () => {
name: 'CONFIRM_TURN_OFF_PROFILE_SYNCING',
turnOffProfileSyncing: () => {
disableProfileSyncing();
trackEvent({
category: MetaMetricsEventCategory.Settings,
event: MetaMetricsEventName.SettingsUpdated,
properties: {
settings_group: 'security',
settings_type: 'profile_syncing',
old_value: true,
new_value: false,
},
});
},
}),
);
} else {
await enableProfileSyncing();
trackEvent({
category: MetaMetricsEventCategory.Settings,
event: MetaMetricsEventName.SettingsUpdated,
properties: {
settings_group: 'security',
settings_type: 'profile_syncing',
old_value: false,
new_value: true,
},
});
}
};

Expand Down

0 comments on commit 92eb990

Please sign in to comment.