Skip to content

Commit

Permalink
Swaps Entry Point Analytics (#1757)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent 371111d commit 488460d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export const event = {
*/
settingsRainbowDefaultProviderEnabled:
'settings.rainbow_default_provider.enabled',
/**
* Called when a user enters the swaps flow
*/
swapOpened: 'swap.opened',
/**
* Called when the user completes a Swap/Bridge and submits the transaction.
* This includes cross-chain swaps, while `bridgeSubmitted` is instead called
Expand Down Expand Up @@ -755,6 +759,18 @@ export type EventProperties = {
[event.settingsRainbowDefaultProviderEnabled]: undefined;
[event.settingsFlashbotsDisabled]: undefined;
[event.settingsFlashbotsEnabled]: undefined;
[event.swapOpened]: {
/**
* Entrypoint of the swaps flow.
*/
entryPoint:
| 'commandk' // command k action
| 'home_header_swap_button' // Home header swap button
| 'home_shortcut_x_key' // 'X' key shortcut
| 'token_context_menu' // Token context menu
| 'token_details' // Token details
| 'token_details_shortcut_x_key'; // Token details 'X' key shortcut
};
[event.swapSubmitted]: {
/**
* Symbol of the input asset being swapped.
Expand Down
15 changes: 13 additions & 2 deletions src/entries/popup/components/CommandK/useCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { To } from 'react-router-dom';
import { Address } from 'viem';
import { useEnsName } from 'wagmi';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
import { useCurrentAddressStore, useFlashbotsEnabledStore } from '~/core/state';
Expand Down Expand Up @@ -733,6 +735,15 @@ export const useCommands = (
const isFullScreen = useIsFullScreen();
const navigate = useRainbowNavigate();
const navigateToSwaps = useNavigateToSwaps();

// Wrapped to add analytics
const wrappedNavigateToSwaps = React.useCallback(() => {
navigateToSwaps();
analytics.track(event.swapOpened, {
entryPoint: 'commandk',
});
}, [navigateToSwaps]);

const { isWatchingWallet } = useWallets();
const save = useSavedEnsNames.use.save();
const toggleHideNFTStore = useNftsStore.use.toggleHideNFT();
Expand Down Expand Up @@ -1019,7 +1030,7 @@ export const useCommands = (
() => ({
// PAGE: HOME
swap: {
action: navigateToSwaps,
action: wrappedNavigateToSwaps,
},
bridge: {
action: () => navigate(ROUTES.BRIDGE),
Expand Down Expand Up @@ -1415,7 +1426,7 @@ export const useCommands = (
},
}),
[
navigateToSwaps,
wrappedNavigateToSwaps,
isWatchingWallet,
ensName,
address,
Expand Down
7 changes: 6 additions & 1 deletion src/entries/popup/hooks/useHomeShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { useEnsName } from 'wagmi';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
import { useDappMetadata } from '~/core/resources/metadata/dapp';
Expand Down Expand Up @@ -159,11 +161,14 @@ export function useHomeShortcuts() {
navigate(ROUTES.SETTINGS);
break;
case shortcuts.home.GO_TO_SWAP.key:
navigateToSwaps();
analytics.track(event.swapOpened, {
entryPoint: 'home_shortcut_x_key',
});
trackShortcut({
key: shortcuts.home.GO_TO_SWAP.display,
type: 'home.goToSwap',
});
navigateToSwaps();
break;
case shortcuts.home.GO_TO_PROFILE.key:
if (!selectedToken && !isTokenDetailsPage) {
Expand Down
7 changes: 6 additions & 1 deletion src/entries/popup/hooks/useTokensShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback, useMemo } from 'react';
import { useLocation } from 'react-router';
import { Address } from 'viem';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import config from '~/core/firebase/remoteConfig';
import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
Expand Down Expand Up @@ -134,11 +136,14 @@ export function useTokensShortcuts() {
if (selectedToken && isHomeRoute) {
if (e.key === shortcuts.tokens.SWAP_ASSET.key) {
if (allowSwap) {
navigateToSwaps();
analytics.track(event.swapOpened, {
entryPoint: 'token_details_shortcut_x_key',
});
trackShortcut({
key: shortcuts.tokens.SWAP_ASSET.display,
type: 'tokens.goToSwap',
});
navigateToSwaps();
} else {
triggerAlert({ text: i18n.t('alert.coming_soon') });
// clear selected token
Expand Down
5 changes: 5 additions & 0 deletions src/entries/popup/pages/home/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { motion, useTransform } from 'framer-motion';
import * as React from 'react';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import config from '~/core/firebase/remoteConfig';
import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
Expand Down Expand Up @@ -228,6 +230,9 @@ function ActionButtonsSection() {
}
} else {
navigateToSwaps();
analytics.track(event.swapOpened, {
entryPoint: 'home_header_swap_button',
});
}
}}
tooltipHint={shortcuts.home.GO_TO_SWAP.display}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ReactNode, useCallback } from 'react';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import config from '~/core/firebase/remoteConfig';
import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
Expand Down Expand Up @@ -74,6 +76,9 @@ export function TokenContextMenu({ children, token }: TokenContextMenuProps) {
if (allowSwap) {
isNavigating = true;
navigateToSwaps();
analytics.track(event.swapOpened, {
entryPoint: 'token_context_menu',
});
} else {
triggerAlert({ text: i18n.t('alert.coming_soon') });
setSelectedToken(); // clear selected token
Expand Down
9 changes: 8 additions & 1 deletion src/entries/popup/pages/home/TokenDetails/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback, useEffect, useReducer } from 'react';
import { Navigate, To, useParams, useSearchParams } from 'react-router-dom';
import { Address } from 'viem';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import { i18n } from '~/core/languages';
import { ETH_ADDRESS } from '~/core/references';
import { shortcuts } from '~/core/references/shortcuts';
Expand Down Expand Up @@ -197,7 +199,12 @@ function SwapSend({
width="full"
color="accent"
symbol="arrow.triangle.swap"
onClick={() => selectTokenAndNavigate(ROUTES.SWAP)}
onClick={() => {
selectTokenAndNavigate(ROUTES.SWAP);
analytics.track(event.swapOpened, {
entryPoint: 'token_details',
});
}}
tabIndex={0}
>
{i18n.t('token_details.swap')}
Expand Down

0 comments on commit 488460d

Please sign in to comment.