From 60f1ec1271ee1ff9f58d0ccf42e3c68e0e1fdfd8 Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Thu, 12 Dec 2024 12:09:23 -0500 Subject: [PATCH] feat: added visited-eth-overview-with-staked-positions event --- .../StakingBalance/StakingBalance.tsx | 33 ++++++++++++++++++- app/core/Analytics/MetaMetrics.events.ts | 4 +++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx b/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx index 1d41646bc3c..5814ada1fde 100644 --- a/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx +++ b/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import Badge, { BadgeVariant, } from '../../../../../component-library/components/Badges/Badge'; @@ -44,6 +44,7 @@ import useBalance from '../../hooks/useBalance'; import { NetworkBadgeSource } from '../../../AssetOverview/Balance/Balance'; import { selectChainId } from '../../../../../selectors/networkController'; import SkeletonPlaceholder from 'react-native-skeleton-placeholder'; +import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics'; export interface StakingBalanceProps { asset: TokenI; @@ -51,6 +52,12 @@ export interface StakingBalanceProps { const StakingBalanceContent = ({ asset }: StakingBalanceProps) => { const { styles } = useStyles(styleSheet, {}); + + const [ + hasSentViewingStakingRewardsMetric, + setHasSentViewingStakingRewardsMetric, + ] = useState(false); + const chainId = useSelector(selectChainId); const networkName = useSelector(selectNetworkName); @@ -58,6 +65,8 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => { const { isStakingSupportedChain } = useStakingChain(); + const { trackEvent, createEventBuilder } = useMetrics(); + const { pooledStakesData, exchangeRate, @@ -92,6 +101,28 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => { const hasClaimableEth = !!Number(claimableEth); + useEffect(() => { + if (hasStakedPositions && !hasSentViewingStakingRewardsMetric) { + trackEvent( + createEventBuilder( + MetaMetricsEvents.VISITED_ETH_OVERVIEW_WITH_STAKED_POSITIONS, + ) + .addProperties({ + selected_provider: 'consensys', + location: 'StakingBalance', + }) + .build(), + ); + + setHasSentViewingStakingRewardsMetric(true); + } + }, [ + createEventBuilder, + hasSentViewingStakingRewardsMetric, + hasStakedPositions, + trackEvent, + ]); + if (!isStakingSupportedChain) { return <>; } diff --git a/app/core/Analytics/MetaMetrics.events.ts b/app/core/Analytics/MetaMetrics.events.ts index 87b26a00eed..8610a0c4d9b 100644 --- a/app/core/Analytics/MetaMetrics.events.ts +++ b/app/core/Analytics/MetaMetrics.events.ts @@ -303,6 +303,7 @@ enum EVENT_NAME { UNSTAKE_TRANSACTION_FAILED = 'Unstake Transaction Failed', UNSTAKE_TRANSACTION_CONFIRMED = 'Unstake Transaction Confirmed', UNSTAKE_TRANSACTION_SUBMITTED = 'Unstake Transaction Submitted', + VISITED_ETH_OVERVIEW_WITH_STAKED_POSITIONS = 'Visited ETH Overview with Staked Positions', // Force Upgrade | Automatic Security Checks FORCE_UPGRADE_UPDATE_NEEDED_PROMPT_VIEWED = 'Force Upgrade Update Needed Prompt Viewed', @@ -986,6 +987,9 @@ const events = { UNSTAKE_TRANSACTION_SUBMITTED: generateOpt( EVENT_NAME.UNSTAKE_TRANSACTION_SUBMITTED, ), + VISITED_ETH_OVERVIEW_WITH_STAKED_POSITIONS: generateOpt( + EVENT_NAME.VISITED_ETH_OVERVIEW_WITH_STAKED_POSITIONS, + ), }; /**