refactor: update RPC event tracking and analytics for network management
Description
This PR implements analytics tracking for RPC endpoint management by renaming the NETWORK_ADDED event to RPC_ADDED and adding a new RPC_DELETED event, both with the rpc_url_index property to track which RPC endpoint index is being added or removed.
Reason for change: Users can now add multiple RPC endpoints to a single network. We need to track which RPC endpoint index is being added or deleted to better understand user behavior and network configuration patterns.
Improvement/Solution:
- Renamed
NETWORK_ADDEDevent toRPC_ADDEDto better reflect that we're tracking RPC endpoint additions, not just network additions - Added new
RPC_DELETEDevent to track when RPC endpoints are removed - Added
rpc_url_indexproperty to both events:0indicates there is only 1 RPC URL for the network (first/only endpoint)- Higher values indicate additional RPC endpoints
- Standardized all
chain_idvalues to usetoHex()format for consistency across all RPC tracking events - Updated tracking in:
NetworkModal- when networks are added via UIwallet_addEthereumChain- when RPC endpoints are added via RPC methodNetworkSettings- when RPC endpoints are added/removed in network settings
Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-211
Manual testing steps
Feature: RPC endpoint analytics tracking
Scenario: user adds a network with first RPC endpoint
Given the user is on the network settings screen
When user adds a new network with an RPC URL
Then RPC_ADDED event should be tracked with rpc_url_index: 0 and chain_id in hex format
Scenario: user adds additional RPC endpoint to existing network
Given the user has a network with at least one RPC endpoint configured
When user adds an additional RPC endpoint to that network
Then RPC_ADDED event should be tracked with rpc_url_index matching the new endpoint's index and chain_id in hex format
Scenario: user removes an RPC endpoint from network
Given the user has a network with multiple RPC endpoints configured
When user deletes one of the RPC endpoints
Then RPC_DELETED event should be tracked with rpc_url_index matching the deleted endpoint's index and chain_id in hex format
Scenario: user adds network via wallet_addEthereumChain RPC method
Given a dapp calls wallet_addEthereumChain with a new network
When the network is successfully added
Then RPC_ADDED event should be tracked with rpc_url_index: 0 and chain_id in hex format
Scenario: user adds RPC endpoint to existing network via wallet_addEthereumChain
Given a network already exists in the wallet
When a dapp calls wallet_addEthereumChain with a different RPC URL for the same chainId
Then RPC_ADDED event should be tracked with rpc_url_index matching the new endpoint's index and chain_id in hex format
Screenshots/Recordings
Before
After
Pre-merge author checklist
- [x] I’ve followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
- [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 format if applicable
- [x] I’ve applied the right labels on the PR (see labeling guidelines). 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.
[!NOTE] Replaces NETWORK_ADDED with RPC_ADDED and adds RPC_REMOVED, standardizing chain_id to hex and capturing rpc_url_index across UI flows and wallet_addEthereumChain, with comprehensive tests.
- Analytics:
- Rename
NETWORK_ADDEDtoRPC_ADDED; addRPC_REMOVEDincore/Analytics/MetaMetrics.events.tsand exports.- Standardize
chain_idto hex viatoHex; addrpc_url_indexto RPC events.- UI Tracking:
components/UI/NetworkModal/index.tsx: TrackRPC_ADDEDfor popular/custom adds withrpc_url_index: 0.Views/Settings/NetworksSettings/NetworkSettings/index.js:
- On RPC add: track
RPC_ADDEDwithchain_id,symbol, and computedrpc_url_index.- On RPC delete: track
RPC_REMOVEDwithrpc_url_index.- RPC Method:
core/RPCMethods/wallet_addEthereumChain.js: When updating/adding networks, emitRPC_ADDED:
- New network:
rpc_url_index: 0.- Existing network: only when a new RPC endpoint is appended; include correct index.
- Tests:
- Add/expand unit tests to assert
RPC_ADDED/RPC_REMOVEDemissions, index accuracy, and hexchain_idinNetworkSettingsandwallet_addEthereumChain.Written by Cursor Bugbot for commit fd0489b2d12d8b646f0693d521249d64324eb404. This will update automatically on new commits. Configure here.
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.
🔍 Smart E2E Test Selection
- Selected E2E tags: SmokeNetworkAbstractions, SmokeWalletPlatform, SmokeAnalytics
- Risk Level: medium
- AI Confidence: 85%
click to see 🤖 AI reasoning details
The changes focus on renaming and improving analytics event tracking for network/RPC management:
-
MetaMetrics.events.ts: Renamed
NETWORK_ADDEDtoRPC_ADDEDand addedRPC_REMOVEDevent. This is an analytics event naming change that affects event tracking across multiple files. -
wallet_addEthereumChain.js: Modified the RPC method to track
RPC_ADDEDinstead ofNETWORK_ADDED, with additional tracking logic for when new RPC endpoints are added vs existing ones. This is a core RPC method used by dApps, WalletConnect, and SDK to add custom networks. -
NetworkModal/index.tsx: Updated to use the new
RPC_ADDEDevent for tracking when popular or custom networks are added. -
NetworkSettings/index.js: Added tracking for
RPC_ADDEDandRPC_REMOVEDevents when users add or remove RPC URLs in the Network Settings UI. -
Test files: Unit tests updated to verify the new analytics events are tracked correctly.
Tag Selection Rationale:
- SmokeNetworkAbstractions: Directly covers network configuration, RPC endpoints, and network management functionality - the core of these changes. E2E tests in
e2e/specs/networks/test adding networks, popular networks, and network management. - SmokeWalletPlatform: Covers core wallet functionality including network switching which interacts with the modified code paths.
- SmokeAnalytics: These changes are primarily about analytics event tracking (RPC_ADDED/RPC_REMOVED events), so analytics tests should verify correct event emission.
The changes are scoped to analytics event tracking and don't modify core business logic (network adding/switching still works the same way), which keeps risk at medium level. The existing unit tests are comprehensive for the new analytics behavior.
Quality Gate passed
Issues
4 New issues
0 Accepted issues
Measures
0 Security Hotspots
94.4% Coverage on New Code
0.0% Duplication on New Code