-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: add analytics tracking for account pin, hide, and list viewed events #37952
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ const mockState = { | |
| }, | ||
| }, | ||
| }, | ||
| pinnedAccountList: [], | ||
| hiddenAccountList: [], | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, { useMemo, useRef } from 'react'; | ||
| import React, { useContext, useMemo, useRef } from 'react'; | ||
| import { useHistory } from 'react-router-dom'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
| import { | ||
|
|
@@ -28,6 +28,15 @@ import { | |
| setAccountGroupHidden, | ||
| } from '../../../store/actions'; | ||
| import { getAccountTree } from '../../../selectors/multichain-accounts/account-tree'; | ||
| import { | ||
| getPinnedAccountsList, | ||
| getHiddenAccountsList, | ||
| } from '../../../selectors/selectors'; | ||
| import { MetaMetricsContext } from '../../../contexts/metametrics'; | ||
| import { | ||
| MetaMetricsEventCategory, | ||
| MetaMetricsEventName, | ||
| } from '../../../../shared/constants/metametrics'; | ||
| import { MultichainAccountMenuProps } from './multichain-account-menu.types'; | ||
|
|
||
| export const MultichainAccountMenu = ({ | ||
|
|
@@ -42,6 +51,9 @@ export const MultichainAccountMenu = ({ | |
| const dispatch = useDispatch(); | ||
| const popoverRef = useRef<HTMLDivElement>(null); | ||
| const accountTree = useSelector(getAccountTree); | ||
| const trackEvent = useContext(MetaMetricsContext); | ||
| const pinnedAccountsList = useSelector(getPinnedAccountsList); | ||
| const hiddenAccountsList = useSelector(getHiddenAccountsList); | ||
|
|
||
| // Get the account group metadata to check pinned/hidden state | ||
| const accountGroupMetadata = useMemo(() => { | ||
|
|
@@ -89,25 +101,63 @@ export const MultichainAccountMenu = ({ | |
| mouseEvent.stopPropagation(); | ||
| mouseEvent.preventDefault(); | ||
|
|
||
| const willBePinned = !isPinned; | ||
|
|
||
| // If account is hidden, unhide it first before pinning | ||
| if (isHidden) { | ||
| await dispatch(setAccountGroupHidden(accountGroupId, false)); | ||
| } | ||
|
|
||
| await dispatch(setAccountGroupPinned(accountGroupId, !isPinned)); | ||
| await dispatch(setAccountGroupPinned(accountGroupId, willBePinned)); | ||
|
|
||
| // Calculate the count after the action | ||
| const pinnedCountAfter = willBePinned | ||
| ? pinnedAccountsList.length + 1 | ||
| : pinnedAccountsList.length - 1; | ||
|
|
||
| // Track the event | ||
| trackEvent({ | ||
| event: MetaMetricsEventName.AccountPinned, | ||
| category: MetaMetricsEventCategory.Accounts, | ||
| properties: { | ||
| pinned: willBePinned, | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| pinned_count_after: pinnedCountAfter, | ||
| }, | ||
| }); | ||
|
|
||
| onToggle?.(); | ||
| }; | ||
|
|
||
| const handleAccountHideClick = async (mouseEvent: React.MouseEvent) => { | ||
| mouseEvent.stopPropagation(); | ||
| mouseEvent.preventDefault(); | ||
|
|
||
| const willBeHidden = !isHidden; | ||
|
|
||
| // If account is pinned, unpin it first before hiding | ||
| if (isPinned) { | ||
| await dispatch(setAccountGroupPinned(accountGroupId, false)); | ||
| } | ||
|
|
||
| await dispatch(setAccountGroupHidden(accountGroupId, !isHidden)); | ||
| await dispatch(setAccountGroupHidden(accountGroupId, willBeHidden)); | ||
|
|
||
| // Calculate the count after the action | ||
| const hiddenCountAfter = willBeHidden | ||
| ? hiddenAccountsList.length + 1 | ||
| : hiddenAccountsList.length - 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Hidden Count Mismatch for Account GroupsThe |
||
|
|
||
| // Track the event | ||
| trackEvent({ | ||
| event: MetaMetricsEventName.AccountHidden, | ||
| category: MetaMetricsEventCategory.Accounts, | ||
| properties: { | ||
| hidden: willBeHidden, | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| hidden_count_after: hiddenCountAfter, | ||
| }, | ||
| }); | ||
|
|
||
| onToggle?.(); | ||
| }; | ||
|
|
||
|
|
@@ -164,6 +214,9 @@ export const MultichainAccountMenu = ({ | |
| isHidden, | ||
| dispatch, | ||
| onToggle, | ||
| pinnedAccountsList, | ||
| hiddenAccountsList, | ||
| trackEvent, | ||
| ]); | ||
|
|
||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Account Group Pinning: Count Mismatch
The
pinnedCountAftercalculation assumes only one address is added or removed, but account groups can contain multiple addresses across different chains. When pinning or unpinning a group with N addresses, the count changes by N, not 1. The calculation uses stale list values captured at render time and doesn't account for the actual number of addresses in the account group being modified.