-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analytics: track Buy Crypto button (#3029)
* Analytics: track Buy Crypto button * Refactor * Track page path
- Loading branch information
Showing
5 changed files
with
67 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { usePathname, useSearchParams } from 'next/navigation' | ||
import Link, { type LinkProps } from 'next/link' | ||
import { Button } from '@mui/material' | ||
import AddIcon from '@mui/icons-material/Add' | ||
import { SafeAppsTag } from '@/config/constants' | ||
import { AppRoutes } from '@/config/routes' | ||
import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' | ||
import madProps from '@/utils/mad-props' | ||
import { useMemo } from 'react' | ||
import Track from '../Track' | ||
import { OVERVIEW_EVENTS } from '@/services/analytics' | ||
|
||
const useOnrampAppUrl = (): string | undefined => { | ||
const [onrampApps] = useRemoteSafeApps(SafeAppsTag.ONRAMP) | ||
return onrampApps?.[0]?.url | ||
} | ||
|
||
const useBuyCryptoHref = (): LinkProps['href'] | undefined => { | ||
const query = useSearchParams() | ||
const safe = query.get('safe') | ||
const appUrl = useOnrampAppUrl() | ||
|
||
return useMemo(() => { | ||
if (!safe || !appUrl) return undefined | ||
return { pathname: AppRoutes.apps.open, query: { safe, appUrl } } | ||
}, [safe, appUrl]) | ||
} | ||
|
||
const buttonStyles = { | ||
minHeight: '40px', | ||
} | ||
|
||
const _BuyCryptoButton = ({ href, pagePath }: { href?: LinkProps['href']; pagePath: string }) => { | ||
if (!href) return null | ||
|
||
return ( | ||
<Track {...OVERVIEW_EVENTS.BUY_CRYPTO_BUTTON} label={pagePath}> | ||
<Link href={href} passHref> | ||
<Button variant="contained" size="small" sx={buttonStyles} fullWidth startIcon={<AddIcon />}> | ||
Buy crypto | ||
</Button> | ||
</Link> | ||
</Track> | ||
) | ||
} | ||
|
||
const BuyCryproButton = madProps(_BuyCryptoButton, { | ||
href: useBuyCryptoHref, | ||
pagePath: usePathname, | ||
}) | ||
|
||
export default BuyCryproButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters