From f743ea028b6865ff36ac279d2c4a55eb75570c63 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 6 Mar 2024 10:46:39 -0800 Subject: [PATCH] fix: Rename DAPP_VISITED to DAPP_VIEWED (#8838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** These changes renames `Dapp Visited` -> `Dapp Viewed` to match event name with extension Original mobile ticket here - https://github.com/MetaMask/metamask-mobile/pull/8520 ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** https://github.com/MetaMask/metamask-mobile/assets/10508597/b4aedbc6-6c8d-49c4-a9cb-20420636f789 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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. --- app/actions/browser/index.js | 8 +- .../Views/AccountConnect/AccountConnect.tsx | 12 +- app/components/Views/BrowserTab/index.js | 12 +- app/core/Analytics/MetaMetrics.events.ts | 4 +- app/reducers/browser/index.js | 4 +- app/util/metrics/index.ts | 4 +- .../index.test.ts | 20 +-- .../index.ts | 16 +- .../trackDappVisitedEvent/index.test.ts | 169 ------------------ .../metrics/trackDappVisitedEvent/index.ts | 39 ---- 10 files changed, 40 insertions(+), 248 deletions(-) rename app/util/metrics/{trackDappVisited => trackDappViewedEvent}/index.test.ts (90%) rename app/util/metrics/{trackDappVisited => trackDappViewedEvent}/index.ts (77%) delete mode 100644 app/util/metrics/trackDappVisitedEvent/index.test.ts delete mode 100644 app/util/metrics/trackDappVisitedEvent/index.ts diff --git a/app/actions/browser/index.js b/app/actions/browser/index.js index 64c3a2fd522..2d21c3a2182 100644 --- a/app/actions/browser/index.js +++ b/app/actions/browser/index.js @@ -2,18 +2,18 @@ * Browser actions for Redux */ export const BrowserActionTypes = { - ADD_TO_VISITED_DAPP: 'ADD_TO_VISITED_DAPP', + ADD_TO_VIEWED_DAPP: 'ADD_TO_VIEWED_DAPP', }; /** - * Adds a new entry to visited dapps + * Adds a new entry to viewed dapps * * @param {string} hostname - Dapp hostname * @returns */ -export function addToVisitedDapp(hostname) { +export function addToViewedDapp(hostname) { return { - type: BrowserActionTypes.ADD_TO_VISITED_DAPP, + type: BrowserActionTypes.ADD_TO_VIEWED_DAPP, hostname, }; } diff --git a/app/components/Views/AccountConnect/AccountConnect.tsx b/app/components/Views/AccountConnect/AccountConnect.tsx index fe65facdff6..8ff8fbedd78 100644 --- a/app/components/Views/AccountConnect/AccountConnect.tsx +++ b/app/components/Views/AccountConnect/AccountConnect.tsx @@ -55,7 +55,7 @@ import useFavicon from '../../hooks/useFavicon/useFavicon'; import URLParse from 'url-parse'; import SDKConnect from '../../../core/SDKConnect/SDKConnect'; import AppConstants from '../../../../app/core/AppConstants'; -import { trackDappVisitedEvent } from '../../../util/metrics'; +import { trackDappViewedEvent } from '../../../util/metrics'; import { useMetrics } from '../../../components/hooks/useMetrics'; import { RootState } from '../../../../app/reducers'; @@ -171,10 +171,10 @@ const AccountConnect = (props: AccountConnectProps) => { ], ); - const triggerDappVisitedEvent = useCallback( + const triggerDappViewedEvent = useCallback( (numberOfConnectedAccounts: number) => - // Track dapp visited event - trackDappVisitedEvent({ hostname, numberOfConnectedAccounts }), + // Track dapp viewed event + trackDappViewedEvent({ hostname, numberOfConnectedAccounts }), [hostname], ); @@ -205,7 +205,7 @@ const AccountConnect = (props: AccountConnectProps) => { request, ); - triggerDappVisitedEvent(connectedAccountLength); + triggerDappViewedEvent(connectedAccountLength); trackEvent(MetaMetricsEvents.CONNECT_REQUEST_COMPLETED, { number_of_accounts: accountsLength, @@ -250,7 +250,7 @@ const AccountConnect = (props: AccountConnectProps) => { toastRef, accountsLength, metadataOrigin, - triggerDappVisitedEvent, + triggerDappViewedEvent, trackEvent, ]); diff --git a/app/components/Views/BrowserTab/index.js b/app/components/Views/BrowserTab/index.js index 539a36ccdae..61fc1c71bbc 100644 --- a/app/components/Views/BrowserTab/index.js +++ b/app/components/Views/BrowserTab/index.js @@ -99,7 +99,7 @@ import { regex } from '../../../../app/util/regex'; import { selectChainId } from '../../../selectors/networkController'; import { BrowserViewSelectorsIDs } from '../../../../e2e/selectors/BrowserView.selectors'; import { useMetrics } from '../../../components/hooks/useMetrics'; -import trackDappVisitedEvent from '../../../util/metrics/trackDappVisited'; +import { trackDappViewedEvent } from '../../../util/metrics'; import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAsAnalytics'; const { HOMEPAGE_URL, NOTIFICATION_NAMES } = AppConstants; @@ -531,7 +531,7 @@ export const BrowserTab = (props) => { [goBack, props.ipfsGateway, setIpfsBannerVisible, props.chainId], ); - const triggerDappVisitedEvent = (url) => { + const triggerDappViewedEvent = (url) => { const permissionsControllerState = Engine.context.PermissionController.state; const hostname = new URL(url).hostname; @@ -545,8 +545,8 @@ export const BrowserTab = (props) => { return; } - // Track dapp visited event - trackDappVisitedEvent({ + // Track dapp viewed event + trackDappViewedEvent({ hostname, numberOfConnectedAccounts: connectedAccounts.length, }); @@ -596,7 +596,7 @@ export const BrowserTab = (props) => { // Skip tracking on initial open if (!initialCall) { - triggerDappVisitedEvent(urlToGo); + triggerDappViewedEvent(urlToGo); } setProgress(0); @@ -627,7 +627,7 @@ export const BrowserTab = (props) => { const { current } = webviewRef; current && current.reload(); - triggerDappVisitedEvent(url.current); + triggerDappViewedEvent(url.current); }, []); /** diff --git a/app/core/Analytics/MetaMetrics.events.ts b/app/core/Analytics/MetaMetrics.events.ts index aad8067e9bd..9c8a8ece16a 100644 --- a/app/core/Analytics/MetaMetrics.events.ts +++ b/app/core/Analytics/MetaMetrics.events.ts @@ -151,7 +151,7 @@ enum EVENT_NAME { BROWSER_RELOAD = 'Reload Browser', BROWSER_ADD_FAVORITES = 'Added Site To Favorites', BROWSER_SWITCH_TAB = 'Switched tab within Browser', - DAPP_VISITED = 'Dapp Visited', + DAPP_VIEWED = 'Dapp Viewed', // Security & Privacy Settings VIEW_SECURITY_SETTINGS = 'Views Security & Privacy', @@ -534,7 +534,7 @@ const events = { BROWSER_SHARE_SITE: generateOpt(EVENT_NAME.BROWSER_SHARE_SITE), BROWSER_RELOAD: generateOpt(EVENT_NAME.BROWSER_RELOAD), BROWSER_ADD_FAVORITES: generateOpt(EVENT_NAME.BROWSER_ADD_FAVORITES), - DAPP_VISITED: generateOpt(EVENT_NAME.DAPP_VISITED), + DAPP_VIEWED: generateOpt(EVENT_NAME.DAPP_VIEWED), // Security & Privacy Settings VIEW_SECURITY_SETTINGS: generateOpt(EVENT_NAME.VIEW_SECURITY_SETTINGS), // Reveal SRP diff --git a/app/reducers/browser/index.js b/app/reducers/browser/index.js index f7824534cd7..fec7595d4d2 100644 --- a/app/reducers/browser/index.js +++ b/app/reducers/browser/index.js @@ -7,12 +7,12 @@ const initialState = { tabs: [], favicons: [], activeTab: null, - // Keep track of visited Dapps, which is used for MetaMetricsEvents.DAPP_VIEWED event + // Keep track of viewed Dapps, which is used for MetaMetricsEvents.DAPP_VIEWED event visitedDappsByHostname: {}, }; const browserReducer = (state = initialState, action) => { switch (action.type) { - case BrowserActionTypes.ADD_TO_VISITED_DAPP: { + case BrowserActionTypes.ADD_TO_VIEWED_DAPP: { const { hostname } = action; return { ...state, diff --git a/app/util/metrics/index.ts b/app/util/metrics/index.ts index 6942d325ebc..db4c2d0b4be 100644 --- a/app/util/metrics/index.ts +++ b/app/util/metrics/index.ts @@ -1,9 +1,9 @@ import DeviceAnalyticsMetaData from './DeviceAnalyticsMetaData/generateDeviceAnalyticsMetaData'; import UserSettingsAnalyticsMetaData from './UserSettingsAnalyticsMetaData/generateUserProfileAnalyticsMetaData'; import TrackAfterInteractions from './TrackAfterInteraction/trackAfterInteractions'; -import trackDappVisitedEvent from './trackDappVisitedEvent'; +import trackDappViewedEvent from './trackDappViewedEvent'; export default DeviceAnalyticsMetaData; export { UserSettingsAnalyticsMetaData }; export { TrackAfterInteractions }; -export { trackDappVisitedEvent }; +export { trackDappViewedEvent }; diff --git a/app/util/metrics/trackDappVisited/index.test.ts b/app/util/metrics/trackDappViewedEvent/index.test.ts similarity index 90% rename from app/util/metrics/trackDappVisited/index.test.ts rename to app/util/metrics/trackDappViewedEvent/index.test.ts index 8c5896d68a6..f3d3ecdce87 100644 --- a/app/util/metrics/trackDappVisited/index.test.ts +++ b/app/util/metrics/trackDappViewedEvent/index.test.ts @@ -1,4 +1,4 @@ -import trackDappVisitedEvent from './index'; +import trackDappViewedEvent from './index'; import { MetaMetrics, MetaMetricsEvents } from '../../../core/Analytics'; jest.mock('../../../core/Analytics/MetaMetrics'); @@ -34,7 +34,7 @@ jest.mock('../../../store', () => { }; }); -describe('trackDappVisitedEvent', () => { +describe('trackDappViewedEvent', () => { afterEach(() => { jest.clearAllMocks(); }); @@ -60,13 +60,13 @@ describe('trackDappVisitedEvent', () => { source: 'in-app browser', }; - trackDappVisitedEvent({ + trackDappViewedEvent({ hostname: 'uniswap.org', numberOfConnectedAccounts: 1, }); expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, + MetaMetricsEvents.DAPP_VIEWED, expectedMetrics, ); }); @@ -92,13 +92,13 @@ describe('trackDappVisitedEvent', () => { source: 'in-app browser', }; - trackDappVisitedEvent({ + trackDappViewedEvent({ hostname: 'uniswap.org', numberOfConnectedAccounts: 1, }); expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, + MetaMetricsEvents.DAPP_VIEWED, expectedMetrics, ); }); @@ -124,13 +124,13 @@ describe('trackDappVisitedEvent', () => { source: 'in-app browser', }; - trackDappVisitedEvent({ + trackDappViewedEvent({ hostname: 'uniswap.org', numberOfConnectedAccounts: 1, }); expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, + MetaMetricsEvents.DAPP_VIEWED, expectedMetrics, ); }); @@ -156,13 +156,13 @@ describe('trackDappVisitedEvent', () => { source: 'in-app browser', }; - trackDappVisitedEvent({ + trackDappViewedEvent({ hostname: 'uniswap.org', numberOfConnectedAccounts: 1, }); expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, + MetaMetricsEvents.DAPP_VIEWED, expectedMetrics, ); }); diff --git a/app/util/metrics/trackDappVisited/index.ts b/app/util/metrics/trackDappViewedEvent/index.ts similarity index 77% rename from app/util/metrics/trackDappVisited/index.ts rename to app/util/metrics/trackDappViewedEvent/index.ts index 58993a279af..44983d7163c 100644 --- a/app/util/metrics/trackDappVisited/index.ts +++ b/app/util/metrics/trackDappViewedEvent/index.ts @@ -1,18 +1,18 @@ import { store } from '../../../store'; import { selectIdentities } from '../../../selectors/preferencesController'; -import { addToVisitedDapp } from '../../../actions/browser'; +import { addToViewedDapp } from '../../../actions/browser'; import { MetaMetrics, MetaMetricsEvents } from '../../../core/Analytics'; /** - * Tracks Dapp visited event + * Tracks Dapp viewed event * - * This is used to track when a user visits a Dapp in the in-app browser + * This is used to track when a user viewed a Dapp in the in-app browser * * @param params - The parameter object for the tracking function * @param params.hostname - Hostname of the Dapp * @param params.numberOfConnectedAccounts - Number of connected accounts that are connected to the Dapp */ -const trackDappVisitedEvent = ({ +const trackDappViewedEvent = ({ hostname, numberOfConnectedAccounts, }: { @@ -25,10 +25,10 @@ const trackDappVisitedEvent = ({ const accountByAddress = selectIdentities(store.getState()); const numberOfWalletAccounts = Object.keys(accountByAddress).length; - // Add Dapp hostname to visited dapps - store.dispatch(addToVisitedDapp(hostname)); + // Add Dapp hostname to viewed dapps + store.dispatch(addToViewedDapp(hostname)); - MetaMetrics.getInstance().trackEvent(MetaMetricsEvents.DAPP_VISITED, { + MetaMetrics.getInstance().trackEvent(MetaMetricsEvents.DAPP_VIEWED, { is_first_visit: isFirstVisit, number_of_accounts: numberOfWalletAccounts, number_of_accounts_connected: numberOfConnectedAccounts, @@ -36,4 +36,4 @@ const trackDappVisitedEvent = ({ }); }; -export default trackDappVisitedEvent; +export default trackDappViewedEvent; diff --git a/app/util/metrics/trackDappVisitedEvent/index.test.ts b/app/util/metrics/trackDappVisitedEvent/index.test.ts deleted file mode 100644 index 8c5896d68a6..00000000000 --- a/app/util/metrics/trackDappVisitedEvent/index.test.ts +++ /dev/null @@ -1,169 +0,0 @@ -import trackDappVisitedEvent from './index'; -import { MetaMetrics, MetaMetricsEvents } from '../../../core/Analytics'; - -jest.mock('../../../core/Analytics/MetaMetrics'); - -const mockMetrics = { - trackEvent: jest.fn(), -}; - -(MetaMetrics.getInstance as jest.Mock).mockReturnValue(mockMetrics); - -// Mock store.getState -let mockGetState: jest.Mock; -jest.mock('../../../store', () => { - mockGetState = jest.fn(); - mockGetState.mockImplementation(() => ({ - browser: { - visitedDappsByHostname: {}, - }, - engine: { - backgroundState: { - PreferencesController: { - identities: { '0x1': true, '0x2': true }, - }, - }, - }, - })); - - return { - store: { - getState: mockGetState, - dispatch: jest.fn(), - }, - }; -}); - -describe('trackDappVisitedEvent', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - it('should track with isFirstVisit = true', () => { - mockGetState.mockImplementation(() => ({ - browser: { - visitedDappsByHostname: {}, - }, - engine: { - backgroundState: { - PreferencesController: { - identities: { '0x1': true, '0x2': true }, - }, - }, - }, - })); - - const expectedMetrics = { - is_first_visit: true, - number_of_accounts: 2, - number_of_accounts_connected: 1, - source: 'in-app browser', - }; - - trackDappVisitedEvent({ - hostname: 'uniswap.org', - numberOfConnectedAccounts: 1, - }); - - expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, - expectedMetrics, - ); - }); - - it('should track with isFirstVisit = false', () => { - mockGetState.mockImplementation(() => ({ - browser: { - visitedDappsByHostname: { 'uniswap.org': true }, - }, - engine: { - backgroundState: { - PreferencesController: { - identities: { '0x1': true, '0x2': true }, - }, - }, - }, - })); - - const expectedMetrics = { - is_first_visit: false, - number_of_accounts: 2, - number_of_accounts_connected: 1, - source: 'in-app browser', - }; - - trackDappVisitedEvent({ - hostname: 'uniswap.org', - numberOfConnectedAccounts: 1, - }); - - expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, - expectedMetrics, - ); - }); - - it('should track with the correct number of connected accounts', () => { - mockGetState.mockImplementation(() => ({ - browser: { - visitedDappsByHostname: { 'uniswap.org': true }, - }, - engine: { - backgroundState: { - PreferencesController: { - identities: { '0x1': true, '0x2': true }, - }, - }, - }, - })); - - const expectedMetrics = { - is_first_visit: false, - number_of_accounts: 2, - number_of_accounts_connected: 1, - source: 'in-app browser', - }; - - trackDappVisitedEvent({ - hostname: 'uniswap.org', - numberOfConnectedAccounts: 1, - }); - - expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, - expectedMetrics, - ); - }); - - it('should track with the correct number of wallet accounts', () => { - mockGetState.mockImplementation(() => ({ - browser: { - visitedDappsByHostname: { 'uniswap.org': true }, - }, - engine: { - backgroundState: { - PreferencesController: { - identities: { '0x1': true }, - }, - }, - }, - })); - - const expectedMetrics = { - is_first_visit: false, - number_of_accounts: 1, - number_of_accounts_connected: 1, - source: 'in-app browser', - }; - - trackDappVisitedEvent({ - hostname: 'uniswap.org', - numberOfConnectedAccounts: 1, - }); - - expect(mockMetrics.trackEvent).toBeCalledWith( - MetaMetricsEvents.DAPP_VISITED, - expectedMetrics, - ); - }); -}); diff --git a/app/util/metrics/trackDappVisitedEvent/index.ts b/app/util/metrics/trackDappVisitedEvent/index.ts deleted file mode 100644 index 58993a279af..00000000000 --- a/app/util/metrics/trackDappVisitedEvent/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { store } from '../../../store'; -import { selectIdentities } from '../../../selectors/preferencesController'; -import { addToVisitedDapp } from '../../../actions/browser'; -import { MetaMetrics, MetaMetricsEvents } from '../../../core/Analytics'; - -/** - * Tracks Dapp visited event - * - * This is used to track when a user visits a Dapp in the in-app browser - * - * @param params - The parameter object for the tracking function - * @param params.hostname - Hostname of the Dapp - * @param params.numberOfConnectedAccounts - Number of connected accounts that are connected to the Dapp - */ -const trackDappVisitedEvent = ({ - hostname, - numberOfConnectedAccounts, -}: { - hostname: string; - numberOfConnectedAccounts: number; -}) => { - const visitedDappsByHostname = - store.getState().browser.visitedDappsByHostname; - const isFirstVisit = !visitedDappsByHostname[hostname]; - const accountByAddress = selectIdentities(store.getState()); - const numberOfWalletAccounts = Object.keys(accountByAddress).length; - - // Add Dapp hostname to visited dapps - store.dispatch(addToVisitedDapp(hostname)); - - MetaMetrics.getInstance().trackEvent(MetaMetricsEvents.DAPP_VISITED, { - is_first_visit: isFirstVisit, - number_of_accounts: numberOfWalletAccounts, - number_of_accounts_connected: numberOfConnectedAccounts, - source: 'in-app browser', - }); -}; - -export default trackDappVisitedEvent;