Commit 934aff0
authored
refactor: update network switching metrics to include chain ID and custom network status (MetaMask#23613)
<!--
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 adds additional properties to the NETWORK_SWITCHED analytics
event to improve network switching tracking. The changes include:
1. Adding from_network and to_network as chain IDs (hex format) instead
of network names
2. Adding custom_network boolean flag to indicate if the target network
is a custom (non-popular) network
Removing the selectedNetworkName parameter from useSwitchNetworks hook
as it's no longer needed
These changes apply to network switching from:
- Network Selector modal
- Network Permissions Connected component (dApp permission flow)
- RPC method calls (wallet_switchEthereumChain)
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
3. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-213
## **Manual testing steps**
```gherkin
Feature: Network Switched Analytics Event
Scenario: user switches network from Network Selector
Given user is on any screen with network selector accessible
When user opens the network selector and switches to a different network
Then the NETWORK_SWITCHED event should contain chain_id, from_network, to_network, and custom_network properties
Scenario: user switches network via dApp permission
Given user is connected to a dApp with network permissions
When user switches network through the network permissions modal
Then the NETWORK_SWITCHED event should contain chain_id, from_network (hex), to_network (hex), and custom_network (boolean)
Scenario: dApp requests network switch via RPC
Given user is connected to a dApp
When the dApp calls wallet_switchEthereumChain
Then the NETWORK_SWITCHED event should include from_network, to_network, and custom_network properties
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Unifies NETWORK_SWITCHED analytics to report from/to chain IDs and a
custom_network flag across UI flows and RPC, with tests updated
accordingly.
>
> - **Analytics/metrics**
> - Standardize `MetaMetricsEvents.NETWORK_SWITCHED` properties across
network switching flows:
> - `from_network` and `to_network` now use chain IDs (hex) instead of
names.
> - Add `custom_network` boolean based on `POPULAR_NETWORK_CHAIN_IDS`.
> - Ensure `chain_id` reflects the target chain (decimal where
applicable).
> - Apply changes in:
> -
`app/components/Views/AccountPermissions/.../NetworkPermissionsConnected.tsx`
(remove `selectProviderConfig`; track using `evmChainId` →
`targetChainId`).
> - `app/components/Views/NetworkSelector/useSwitchNetworks.ts` (remove
`selectedNetworkName`; track with `selectedChainId` →
`chainId`/built-ins; add popularity check).
> - `app/core/RPCMethods/lib/ethereum-chain-utils.js` (include
`from_network`, `to_network`, `custom_network`).
> - **Tests**
> - Update `ethereum-chain-utils.test.ts` to assert new analytics fields
(`from_network`, `to_network`, `custom_network`).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
df07c0b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e47bcb5 commit 934aff0
4 files changed
Lines changed: 27 additions & 19 deletions
File tree
- app
- components/Views
- AccountPermissions/NetworkPermissionsConnected
- NetworkSelector
- core/RPCMethods/lib
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
| |||
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
| |||
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
| 142 | + | |
144 | 143 | | |
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
148 | | - | |
149 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
Lines changed: 11 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 111 | + | |
| 112 | + | |
118 | 113 | | |
119 | 114 | | |
120 | 115 | | |
| |||
154 | 149 | | |
155 | 150 | | |
156 | 151 | | |
157 | | - | |
158 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
159 | 155 | | |
160 | 156 | | |
161 | 157 | | |
162 | 158 | | |
163 | 159 | | |
164 | 160 | | |
165 | 161 | | |
166 | | - | |
| 162 | + | |
167 | 163 | | |
168 | 164 | | |
169 | 165 | | |
| |||
225 | 221 | | |
226 | 222 | | |
227 | 223 | | |
| 224 | + | |
228 | 225 | | |
229 | 226 | | |
230 | 227 | | |
231 | | - | |
232 | | - | |
233 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
234 | 232 | | |
235 | 233 | | |
236 | 234 | | |
| |||
241 | 239 | | |
242 | 240 | | |
243 | 241 | | |
244 | | - | |
245 | 242 | | |
246 | 243 | | |
247 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
278 | 279 | | |
279 | 280 | | |
280 | 281 | | |
| 282 | + | |
281 | 283 | | |
282 | 284 | | |
283 | 285 | | |
284 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
285 | 290 | | |
286 | 291 | | |
287 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| |||
0 commit comments