1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

identify desktop is paired in the metrics event (#17892)

This commit is contained in:
Vinicius Stevam 2023-03-02 20:55:27 +00:00 committed by GitHub
parent 7f648e4acf
commit e07ec9dcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 3 deletions

View File

@ -716,6 +716,9 @@ export default class MetaMetricsController {
[TRAITS.THREE_BOX_ENABLED]: false, // deprecated, hard-coded as false
[TRAITS.THEME]: metamaskState.theme || 'default',
[TRAITS.TOKEN_DETECTION_ENABLED]: metamaskState.useTokenDetection,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
[TRAITS.DESKTOP_ENABLED]: metamaskState.desktopEnabled || false,
///: END:ONLY_INCLUDE_IN
};
if (!previousUserTraits) {

View File

@ -944,6 +944,7 @@ describe('MetaMetricsController', function () {
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
desktopEnabled: false,
});
assert.deepEqual(traits, {
@ -961,6 +962,7 @@ describe('MetaMetricsController', function () {
[TRAITS.THREE_BOX_ENABLED]: false,
[TRAITS.THEME]: 'default',
[TRAITS.TOKEN_DETECTION_ENABLED]: true,
[TRAITS.DESKTOP_ENABLED]: false,
});
});
@ -982,6 +984,7 @@ describe('MetaMetricsController', function () {
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
desktopEnabled: false,
});
const updatedTraits = metaMetricsController._buildUserTraitsObject({
@ -1002,6 +1005,7 @@ describe('MetaMetricsController', function () {
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
desktopEnabled: false,
});
assert.deepEqual(updatedTraits, {
@ -1030,6 +1034,7 @@ describe('MetaMetricsController', function () {
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
desktopEnabled: false,
});
const updatedTraits = metaMetricsController._buildUserTraitsObject({
@ -1048,6 +1053,7 @@ describe('MetaMetricsController', function () {
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
desktopEnabled: false,
});
assert.equal(updatedTraits, null);

View File

@ -186,6 +186,7 @@
* @property {'token_detection_enabled'} TOKEN_DETECTION_ENABLED - when token detection feature is toggled we
* identify the token_detection_enabled trait
* @property {'install_date_ext'} INSTALL_DATE_EXT - when the user installed the extension
* @property {'desktop_enabled'} [DESKTOP_ENABLED] - optional / does the user have desktop enabled?
*/
/**
@ -208,6 +209,7 @@ export const TRAITS = {
THEME: 'theme',
THREE_BOX_ENABLED: 'three_box_enabled',
TOKEN_DETECTION_ENABLED: 'token_detection_enabled',
DESKTOP_ENABLED: 'desktop_enabled',
};
/**
@ -237,6 +239,7 @@ export const TRAITS = {
* enabled? (deprecated)
* @property {string} [theme] - which theme the user has selected
* @property {boolean} [token_detection_enabled] - does the user have token detection is enabled?
* @property {boolean} [desktop_enabled] - optional / does the user have desktop enabled?
*/
// Mixpanel converts the zero address value to a truly anonymous event, which
@ -399,6 +402,7 @@ export const EVENT = {
SWAPS: 'Swaps',
TRANSACTIONS: 'Transactions',
WALLET: 'Wallet',
DESKTOP: 'Desktop',
},
EXTERNAL_LINK_TYPES: {
TRANSACTION_BLOCK_EXPLORER: 'Transaction Block Explorer',

View File

@ -19,17 +19,21 @@ import {
disableDesktop,
} from '../../../store/actions';
import { SECOND } from '../../../../shared/constants/time';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import { EVENT } from '../../../../shared/constants/metametrics';
const DESKTOP_ERROR_DESKTOP_OUTDATED_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.DESKTOP_OUTDATED}`;
const DESKTOP_ERROR_EXTENSION_OUTDATED_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.EXTENSION_OUTDATED}`;
const DESKTOP_ERROR_NOT_FOUND_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.NOT_FOUND}`;
const DESKTOP_ERROR_PAIRING_KEY_NOT_MATCH_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.PAIRING_KEY_NOT_MATCH}`;
const SKIP_PAIRING_RESTART_DELAY = 2 * SECOND;
const DESKTOP_UPDATE_SETTINGS_EVENT = 'Settings Updated';
export default function DesktopEnableButton() {
const t = useContext(I18nContext);
const dispatch = useDispatch();
const history = useHistory();
const trackEvent = useContext(MetaMetricsContext);
const showLoader = () => dispatch(showLoadingIndication());
const hideLoader = () => dispatch(hideLoadingIndication());
const desktopEnabled = useSelector(getIsDesktopEnabled);
@ -40,6 +44,13 @@ export default function DesktopEnableButton() {
if (desktopEnabled) {
await disableDesktop();
setDesktopEnabled(false);
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: DESKTOP_UPDATE_SETTINGS_EVENT,
properties: {
desktop_enabled: false,
},
});
return;
}
@ -78,9 +89,19 @@ export default function DesktopEnableButton() {
return;
}
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: 'Desktop Button Clicked',
properties: {
button_action: 'Enable MetaMask Desktop',
},
});
history.push(DESKTOP_PAIRING_ROUTE);
};
const getButtonText = (isDesktopEnabled) =>
isDesktopEnabled ? t('desktopDisableButton') : t('desktopEnableButton');
return (
<Button
type="primary"
@ -90,7 +111,7 @@ export default function DesktopEnableButton() {
onClick();
}}
>
{desktopEnabled ? t('desktopDisableButton') : t('desktopEnableButton')}
{getButtonText(desktopEnabled)}
</Button>
);
}

View File

@ -1,4 +1,5 @@
import { useParams, useHistory } from 'react-router-dom';
import { useContext } from 'react';
import { useI18nContext } from '../../hooks/useI18nContext';
import {
downloadDesktopApp,
@ -6,12 +7,14 @@ import {
restartExtension,
} from '../../../shared/lib/error-utils';
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
import { MetaMetricsContext } from '../../contexts/metametrics';
import { renderDesktopError } from './render-desktop-error';
export default function DesktopError({ forceDisableDesktop }) {
const t = useI18nContext();
const { errorType } = useParams();
const history = useHistory();
const trackEvent = useContext(MetaMetricsContext);
return renderDesktopError({
type: errorType,
@ -25,5 +28,6 @@ export default function DesktopError({ forceDisableDesktop }) {
downloadDesktopApp,
downloadExtension,
restartExtension,
trackEvent,
});
}

View File

@ -16,6 +16,7 @@ import Typography from '../../components/ui/typography';
import Button from '../../components/ui/button';
import Box from '../../components/ui/box';
import { openCustomProtocol } from '../../../shared/lib/deep-linking';
import { EVENT } from '../../../shared/constants/metametrics';
export function renderDesktopError({
type,
@ -27,9 +28,21 @@ export function renderDesktopError({
downloadDesktopApp,
restartExtension,
openOrDownloadDesktopApp,
trackEvent,
}) {
let content;
const DESKTOP_BUTTON_ACTIONS = {
DOWNLOAD_METAMASK_DESKTOP: 'Download MetaMask Desktop',
OPEN_METAMASK_DESKTOP: 'Open MetaMask Desktop',
DISABLE_METAMASK_DESKTOP: 'Disable MetaMask Desktop',
UPDATE_METAMASK_DESKTOP: 'Update MetaMask Desktop',
RETURN_SETTINGS_PAGE: 'Return to Settings Page',
UPDATE_METAMASK_EXTENSION: 'Update MetaMask Extension',
RESTART_METAMASK: 'Restart MetaMask',
RETURN_METAMASK_HOME: 'Return MetaMask Home',
};
const noop = () => {
// do nothing
};
@ -61,10 +74,29 @@ export function renderDesktopError({
);
};
const renderCTA = (id, text, onClick) => {
const renderCTA = (id, text, onClick, action) => {
return (
<Box marginTop={6}>
<Button type="primary" onClick={onClick ?? noop} id={id}>
<Button
type="primary"
onClick={() => {
if (onClick) {
onClick();
if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: 'Desktop Button Clicked',
properties: {
button_action: action,
},
});
}
} else {
noop();
}
}}
id={id}
>
{text}
</Button>
</Box>
@ -88,6 +120,7 @@ export function renderDesktopError({
'desktop-error-button-download-mmd',
t('desktopNotFoundErrorCTA'),
downloadDesktopApp,
DESKTOP_BUTTON_ACTIONS.DOWNLOAD_METAMASK_DESKTOP,
)}
</>
);
@ -107,6 +140,7 @@ export function renderDesktopError({
'desktop-error-button-disable-mmd',
t('desktopDisableErrorCTA'),
disableDesktop,
DESKTOP_BUTTON_ACTIONS.DISABLE_METAMASK_DESKTOP,
)}
</>
);
@ -121,6 +155,7 @@ export function renderDesktopError({
'desktop-error-button-update-mmd',
t('desktopOutdatedErrorCTA'),
downloadDesktopApp,
DESKTOP_BUTTON_ACTIONS.UPDATE_METAMASK_DESKTOP,
)}
</>
);
@ -135,6 +170,7 @@ export function renderDesktopError({
'desktop-error-button-update-extension',
t('desktopOutdatedExtensionErrorCTA'),
downloadExtension,
DESKTOP_BUTTON_ACTIONS.UPDATE_METAMASK_EXTENSION,
)}
</>
);
@ -149,11 +185,13 @@ export function renderDesktopError({
'desktop-error-button-restart-mm',
t('desktopErrorRestartMMCTA'),
restartExtension,
DESKTOP_BUTTON_ACTIONS.RESTART_METAMASK,
)}
{renderCTA(
'desktop-error-button-disable-mmd',
t('desktopDisableErrorCTA'),
disableDesktop,
DESKTOP_BUTTON_ACTIONS.DISABLE_METAMASK_DESKTOP,
)}
</>
);
@ -170,6 +208,7 @@ export function renderDesktopError({
'desktop-error-button-navigate-settings',
t('desktopErrorNavigateSettingsCTA'),
navigateSettings,
DESKTOP_BUTTON_ACTIONS.RETURN_SETTINGS_PAGE,
)}
</>
);
@ -194,6 +233,7 @@ export function renderDesktopError({
'desktop-error-button-navigate-settings',
t('desktopErrorNavigateSettingsCTA'),
navigateSettings,
DESKTOP_BUTTON_ACTIONS.RETURN_SETTINGS_PAGE,
)}
</>
);
@ -208,6 +248,7 @@ export function renderDesktopError({
'desktop-error-button-return-mm-home',
t('desktopUnexpectedErrorCTA'),
returnExtensionHome,
DESKTOP_BUTTON_ACTIONS.RETURN_METAMASK_HOME,
)}
</>
);