metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

refactor: update RPC event tracking and analytics for network management

Open PatrykLucka opened this issue 1 year ago • 3 comments

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_ADDED event to RPC_ADDED to better reflect that we're tracking RPC endpoint additions, not just network additions
  • Added new RPC_DELETED event to track when RPC endpoints are removed
  • Added rpc_url_index property to both events:
    • 0 indicates there is only 1 RPC URL for the network (first/only endpoint)
    • Higher values indicate additional RPC endpoints
  • Standardized all chain_id values to use toHex() format for consistency across all RPC tracking events
  • Updated tracking in:
    • NetworkModal - when networks are added via UI
    • wallet_addEthereumChain - when RPC endpoints are added via RPC method
    • NetworkSettings - 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

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_ADDED to RPC_ADDED; add RPC_REMOVED in core/Analytics/MetaMetrics.events.ts and exports.
    • Standardize chain_id to hex via toHex; add rpc_url_index to RPC events.
  • UI Tracking:
    • components/UI/NetworkModal/index.tsx: Track RPC_ADDED for popular/custom adds with rpc_url_index: 0.
    • Views/Settings/NetworksSettings/NetworkSettings/index.js:
      • On RPC add: track RPC_ADDED with chain_id, symbol, and computed rpc_url_index.
      • On RPC delete: track RPC_REMOVED with rpc_url_index.
  • RPC Method:
    • core/RPCMethods/wallet_addEthereumChain.js: When updating/adding networks, emit RPC_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_REMOVED emissions, index accuracy, and hex chain_id in NetworkSettings and wallet_addEthereumChain.

Written by Cursor Bugbot for commit fd0489b2d12d8b646f0693d521249d64324eb404. This will update automatically on new commits. Configure here.

PatrykLucka avatar Nov 25 '25 11:11 PatrykLucka

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.

github-actions[bot] avatar Nov 25 '25 11:11 github-actions[bot]

🔍 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:

  1. MetaMetrics.events.ts: Renamed NETWORK_ADDED to RPC_ADDED and added RPC_REMOVED event. This is an analytics event naming change that affects event tracking across multiple files.

  2. wallet_addEthereumChain.js: Modified the RPC method to track RPC_ADDED instead of NETWORK_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.

  3. NetworkModal/index.tsx: Updated to use the new RPC_ADDED event for tracking when popular or custom networks are added.

  4. NetworkSettings/index.js: Added tracking for RPC_ADDED and RPC_REMOVED events when users add or remove RPC URLs in the Network Settings UI.

  5. 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.

View GitHub Actions results

github-actions[bot] avatar Dec 10 '25 13:12 github-actions[bot]