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

Analytics changes #6169

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
52 changes: 33 additions & 19 deletions src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {

const isBridge = swapsStore.getState().inputAsset?.mainnetAddress === swapsStore.getState().outputAsset?.mainnetAddress;
const isDegenModeEnabled = swapsStore.getState().degenMode;
const slippage = swapsStore.getState().slippage;
const isSwappingToPopularAsset = swapsStore.getState().outputAsset?.sectionId === 'popular';

const selectedGas = getSelectedGas(parameters.chainId);
Expand Down Expand Up @@ -244,7 +243,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
}

const gasFeeParamsBySpeed = getGasSettingsBySpeed(parameters.chainId);
const selectedGasSpeed = getSelectedGasSpeed(parameters.chainId);

let gasParams: TransactionGasParamAmounts | LegacyTransactionGasParamAmounts = {} as
| TransactionGasParamAmounts
Expand Down Expand Up @@ -282,18 +280,26 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
SwapInputController.quoteFetchingInterval.start();

analyticsV2.track(analyticsV2.event.swapsFailed, {
createdAt: Date.now(),
type,
parameters,
selectedGas,
selectedGasSpeed,
slippage,
bridge: isBridge,
errorMessage,
inputNativeValue: SwapInputController.inputValues.value.inputNativeValue,
outputNativeValue: SwapInputController.inputValues.value.outputNativeValue,
isBridge: isBridge,
inputAssetSymbol: internalSelectedInputAsset.value?.symbol || '',
inputAssetName: internalSelectedInputAsset.value?.name || '',
inputAssetAddress: internalSelectedInputAsset.value?.address as AddressOrEth,
inputAssetChainId: internalSelectedInputAsset.value?.chainId || ChainId.mainnet,
inputAssetAmount: parameters.quote.sellAmount as number,
outputAssetSymbol: internalSelectedOutputAsset.value?.symbol || '',
outputAssetName: internalSelectedOutputAsset.value?.name || '',
outputAssetAddress: internalSelectedOutputAsset.value?.address as AddressOrEth,
outputAssetChainId: internalSelectedOutputAsset.value?.chainId || ChainId.mainnet,
outputAssetAmount: parameters.quote.buyAmount as number,
mainnetAddress: (parameters.assetToBuy.chainId === ChainId.mainnet
? parameters.assetToBuy.address
: parameters.assetToSell.mainnetAddress) as AddressOrEth,
flashbots: parameters.flashbots ?? false,
tradeAmountUSD: parameters.quote.tradeAmountUSD,
degenMode: isDegenModeEnabled,
isSwappingToPopularAsset,
errorMessage,
});

if (errorMessage !== 'handled') {
Expand Down Expand Up @@ -333,15 +339,23 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
})(Routes.PROFILE_SCREEN, {});

analyticsV2.track(analyticsV2.event.swapsSubmitted, {
createdAt: Date.now(),
type,
parameters,
selectedGas,
selectedGasSpeed,
slippage,
bridge: isBridge,
inputNativeValue: SwapInputController.inputValues.value.inputNativeValue,
outputNativeValue: SwapInputController.inputValues.value.outputNativeValue,
isBridge: isBridge,
inputAssetSymbol: internalSelectedInputAsset.value?.symbol || '',
inputAssetName: internalSelectedInputAsset.value?.name || '',
inputAssetAddress: internalSelectedInputAsset.value?.address as AddressOrEth,
inputAssetChainId: internalSelectedInputAsset.value?.chainId || ChainId.mainnet,
inputAssetAmount: parameters.quote.sellAmount as number,
outputAssetSymbol: internalSelectedOutputAsset.value?.symbol || '',
outputAssetName: internalSelectedOutputAsset.value?.name || '',
outputAssetAddress: internalSelectedOutputAsset.value?.address as AddressOrEth,
outputAssetChainId: internalSelectedOutputAsset.value?.chainId || ChainId.mainnet,
outputAssetAmount: parameters.quote.buyAmount as number,
mainnetAddress: (parameters.assetToBuy.chainId === ChainId.mainnet
? parameters.assetToBuy.address
: parameters.assetToSell.mainnetAddress) as AddressOrEth,
flashbots: parameters.flashbots ?? false,
tradeAmountUSD: parameters.quote.tradeAmountUSD,
degenMode: isDegenModeEnabled,
isSwappingToPopularAsset,
});
Expand Down
33 changes: 24 additions & 9 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GasSettings } from '@/__swaps__/screens/Swap/hooks/useCustomGas';
import { ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets';
import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets';
import { ChainId, Network } from '@/chains/types';
import { GasSpeed } from '@/__swaps__/types/gas';
import { SwapAssetType } from '@/__swaps__/types/swap';
Expand Down Expand Up @@ -149,18 +149,26 @@ export const event = {

performanceTimeToSign: 'performance.time_to_sign',
performanceTimeToSignOperation: 'performance.time_to_sign.operation',

addFavoriteToken: 'add_favorite_token',
} as const;

type SwapEventParameters<T extends 'swap' | 'crosschainSwap'> = {
createdAt: number;
type: T;
bridge: boolean;
inputNativeValue: string | number;
outputNativeValue: string | number;
parameters: Omit<RapSwapActionParameters<T>, 'gasParams' | 'gasFeeParamsBySpeed' | 'selectedGasFee'>;
selectedGas: GasSettings;
selectedGasSpeed: GasSpeed;
slippage: string;
isBridge: boolean;
inputAssetSymbol: string;
inputAssetName: string;
inputAssetAddress: AddressOrEth;
inputAssetChainId: ChainId;
inputAssetAmount: number;
outputAssetSymbol: string;
outputAssetName: string;
outputAssetAddress: AddressOrEth;
outputAssetChainId: ChainId;
outputAssetAmount: number;
mainnetAddress: string;
flashbots: boolean;
tradeAmountUSD: number;
degenMode: boolean;
isSwappingToPopularAsset: boolean;
};
Expand Down Expand Up @@ -571,4 +579,11 @@ export type EventProperties = {
};

[event.performanceTimeToSignOperation]: AnyPerformanceLog;

[event.addFavoriteToken]: {
address: AddressOrEth;
chainId: ChainId;
name: string;
symbol: string;
};
};
8 changes: 8 additions & 0 deletions src/resources/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useQuery } from '@tanstack/react-query';
import { omit } from 'lodash';
import { externalTokenQueryKey, fetchExternalToken } from './assets/externalAssetsQuery';
import { chainsIdByName, chainsName } from '@/chains';
import { analyticsV2 } from '@/analytics';

export const favoritesQueryKey = createQueryKey('favorites', {}, { persisterVersion: 4 });

Expand Down Expand Up @@ -123,6 +124,13 @@ export async function toggleFavorite(address: string, chainId = ChainId.mainnet)
queryClient.setQueryData(favoritesQueryKey, omit(favorites, uniqueId));
} else {
const metadata = await fetchMetadata([lowercasedAddress], chainId);
analyticsV2.track(analyticsV2.event.addFavoriteToken, {
address: lowercasedAddress,
chainId,
name: metadata[uniqueId].name,
symbol: metadata[uniqueId].symbol,
});

queryClient.setQueryData(favoritesQueryKey, { ...favorites, ...metadata });
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/AddWalletSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const AddWalletSheet = () => {
};

const onPressWatch = () => {
analytics.track('Tapped "Add an existing wallet"');
analytics.track('Tapped "Watch an Ethereum Address"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to merge the new & old events together somehow & is that even possible?

Copy link
Contributor Author

@walmat walmat Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't believe so. I think this event was supposed to be what I changed it to. It's what one of the tickets was.

analyticsV2.track(analyticsV2.event.addWalletFlowStarted, {
isFirstWallet,
type: 'watch',
Expand Down
Loading