From 724605879782f3b93285dfc2fb25677fc3ad1d20 Mon Sep 17 00:00:00 2001 From: Filip Sekulic Date: Wed, 13 Jul 2022 16:17:13 +0200 Subject: [PATCH] Added metrics for adding a new network (#15176) * Added metrics for adding a new network * Applied requested changes * Added missed changes --- .../handlers/add-ethereum-chain.js | 6 ++-- app/scripts/metamask-controller.js | 19 ++++++++++++ shared/constants/metametrics.js | 4 +++ .../networks-form/networks-form.js | 29 ++++++++++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js index 04d66a3ad..13e2ae1ff 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js @@ -267,9 +267,8 @@ async function addEthereumChainHandler( referrer: { url: origin, }, - sensitiveProperties: { + properties: { chain_id: _chainId, - rpc_url: firstValidRPCUrl, network_name: _chainName, // Including network to override the default network // property included in all events. For RPC type networks @@ -280,6 +279,9 @@ async function addEthereumChainHandler( block_explorer_url: firstValidBlockExplorerUrl, source: EVENT.SOURCE.TRANSACTION.DAPP, }, + sensitiveProperties: { + rpc_url: firstValidRPCUrl, + }, }); // Once the network has been added, the requested is considered successful diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index d01d277e7..c91c12faf 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2064,6 +2064,25 @@ export default class MetamaskController extends EventEmitter { blockExplorerUrl, }, ); + + this.metaMetricsController.trackEvent({ + event: 'Custom Network Added', + category: EVENT.CATEGORIES.NETWORK, + referrer: { + url: rpcUrl, + }, + properties: { + chain_id: chainId, + network_name: chainName, + network: rpcUrl, + symbol: ticker, + block_explorer_url: blockExplorerUrl, + source: EVENT.SOURCE.NETWORK.POPULAR_NETWORK_LIST, + }, + sensitiveProperties: { + rpc_url: rpcUrl, + }, + }); } /** diff --git a/shared/constants/metametrics.js b/shared/constants/metametrics.js index 1751c2a55..2fe2a0457 100644 --- a/shared/constants/metametrics.js +++ b/shared/constants/metametrics.js @@ -305,6 +305,10 @@ export const EVENT = { WALLET: 'Wallet', }, SOURCE: { + NETWORK: { + POPULAR_NETWORK_LIST: 'popular_network_list', + CUSTOM_NETWORK_FORM: 'custom_network_form', + }, SWAPS: { MAIN_VIEW: 'Main View', TOKEN_VIEW: 'Token View', diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index 22c28a170..c097e53c0 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -1,4 +1,10 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react'; +import React, { + useCallback, + useContext, + useEffect, + useRef, + useState, +} from 'react'; import { useHistory } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; @@ -28,6 +34,8 @@ import { } from '../../../../helpers/constants/routes'; import fetchWithCache from '../../../../helpers/utils/fetch-with-cache'; import { usePrevious } from '../../../../hooks/usePrevious'; +import { MetaMetricsContext } from '../../../../contexts/metametrics'; +import { EVENT } from '../../../../../shared/constants/metametrics'; /** * Attempts to convert the given chainId to a decimal string, for display @@ -73,6 +81,7 @@ const NetworksForm = ({ selectedNetwork, }) => { const t = useI18nContext(); + const trackEvent = useContext(MetaMetricsContext); const history = useHistory(); const dispatch = useDispatch(); const { label, labelKey, viewOnly, rpcPrefs } = selectedNetwork; @@ -496,6 +505,24 @@ const NetworksForm = ({ } if (addNewNetwork) { + trackEvent({ + event: 'Custom Network Added', + category: EVENT.CATEGORIES.NETWORK, + referrer: { + url: rpcUrl, + }, + properties: { + chain_id: chainId, + network_name: networkName, + network: rpcUrl, + symbol: ticker, + block_explorer_url: blockExplorerUrl, + source: EVENT.SOURCE.NETWORK.CUSTOM_NETWORK_FORM, + }, + sensitiveProperties: { + rpc_url: rpcUrl, + }, + }); dispatch(setNewNetworkAdded(networkName)); history.push(DEFAULT_ROUTE); }