Skip to content

Commit

Permalink
fix: add desktop related events
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Feb 24, 2023
1 parent 07d5c07 commit e396ade
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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}`;
Expand All @@ -30,6 +32,7 @@ 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);
Expand Down Expand Up @@ -81,16 +84,23 @@ export default function DesktopEnableButton() {
history.push(DESKTOP_PAIRING_ROUTE);
};

const getButtonText = (isDesktopEnabled) =>
isDesktopEnabled ? 'Disable Desktop App' : 'Enable Desktop App';

return (
<Button
type="primary"
large
onClick={(event) => {
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `${getButtonText(desktopEnabled)} Button Clicked`,
});
event.preventDefault();
onClick();
}}
>
{desktopEnabled ? t('desktopDisableButton') : t('desktopEnableButton')}
{getButtonText(desktopEnabled)}
</Button>
);
}
4 changes: 4 additions & 0 deletions ui/pages/desktop-error/desktop-error.component.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useParams, useHistory } from 'react-router-dom';
import { useContext } from 'react';
import { useI18nContext } from '../../hooks/useI18nContext';
import {
downloadDesktopApp,
downloadExtension,
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,
Expand All @@ -25,5 +28,6 @@ export default function DesktopError({ forceDisableDesktop }) {
downloadDesktopApp,
downloadExtension,
restartExtension,
trackEvent,
});
}
26 changes: 25 additions & 1 deletion ui/pages/desktop-error/render-desktop-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +28,7 @@ export function renderDesktopError({
downloadDesktopApp,
restartExtension,
openOrDownloadDesktopApp,
trackEvent,
}) {
let content;

Expand All @@ -43,6 +45,12 @@ export function renderDesktopError({
};

const renderHeader = (text) => {
if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.ERROR,
event: `Error: ${text}`,
});
}
return (
<Typography
variant={TypographyVariant.H4}
Expand All @@ -64,7 +72,23 @@ export function renderDesktopError({
const renderCTA = (id, text, onClick) => {
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: `${text} Button Clicked`,
});
}
} else {
noop();
}
}}
id={id}
>
{text}
</Button>
</Box>
Expand Down

0 comments on commit e396ade

Please sign in to comment.