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

[Multichain] fix: Add more analytics events for multichain [SW-165] #4311

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/components/common/NetworkSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { useRouter } from 'next/router'
import css from './styles.module.css'
import { useChainId } from '@/hooks/useChainId'
import { type ReactElement, useCallback, useMemo, useState } from 'react'
import { OVERVIEW_EVENTS, OVERVIEW_LABELS } from '@/services/analytics'
import { OVERVIEW_EVENTS, OVERVIEW_LABELS, trackEvent } from '@/services/analytics'

import { useAllSafesGrouped } from '@/components/welcome/MyAccounts/useAllSafesGrouped'
import useSafeAddress from '@/hooks/useSafeAddress'
Expand Down Expand Up @@ -327,12 +327,17 @@ const NetworkSelector = ({
const chain = chains.data.find((chain) => chain.chainId === chainId)
if (!chain) return null

const onSwitchNetwork = () => {
trackEvent({ ...OVERVIEW_EVENTS.SWITCH_NETWORK, label: chainId })
}

return (
<MenuItem
key={chainId}
value={chainId}
sx={{ '&:hover': { backgroundColor: isSelected ? 'transparent' : 'inherit' } }}
disableRipple={isSelected}
onClick={onSwitchNetwork}
>
<Link
href={getNetworkLink(router, safeAddress, chain.shortName)}
Expand All @@ -353,6 +358,7 @@ const NetworkSelector = ({

const handleOpen = () => {
setOpen(true)
offerSafeCreation && trackEvent({ ...OVERVIEW_EVENTS.EXPAND_MULTI_SAFE, label: OVERVIEW_LABELS.top_bar })
}

return configs.length ? (
Expand Down
7 changes: 6 additions & 1 deletion src/components/welcome/MyAccounts/SubAccountItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ListItemButton, Box, Typography, Chip, Skeleton } from '@mui/material'
import Link from 'next/link'
import SafeIcon from '@/components/common/SafeIcon'
import Track from '@/components/common/Track'
import { OVERVIEW_EVENTS, OVERVIEW_LABELS } from '@/services/analytics'
import { OVERVIEW_EVENTS, OVERVIEW_LABELS, trackEvent } from '@/services/analytics'
import { AppRoutes } from '@/config/routes'
import { useAppSelector } from '@/store'
import { selectChainById } from '@/store/chainsSlice'
Expand Down Expand Up @@ -55,11 +55,16 @@ const SubAccountItem = ({ onLinkClick, safeItem, safeOverview }: SubAccountItem)

const cfSafeSetup = extractCounterfactualSafeSetup(undeployedSafe, chain?.chainId)

const onSwitchSafe = () => {
trackEvent({ ...OVERVIEW_EVENTS.SWITCH_NETWORK, label: chainId })
Copy link
Member

Choose a reason for hiding this comment

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

I switch network the correct event here?
I could also switch to another Multichain Safe and therefore switch Safe and network or only switch to another Safe on the same network.

Maybe we should call it "choose Safe from sidebar" or something like that instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be fine here since its in the SubAccountItem so only emitted if the user switches between the same safe on a different network. I added this to match the network selector in the header which also allows switching between the same safe on different networks.

Copy link
Member

Choose a reason for hiding this comment

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

But I can open a SubAccountItem of a different Safe.
So for instance switch from Safe "0x00...01" on Gnosis Chain to Safe "0x00...02" on Polygon.

Also now its impossible to distinguish between switching networks in the sidebar or through the network selector.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! Maybe we should leave it out then since we already emit an Open Safe when a Safe is opened from the Sidebar.

}

return (
<ListItemButton
data-testid="safe-list-item"
selected={isCurrentSafe}
className={classnames(css.listItem, { [css.currentListItem]: isCurrentSafe }, css.subItem)}
onClick={onSwitchSafe}
>
<Track {...OVERVIEW_EVENTS.OPEN_SAFE} label={trackingLabel}>
<Link onClick={onLinkClick} href={href} className={css.safeSubLink}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ModalDialog from '@/components/common/ModalDialog'
import NetworkInput from '@/components/common/NetworkInput'
import ErrorMessage from '@/components/tx/ErrorMessage'
import { OVERVIEW_EVENTS, trackEvent } from '@/services/analytics'
import { CREATE_SAFE_CATEGORY, CREATE_SAFE_EVENTS, OVERVIEW_EVENTS, trackEvent } from '@/services/analytics'
import { showNotification } from '@/store/notificationsSlice'
import { Box, Button, CircularProgress, DialogActions, DialogContent, Stack, Typography } from '@mui/material'
import { FormProvider, useForm } from 'react-hook-form'
Expand Down Expand Up @@ -95,7 +95,7 @@ const ReplaySafeDialog = ({
return
}

trackEvent({ ...OVERVIEW_EVENTS.SUBMIT_ADD_NEW_NETWORK, label: selectedChain.chainName })
trackEvent({ ...OVERVIEW_EVENTS.SUBMIT_ADD_NEW_NETWORK, label: selectedChain.chainId })

// 2. Replay Safe creation and add it to the counterfactual Safes
replayCounterfactualSafeDeployment(
Expand All @@ -107,6 +107,9 @@ const ReplaySafeDialog = ({
PayMethod.PayLater,
)

trackEvent({ ...OVERVIEW_EVENTS.PROCEED_WITH_TX, label: 'counterfactual', category: CREATE_SAFE_CATEGORY })
trackEvent({ ...CREATE_SAFE_EVENTS.CREATED_SAFE, label: 'counterfactual' })

router.push({
query: {
safe: `${selectedChain.shortName}:${safeAddress}`,
Expand Down
Loading