Skip to content

Commit 6ca921e

Browse files
authored
feat(perps): mixpanels events consolidation (#20468)
## **Description** Consolidates Perps MetaMetrics events from 33+ individual events to 8 consolidated events (76% reduction) using parameter-based differentiation and single-event pattern. **What is the reason for the change?** Perps was tracking excessive individual events, creating analytics complexity and maintenance overhead. Additionally, multiple intermediate events (INITIATED/SUBMITTED) were being fired per operation, creating noise in analytics. **What is the improvement/solution?** Consolidated into 8 strategic events with single-event pattern: - 4 transaction lifecycle events (withdrawal, trade, position close, order cancel) - status-based - 3 user interaction events (screen views, UI interactions, risk management) - type-based - 1 cross-cutting error event - for tracking validation errors, API failures, and provider issues **Key optimizations:** - **Single Event Pattern:** Each operation fires ONE event when complete (no INITIATED/SUBMITTED) - **Consistent tracking:** All operations capture completion_duration and final status - **Added missing tracking:** editOrder previously had no tracking - **Input method tracking:** Captures how users set order amounts (slider, keypad, percentage, max) Maintains full tracking capability with cleaner analytics and significantly reduced complexity. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: Perps event consolidation for analytics optimization ## **Manual testing steps** ```gherkin Feature: Consolidated Perps event tracking Scenario: user views screens Given user navigates through Perps When user visits markets, trading, tutorial screens Then PERPS_SCREEN_VIEWED events track with screen_type parameter Scenario: user interacts with UI Given user is on Perps screens When user changes settings, searches, selects order types Then PERPS_UI_INTERACTION events track with interaction_type parameter Scenario: user creates order with TP/SL Given user is creating a new order When user sets stop loss or take profit during order creation Then TP/SL is included in PERPS_TRADE_TRANSACTION event when order executes Scenario: user manages risk on existing position Given user has an existing position When user edits stop loss or take profit Then PERPS_RISK_MANAGEMENT events track with action_type parameter (submitted, executed, failed) Scenario: user performs transactions Given user initiates trades, withdrawals, or order cancellations When transaction progresses through states Then transaction events track with status parameter (initiated, submitted, executed, failed) ``` ## **Screenshots/Recordings** ### **Before** 33+ individual events for each screen, interaction, and transaction state ### **After** 8 consolidated events with parameter-based differentiation and single-event pattern: 1. `PERPS_WITHDRAWAL_TRANSACTION` (status: executed/failed) 2. `PERPS_TRADE_TRANSACTION` (status: executed/failed) - also covers order edits 3. `PERPS_POSITION_CLOSE_TRANSACTION` (status: executed/failed) 4. `PERPS_ORDER_CANCEL_TRANSACTION` (status: executed/failed) 5. `PERPS_SCREEN_VIEWED` (screen_type-based) 6. `PERPS_UI_INTERACTION` (interaction_type-based) 7. `PERPS_RISK_MANAGEMENT` (status: executed/failed for TP/SL edits) 8. `PERPS_ERROR` (error_type-based) **Event Pattern:** - Transaction events fire ONE event when operation completes (no INITIATED/SUBMITTED) - All events include completion_duration for performance measurement - Status-based differentiation (executed/failed) instead of separate events ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Consolidates Perps analytics into a small set of status/type-based events and updates controllers/UI to emit them with new properties (status, screen_type, input_method), including tracking for order edit/cancel. > > - **Analytics Schema**: > - Replace 30+ granular events with 8 unified events: `PERPS_SCREEN_VIEWED`, `PERPS_UI_INTERACTION`, `PERPS_TRADE_TRANSACTION`, `PERPS_WITHDRAWAL_TRANSACTION`, `PERPS_POSITION_CLOSE_TRANSACTION`, `PERPS_ORDER_CANCEL_TRANSACTION`, `PERPS_RISK_MANAGEMENT`, `PERPS_ERROR`. > - Add/standardize properties and values: `status`, `screen_type`, `setting_type`, expanded `interaction_type`; rename `PERPS_ERROR_ENCOUNTERED` → `PERPS_ERROR`. > - **Controller (PerpsController.ts)**: > - Switch trade/close tracking to single `*_TRANSACTION` events with `status` and `completion_duration`; include TP/SL when present. > - Add tracking for `editOrder` and `cancelOrder` (executed/failed) with durations and errors. > - **UI Updates**: > - Emit consolidated events across views (`PerpsMarketListView`, `PerpsMarketDetailsView`, `PerpsOrderView`, `PerpsClosePositionView`, `PerpsLeverageBottomSheet`, `PerpsOrderTypeBottomSheet`, `PerpsCandlePeriodBottomSheet`, `PerpsTutorialCarousel`, `PerpsWithdrawView`). > - Migrate to `PERPS_SCREEN_VIEWED` and `PERPS_UI_INTERACTION` with new `interaction_type` values; remove legacy events (e.g., balance modal viewed, funding input/review). > - Add input method tracking (`slider`, `keypad`, `percentage`, `max`) via new `InputMethod` and pass through tracking data. > - **Constants/Types**: > - Update `eventNames.ts` with new keys/values; add `InputMethod` and extend `TrackingData`. > - **Tests/Docs**: > - Adjust tests for renamed events; remove `PERPS_EVENTS_REFERENCE_v1.1.md`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5a9e18f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent f33cbe0 commit 6ca921e

File tree

22 files changed

+365
-754
lines changed

22 files changed

+365
-754
lines changed

app/components/UI/Perps/PERPS_EVENTS_REFERENCE_v1.1.md

Lines changed: 0 additions & 369 deletions
This file was deleted.

app/components/UI/Perps/Views/PerpsBalanceModal/PerpsBalanceModal.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useNavigation, type NavigationProp } from '@react-navigation/native';
2-
import React, { useCallback, useRef, useEffect } from 'react';
2+
import React, { useCallback, useRef } from 'react';
33
import { View } from 'react-native';
44
import { strings } from '../../../../../../locales/i18n';
55
import BottomSheet, {
@@ -22,12 +22,6 @@ import { usePerpsTrading, usePerpsNetworkManagement } from '../../hooks';
2222
import createStyles from './PerpsBalanceModal.styles';
2323
import { PerpsTabViewSelectorsIDs } from '../../../../../../e2e/selectors/Perps/Perps.selectors';
2424
import { useConfirmNavigation } from '../../../../Views/confirmations/hooks/useConfirmNavigation';
25-
import { usePerpsEventTracking } from '../../hooks/usePerpsEventTracking';
26-
import { MetaMetricsEvents } from '../../../../../core/Analytics';
27-
import {
28-
PerpsEventProperties,
29-
PerpsEventValues,
30-
} from '../../constants/eventNames';
3125

3226
interface PerpsBalanceModalProps {}
3327

@@ -38,14 +32,6 @@ const PerpsBalanceModal: React.FC<PerpsBalanceModalProps> = () => {
3832
const { ensureArbitrumNetworkExists } = usePerpsNetworkManagement();
3933
const bottomSheetRef = useRef<BottomSheetRef>(null);
4034
const { navigateToConfirmation } = useConfirmNavigation();
41-
const { track } = usePerpsEventTracking();
42-
43-
// Track balance modal viewed on mount
44-
useEffect(() => {
45-
track(MetaMetricsEvents.PERPS_BALANCE_MODAL_VIEWED, {
46-
[PerpsEventProperties.SOURCE]: PerpsEventValues.SOURCE.HOMESCREEN_TAB,
47-
});
48-
}, [track]);
4935

5036
const handleClose = useCallback(() => {
5137
navigation.goBack();

app/components/UI/Perps/Views/PerpsClosePositionView/PerpsClosePositionView.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,7 @@ describe('PerpsClosePositionView', () => {
18911891
feeDiscountPercentage: undefined,
18921892
metamaskFee: 0,
18931893
estimatedPoints: undefined,
1894+
inputMethod: 'default',
18941895
},
18951896
);
18961897
});

app/components/UI/Perps/Views/PerpsClosePositionView/PerpsClosePositionView.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Icon, {
3030
} from '../../../../../component-library/components/Icons/Icon';
3131
import { useTheme } from '../../../../../util/theme';
3232
import Keypad from '../../../../Base/Keypad';
33-
import type { OrderType, Position } from '../../controllers/types';
33+
import type { InputMethod, OrderType, Position } from '../../controllers/types';
3434
import type { PerpsNavigationParamList } from '../../types/navigation';
3535
import {
3636
useMinimumOrderAmount,
@@ -81,6 +81,7 @@ const PerpsClosePositionView: React.FC = () => {
8181
const { position } = route.params as { position: Position };
8282

8383
const hasTrackedCloseView = useRef(false);
84+
const inputMethodRef = useRef<InputMethod>('default');
8485
const { track } = usePerpsEventTracking();
8586

8687
const { showToast, PerpsToastOptions } = usePerpsToasts();
@@ -249,7 +250,9 @@ const PerpsClosePositionView: React.FC = () => {
249250
const unrealizedPnlPercent =
250251
initialMargin > 0 ? (pnl / initialMargin) * 100 : 0;
251252

252-
track(MetaMetricsEvents.PERPS_POSITION_CLOSE_SCREEN_VIEWED, {
253+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
254+
[PerpsEventProperties.SCREEN_TYPE]:
255+
PerpsEventValues.SCREEN_TYPE.POSITION_CLOSE,
253256
[PerpsEventProperties.ASSET]: position.coin,
254257
[PerpsEventProperties.DIRECTION]: isLong
255258
? PerpsEventValues.DIRECTION.LONG
@@ -294,7 +297,8 @@ const PerpsClosePositionView: React.FC = () => {
294297
? ((effectivePnL * (closePercentage / 100)) / initialMargin) * 100
295298
: 0;
296299

297-
track(MetaMetricsEvents.PERPS_POSITION_CLOSE_INITIATED, {
300+
track(MetaMetricsEvents.PERPS_POSITION_CLOSE_TRANSACTION, {
301+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.INITIATED,
298302
[PerpsEventProperties.ASSET]: position.coin,
299303
[PerpsEventProperties.DIRECTION]: isLong
300304
? PerpsEventValues.DIRECTION.LONG
@@ -314,7 +318,8 @@ const PerpsClosePositionView: React.FC = () => {
314318
});
315319

316320
// Track position close submitted
317-
track(MetaMetricsEvents.PERPS_POSITION_CLOSE_SUBMITTED, {
321+
track(MetaMetricsEvents.PERPS_POSITION_CLOSE_TRANSACTION, {
322+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.SUBMITTED,
318323
[PerpsEventProperties.ASSET]: position.coin,
319324
[PerpsEventProperties.ORDER_TYPE]: orderType,
320325
});
@@ -344,6 +349,7 @@ const PerpsClosePositionView: React.FC = () => {
344349
feeDiscountPercentage: feeResults.feeDiscountPercentage,
345350
metamaskFee: feeResults.metamaskFee,
346351
estimatedPoints: rewardsState.estimatedPoints,
352+
inputMethod: inputMethodRef.current,
347353
},
348354
);
349355
};
@@ -354,6 +360,7 @@ const PerpsClosePositionView: React.FC = () => {
354360

355361
const handleKeypadChange = useCallback(
356362
({ value }: { value: string; valueAsNumber: number }) => {
363+
inputMethodRef.current = 'keypad';
357364
const previousValue = closeAmountUSDString;
358365
// Special handling for decimal point deletion
359366
// If previous value had a decimal and new value is the same, force remove the decimal
@@ -426,6 +433,7 @@ const PerpsClosePositionView: React.FC = () => {
426433
);
427434

428435
const handlePercentagePress = (percentage: number) => {
436+
inputMethodRef.current = 'percentage';
429437
const newPercentage = percentage * 100;
430438
setClosePercentage(newPercentage);
431439

@@ -435,6 +443,7 @@ const PerpsClosePositionView: React.FC = () => {
435443
};
436444

437445
const handleMaxPress = () => {
446+
inputMethodRef.current = 'max';
438447
setClosePercentage(100);
439448

440449
// Update USD input to match calculated value for keypad display consistency
@@ -448,6 +457,7 @@ const PerpsClosePositionView: React.FC = () => {
448457
};
449458

450459
const handleSliderChange = (value: number) => {
460+
inputMethodRef.current = 'slider';
451461
setClosePercentage(value);
452462
};
453463

app/components/UI/Perps/Views/PerpsMarketDetailsView/PerpsMarketDetailsView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ const PerpsMarketDetailsView: React.FC<PerpsMarketDetailsViewProps> = () => {
237237
endMeasure(PerpsMeasurementName.ASSET_SCREEN_LOADED);
238238

239239
// Track asset screen viewed event - only once
240-
track(MetaMetricsEvents.PERPS_ASSET_SCREEN_VIEWED, {
240+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
241+
[PerpsEventProperties.SCREEN_TYPE]:
242+
PerpsEventValues.SCREEN_TYPE.ASSET_DETAILS,
241243
[PerpsEventProperties.ASSET]: market.symbol,
242244
[PerpsEventProperties.SOURCE]: PerpsEventValues.SOURCE.PERP_MARKETS,
243245
[PerpsEventProperties.OPEN_POSITION]: !!existingPosition,
@@ -267,10 +269,10 @@ const PerpsMarketDetailsView: React.FC<PerpsMarketDetailsViewProps> = () => {
267269
setSelectedCandlePeriod(newPeriod);
268270

269271
// Track chart interaction
270-
track(MetaMetricsEvents.PERPS_CHART_INTERACTION, {
272+
track(MetaMetricsEvents.PERPS_UI_INTERACTION, {
271273
[PerpsEventProperties.ASSET]: market?.symbol || '',
272274
[PerpsEventProperties.INTERACTION_TYPE]:
273-
PerpsEventValues.INTERACTION_TYPE.CANDLE_PERIOD_CHANGE,
275+
PerpsEventValues.INTERACTION_TYPE.CANDLE_PERIOD_CHANGED,
274276
[PerpsEventProperties.CANDLE_PERIOD]: newPeriod,
275277
});
276278

app/components/UI/Perps/Views/PerpsMarketListView/PerpsMarketListView.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ const PerpsMarketListView = ({
207207
setSearchQuery('');
208208
} else {
209209
// Track search bar clicked event
210-
track(MetaMetricsEvents.PERPS_ASSET_SEARCH_BAR_CLICKED, {});
210+
track(MetaMetricsEvents.PERPS_UI_INTERACTION, {
211+
[PerpsEventProperties.INTERACTION_TYPE]:
212+
PerpsEventValues.INTERACTION_TYPE.SEARCH_CLICKED,
213+
});
211214
}
212215
};
213216

@@ -233,7 +236,9 @@ const PerpsMarketListView = ({
233236
// Track markets screen viewed event - only once when data is loaded
234237
if (markets.length > 0 && !hasTrackedMarketsView.current) {
235238
// Track event
236-
track(MetaMetricsEvents.PERPS_MARKETS_VIEWED, {
239+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
240+
[PerpsEventProperties.SCREEN_TYPE]:
241+
PerpsEventValues.SCREEN_TYPE.MARKETS,
237242
[PerpsEventProperties.SOURCE]:
238243
PerpsEventValues.SOURCE.MAIN_ACTION_BUTTON,
239244
});

app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ jest.mock('../../../../../components/hooks/useMetrics', () => ({
340340
PERPS_ORDER_TYPE_VIEWED: 'PERPS_ORDER_TYPE_VIEWED',
341341
PERPS_TRADE_TRANSACTION_INITIATED: 'PERPS_TRADE_TRANSACTION_INITIATED',
342342
PERPS_TRADE_TRANSACTION_SUBMITTED: 'PERPS_TRADE_TRANSACTION_SUBMITTED',
343-
PERPS_ERROR_ENCOUNTERED: 'PERPS_ERROR_ENCOUNTERED',
343+
PERPS_ERROR: 'PERPS_ERROR',
344344
},
345345
}));
346346

app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
usePerpsOrderContext,
7070
} from '../../contexts/PerpsOrderContext';
7171
import type {
72+
InputMethod,
7273
OrderParams,
7374
OrderType,
7475
PerpsNavigationParamList,
@@ -149,6 +150,7 @@ const PerpsOrderViewContentBase: React.FC = () => {
149150
const isSubmittingRef = useRef(false);
150151
const hasShownSubmittedToastRef = useRef(false);
151152
const orderStartTimeRef = useRef<number>(0);
153+
const inputMethodRef = useRef<InputMethod>('default');
152154

153155
const { account } = usePerpsLiveAccount();
154156

@@ -279,14 +281,16 @@ const PerpsOrderViewContentBase: React.FC = () => {
279281
if (!hasTrackedTradingView.current) {
280282
const eventProps = {
281283
[PerpsEventProperties.TIMESTAMP]: Date.now(),
284+
[PerpsEventProperties.SCREEN_TYPE]:
285+
PerpsEventValues.SCREEN_TYPE.TRADING,
282286
[PerpsEventProperties.ASSET]: orderForm.asset,
283287
[PerpsEventProperties.DIRECTION]:
284288
orderForm.direction === 'long'
285289
? PerpsEventValues.DIRECTION.LONG
286290
: PerpsEventValues.DIRECTION.SHORT,
287291
};
288292

289-
track(MetaMetricsEvents.PERPS_TRADING_SCREEN_VIEWED, eventProps);
293+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, eventProps);
290294

291295
hasTrackedTradingView.current = true;
292296
}
@@ -327,7 +331,9 @@ const PerpsOrderViewContentBase: React.FC = () => {
327331
parseFloat(orderForm.amount) > 0 &&
328332
!hasTrackedOrderTypeView.current
329333
) {
330-
track(MetaMetricsEvents.PERPS_ORDER_TYPE_VIEWED, {
334+
track(MetaMetricsEvents.PERPS_UI_INTERACTION, {
335+
[PerpsEventProperties.INTERACTION_TYPE]:
336+
PerpsEventValues.INTERACTION_TYPE.ORDER_TYPE_VIEWED,
331337
[PerpsEventProperties.ASSET]: orderForm.asset,
332338
[PerpsEventProperties.DIRECTION]:
333339
orderForm.direction === 'long'
@@ -607,6 +613,7 @@ const PerpsOrderViewContentBase: React.FC = () => {
607613

608614
const handleKeypadChange = useCallback(
609615
({ value }: { value: string; valueAsNumber: number }) => {
616+
inputMethodRef.current = 'keypad';
610617
// Enforce 9-digit limit (ignoring non-digits like separators)
611618
const digitCount = (value.match(/\d/g) || []).length;
612619
if (digitCount > 9) {
@@ -618,10 +625,12 @@ const PerpsOrderViewContentBase: React.FC = () => {
618625
);
619626

620627
const handlePercentagePress = (percentage: number) => {
628+
inputMethodRef.current = 'percentage';
621629
handlePercentageAmount(percentage);
622630
};
623631

624632
const handleMaxPress = () => {
633+
inputMethodRef.current = 'max';
625634
handleMaxAmount();
626635
};
627636

@@ -670,7 +679,7 @@ const PerpsOrderViewContentBase: React.FC = () => {
670679
);
671680

672681
// Track validation failure as error encountered
673-
track(MetaMetricsEvents.PERPS_ERROR_ENCOUNTERED, {
682+
track(MetaMetricsEvents.PERPS_ERROR, {
674683
[PerpsEventProperties.ERROR_TYPE]:
675684
PerpsEventValues.ERROR_TYPE.VALIDATION,
676685
[PerpsEventProperties.ERROR_MESSAGE]: firstError,
@@ -720,6 +729,7 @@ const PerpsOrderViewContentBase: React.FC = () => {
720729
estimatedPoints: feeResults.estimatedPoints
721730
? Number(feeResults.estimatedPoints)
722731
: undefined,
732+
inputMethod: inputMethodRef.current,
723733
},
724734
};
725735

@@ -855,7 +865,10 @@ const PerpsOrderViewContentBase: React.FC = () => {
855865
<View style={styles.sliderSection}>
856866
<PerpsSlider
857867
value={parseFloat(orderForm.amount || '0')}
858-
onValueChange={(value) => setAmount(Math.floor(value).toString())}
868+
onValueChange={(value) => {
869+
inputMethodRef.current = 'slider';
870+
setAmount(Math.floor(value).toString());
871+
}}
859872
minimumValue={0}
860873
maximumValue={amountTimesLeverage}
861874
step={1}
@@ -1257,7 +1270,13 @@ const PerpsOrderViewContentBase: React.FC = () => {
12571270
: PerpsEventValues.INPUT_METHOD.PRESET;
12581271
}
12591272

1260-
track(MetaMetricsEvents.PERPS_LEVERAGE_CHANGED, eventProperties);
1273+
track(MetaMetricsEvents.PERPS_UI_INTERACTION, {
1274+
...eventProperties,
1275+
[PerpsEventProperties.INTERACTION_TYPE]:
1276+
PerpsEventValues.INTERACTION_TYPE.SETTING_CHANGED,
1277+
[PerpsEventProperties.SETTING_TYPE]:
1278+
PerpsEventValues.SETTING_TYPE.LEVERAGE,
1279+
});
12611280
}}
12621281
leverage={orderForm.leverage}
12631282
minLeverage={1}

app/components/UI/Perps/Views/PerpsTabView/PerpsTabView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ const PerpsTabView: React.FC<PerpsTabViewProps> = () => {
9393
endMeasure(PerpsMeasurementName.POSITION_DATA_LOADED_PERP_TAB);
9494

9595
// Track homescreen tab viewed event with exact property names from requirements
96-
track(MetaMetricsEvents.PERPS_HOMESCREEN_TAB_VIEWED, {
96+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
97+
[PerpsEventProperties.SCREEN_TYPE]:
98+
PerpsEventValues.SCREEN_TYPE.HOMESCREEN,
9799
[PerpsEventProperties.OPEN_POSITION]: positions.map((p) => ({
98100
[PerpsEventProperties.ASSET]: p.coin,
99101
[PerpsEventProperties.LEVERAGE]: p.leverage.value,

app/components/UI/Perps/Views/PerpsWithdrawView/PerpsWithdrawView.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ import Button, {
7171
ButtonVariants,
7272
ButtonWidthTypes,
7373
} from '../../../../../component-library/components/Buttons/Button';
74+
import {
75+
PerpsEventProperties,
76+
PerpsEventValues,
77+
} from '../../constants/eventNames';
7478

7579
// Constants
7680
const MAX_INPUT_LENGTH = 20;
@@ -155,7 +159,10 @@ const PerpsWithdrawView: React.FC = () => {
155159
useEffect(() => {
156160
if (!hasTrackedWithdrawView.current) {
157161
endMeasure(PerpsMeasurementName.WITHDRAWAL_SCREEN_LOADED);
158-
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_INPUT_VIEWED);
162+
trackEvent(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
163+
[PerpsEventProperties.SCREEN_TYPE]:
164+
PerpsEventValues.SCREEN_TYPE.WITHDRAWAL,
165+
});
159166
hasTrackedWithdrawView.current = true;
160167
}
161168
}, [trackEvent, endMeasure]);
@@ -239,7 +246,8 @@ const PerpsWithdrawView: React.FC = () => {
239246
if (!hasValidInputs || isSubmittingTx) return;
240247

241248
setIsSubmittingTx(true);
242-
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_INITIATED, {
249+
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_TRANSACTION, {
250+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.INITIATED,
243251
amount: withdrawAmountDetailed,
244252
});
245253

@@ -296,7 +304,8 @@ const PerpsWithdrawView: React.FC = () => {
296304
);
297305

298306
// Track withdrawal completed with duration
299-
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_COMPLETED, {
307+
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_TRANSACTION, {
308+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.COMPLETED,
300309
amount: withdrawAmountDetailed,
301310
completionDuration: confirmationDuration,
302311
});
@@ -309,7 +318,8 @@ const PerpsWithdrawView: React.FC = () => {
309318
);
310319

311320
// Track withdrawal failed
312-
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_FAILED, {
321+
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_TRANSACTION, {
322+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.FAILED,
313323
errorMessage: result.error || 'Unknown error',
314324
});
315325

@@ -345,7 +355,8 @@ const PerpsWithdrawView: React.FC = () => {
345355
);
346356

347357
// Track withdrawal failed
348-
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_FAILED, {
358+
trackEvent(MetaMetricsEvents.PERPS_WITHDRAWAL_TRANSACTION, {
359+
[PerpsEventProperties.STATUS]: PerpsEventValues.STATUS.FAILED,
349360
errorMessage: error instanceof Error ? error.message : 'Unknown error',
350361
});
351362

0 commit comments

Comments
 (0)