Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(analytics): consistent earn events #6115

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { ErrorMessages } from 'src/app/ErrorMessages'
import { AddAssetsActionType } from 'src/components/AddAssetsBottomSheet'
import { TokenPickerOrigin } from 'src/components/TokenBottomSheet'
import { DappSection } from 'src/dapps/types'
import { EarnDepositMode, BeforeDepositActionName, SerializableRewardsInfo } from 'src/earn/types'
import { BeforeDepositActionName, EarnDepositMode, SerializableRewardsInfo } from 'src/earn/types'
import { ProviderSelectionAnalyticsData } from 'src/fiatExchanges/types'
import { CICOFlow, FiatExchangeFlow, PaymentMethod } from 'src/fiatExchanges/utils'
import { HomeActionName, NotificationBannerCTATypes, NotificationType } from 'src/home/types'
Expand Down Expand Up @@ -1544,7 +1544,7 @@ interface PointsEventsProperties {
[PointsEvents.points_screen_disclaimer_press]: undefined
}

interface EarnCommonProperties {
export interface EarnCommonProperties {
providerId: string
poolId: string
networkId: NetworkId
Expand Down Expand Up @@ -1585,7 +1585,8 @@ interface EarnEventsProperties {
[EarnEvents.earn_entrypoint_press]: undefined
[EarnEvents.earn_before_deposit_action_press]: {
action: BeforeDepositActionName
} & TokenProperties
} & TokenProperties &
EarnCommonProperties
[EarnEvents.earn_deposit_provider_info_press]: EarnDepositProperties
[EarnEvents.earn_deposit_terms_and_conditions_press]: EarnDepositProperties
[EarnEvents.earn_deposit_complete]: EarnDepositProperties
Expand All @@ -1612,7 +1613,7 @@ interface EarnEventsProperties {
tokenAmount: string
} & EarnCommonProperties
[EarnEvents.earn_deposit_more_press]: EarnCommonProperties
[EarnEvents.earn_deposit_add_gas_press]: { gasTokenId: string }
[EarnEvents.earn_deposit_add_gas_press]: EarnCommonProperties & { gasTokenId: string }
[EarnEvents.earn_feed_item_select]: {
origin: 'EarnDeposit' | 'EarnWithdraw' | 'EarnClaimReward' | 'EarnSwapDeposit'
}
Expand All @@ -1623,7 +1624,7 @@ interface EarnEventsProperties {
error: string
}
[EarnEvents.earn_withdraw_submit_cancel]: EarnWithdrawProperties
[EarnEvents.earn_withdraw_add_gas_press]: { gasTokenId: string }
[EarnEvents.earn_withdraw_add_gas_press]: EarnCommonProperties & { gasTokenId: string }
[EarnEvents.earn_info_learn_press]: undefined
[EarnEvents.earn_info_earn_press]: undefined
[EarnEvents.earn_active_pools_card_press]: undefined
Expand Down
54 changes: 44 additions & 10 deletions src/earn/BeforeDepositBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View } from 'react-native'
import AppAnalytics from 'src/analytics/AppAnalytics'
import { EarnEvents } from 'src/analytics/Events'
import { EarnCommonProperties, TokenProperties } from 'src/analytics/Properties'
import BottomSheet, { BottomSheetModalRefType } from 'src/components/BottomSheet'
import Touchable from 'src/components/Touchable'
import { BeforeDepositAction, BeforeDepositActionName } from 'src/earn/types'
Expand Down Expand Up @@ -47,9 +48,11 @@ function ActionCard({ action }: { action: BeforeDepositAction }) {
function AddAction({
token,
forwardedRef,
analyticsProps,
}: {
token: TokenBalance
forwardedRef: React.RefObject<BottomSheetModalRefType>
analyticsProps: EarnCommonProperties & TokenProperties
}) {
const { t } = useTranslation()

Expand All @@ -64,7 +67,7 @@ function AddAction({
onPress: () => {
AppAnalytics.track(EarnEvents.earn_before_deposit_action_press, {
action: BeforeDepositActionName.Add,
...getTokenAnalyticsProps(token),
...analyticsProps,
})

navigate(Screens.FiatExchangeAmount, {
Expand All @@ -82,10 +85,12 @@ function TransferAction({
token,
exchanges,
forwardedRef,
analyticsProps,
}: {
token: TokenBalance
exchanges: ExternalExchangeProvider[]
forwardedRef: React.RefObject<BottomSheetModalRefType>
analyticsProps: EarnCommonProperties & TokenProperties
}) {
const { t } = useTranslation()

Expand All @@ -100,7 +105,7 @@ function TransferAction({
onPress: () => {
AppAnalytics.track(EarnEvents.earn_before_deposit_action_press, {
action: BeforeDepositActionName.Transfer,
...getTokenAnalyticsProps(token),
...analyticsProps,
})

navigate(Screens.ExchangeQR, { flow: CICOFlow.CashIn, exchanges })
Expand All @@ -113,9 +118,11 @@ function TransferAction({
function CrossChainSwapAction({
token,
forwardedRef,
analyticsProps,
}: {
token: TokenBalance
forwardedRef: React.RefObject<BottomSheetModalRefType>
analyticsProps: EarnCommonProperties & TokenProperties
}) {
const { t } = useTranslation()

Expand All @@ -129,7 +136,7 @@ function CrossChainSwapAction({
onPress: () => {
AppAnalytics.track(EarnEvents.earn_before_deposit_action_press, {
action: BeforeDepositActionName.CrossChainSwap,
...getTokenAnalyticsProps(token),
...analyticsProps,
})

navigate(Screens.SwapScreenWithBack, { toTokenId: token.tokenId })
Expand All @@ -142,9 +149,11 @@ function CrossChainSwapAction({
function SwapAction({
token,
forwardedRef,
analyticsProps,
}: {
token: TokenBalance
forwardedRef: React.RefObject<BottomSheetModalRefType>
analyticsProps: EarnCommonProperties & TokenProperties
}) {
const { t } = useTranslation()

Expand All @@ -159,7 +168,7 @@ function SwapAction({
onPress: () => {
AppAnalytics.track(EarnEvents.earn_before_deposit_action_press, {
action: BeforeDepositActionName.Swap,
...getTokenAnalyticsProps(token),
...analyticsProps,
})

navigate(Screens.SwapScreenWithBack, { toTokenId: token.tokenId })
Expand All @@ -173,10 +182,12 @@ function SwapAndDepositAction({
token,
pool,
forwardedRef,
analyticsProps,
}: {
token: TokenBalance
pool: EarnPosition
forwardedRef: React.RefObject<BottomSheetModalRefType>
analyticsProps: EarnCommonProperties & TokenProperties
}) {
const { t } = useTranslation()

Expand All @@ -191,7 +202,7 @@ function SwapAndDepositAction({
onPress: () => {
AppAnalytics.track(EarnEvents.earn_before_deposit_action_press, {
action: BeforeDepositActionName.SwapAndDeposit,
...getTokenAnalyticsProps(token),
...analyticsProps,
})

navigate(Screens.EarnEnterAmount, { pool, mode: 'swap-deposit' })
Expand Down Expand Up @@ -233,6 +244,13 @@ export default function BeforeDepositBottomSheet({
})
: t('earnFlow.beforeDepositBottomSheet.beforeYouCanDepositTitle')

const analyticsProps = {
...getTokenAnalyticsProps(token),
poolId: pool.positionId,
providerId: pool.appId,
depositTokenId: pool.dataProps.depositTokenId,
}

return (
<BottomSheet
forwardedRef={forwardedRef}
Expand All @@ -248,23 +266,39 @@ export default function BeforeDepositBottomSheet({
<View style={styles.actionsContainer}>
{canSwapDeposit && (
<>
<SwapAndDepositAction token={token} pool={pool} forwardedRef={forwardedRef} />
<SwapAndDepositAction
token={token}
pool={pool}
forwardedRef={forwardedRef}
analyticsProps={analyticsProps}
/>
<Text style={styles.actionDetails}>
{t('earnFlow.beforeDepositBottomSheet.crossChainAlternativeDescription', {
tokenNetwork: NETWORK_NAMES[token.networkId],
})}
</Text>
{hasTokensOnOtherNetworks && (
<CrossChainSwapAction token={token} forwardedRef={forwardedRef} />
<CrossChainSwapAction
token={token}
forwardedRef={forwardedRef}
analyticsProps={analyticsProps}
/>
)}
</>
)}
{!canSwapDeposit && (hasTokensOnSameNetwork || hasTokensOnOtherNetworks) && (
<SwapAction token={token} forwardedRef={forwardedRef} />
<SwapAction token={token} forwardedRef={forwardedRef} analyticsProps={analyticsProps} />
)}
{canAdd && (
<AddAction token={token} forwardedRef={forwardedRef} analyticsProps={analyticsProps} />
)}
{canAdd && <AddAction token={token} forwardedRef={forwardedRef} />}
{!canSwapDeposit && (
<TransferAction token={token} exchanges={exchanges} forwardedRef={forwardedRef} />
<TransferAction
token={token}
exchanges={exchanges}
forwardedRef={forwardedRef}
analyticsProps={analyticsProps}
/>
)}
</View>
</BottomSheet>
Expand Down
4 changes: 4 additions & 0 deletions src/earn/EarnCollectScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ describe('EarnCollectScreen', () => {
})
expect(AppAnalytics.track).toBeCalledWith(EarnEvents.earn_withdraw_add_gas_press, {
gasTokenId: mockArbEthTokenId,
networkId: NetworkId['arbitrum-sepolia'],
poolId: mockEarnPositions[0].positionId,
providerId: mockEarnPositions[0].appId,
depositTokenId: mockArbUsdcTokenId,
})
})

Expand Down
4 changes: 4 additions & 0 deletions src/earn/EarnCollectScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export default function EarnCollectScreen({ route }: Props) {
onPressCta={() => {
AppAnalytics.track(EarnEvents.earn_withdraw_add_gas_press, {
gasTokenId: feeCurrencies[0].tokenId,
depositTokenId: pool.dataProps.depositTokenId,
networkId: pool.networkId,
providerId: pool.appId,
poolId: pool.positionId,
})
navigate(Screens.FiatExchangeAmount, {
tokenId: feeCurrencies[0].tokenId,
Expand Down
4 changes: 4 additions & 0 deletions src/earn/EarnEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ describe('EarnEnterAmount', () => {
)
expect(AppAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_deposit_add_gas_press, {
gasTokenId: mockArbEthTokenId,
networkId: NetworkId['arbitrum-sepolia'],
poolId: mockEarnPositions[0].positionId,
providerId: mockEarnPositions[0].appId,
depositTokenId: mockArbUsdcTokenId,
})
expect(navigate).toHaveBeenCalledWith(Screens.FiatExchangeAmount, {
tokenId: mockArbEthTokenId,
Expand Down
4 changes: 4 additions & 0 deletions src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ function EarnEnterAmount({ route }: Props) {
onPressCta={() => {
AppAnalytics.track(EarnEvents.earn_deposit_add_gas_press, {
gasTokenId: feeCurrencies[0].tokenId,
depositTokenId: pool.dataProps.depositTokenId,
networkId: pool.networkId,
providerId: pool.appId,
poolId: pool.positionId,
})
navigate(Screens.FiatExchangeAmount, {
tokenId: prepareTransactionsResult.feeCurrencies[0].tokenId,
Expand Down