Skip to content

Commit

Permalink
feat: add bridge analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrosario committed Aug 10, 2023
1 parent e7e5612 commit d825d95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/MintDialog/elements/useBridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { goerli, baseGoerli, mainnet, base } from 'viem/chains'
import * as OP from '@eth-optimism/sdk'
import { isProd } from '@/config/chain'
import { useAccount, useWalletClient } from 'wagmi'
import { useLogEvent } from '@/utils/useLogEvent'
import { events } from '@/utils/analytics'

const l1Chain = isProd ? mainnet : goerli
const l2Chain = isProd ? base : baseGoerli
Expand All @@ -23,11 +25,12 @@ export const useBridge = (amount: BigNumber) => {
const [l1TxHash, setL1TxHash] = useState('')
const [l2TxHash, setL2TxHash] = useState('')
const [bridgeState, setBridgeState] = useState(BridgeState.NOT_STARTED)
const {address} = useAccount()
const {data: walletClient} = useWalletClient()
const { address } = useAccount()
const { data: walletClient } = useWalletClient()
const logEvent = useLogEvent()

const messenger = useMemo(() => {
if (!walletClient) return;
if (!walletClient) return
const { account, chain, transport } = walletClient
const network = {
chainId: chain.id,
Expand Down Expand Up @@ -76,6 +79,7 @@ export const useBridge = (amount: BigNumber) => {
messageReceipt.transactionReceipt.transactionHash
)

logEvent?.(events.bridgeSuccess)
setBridgeState(BridgeState.BRIDGED)
} catch (e) {
// @ts-expect-error
Expand All @@ -91,7 +95,7 @@ export const useBridge = (amount: BigNumber) => {

const bridge = useCallback(
async () => {
if (!messenger) return;
if (!messenger) return
await depositETH(messenger)
}, // main
[depositETH, messenger]
Expand Down
8 changes: 8 additions & 0 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ export const events: Record<string, CCAEvent> = {
},
importance: AnalyticsEventImportance.high,
},
bridgeSuccess: {
eventName: 'bridge_success',
eventData: {
loggingId: '211fb8c6-cc70-40a9-8116-6afa6420bdd6',
componentType: ComponentType.page,
action: ActionType.change,
},
},
}

0 comments on commit d825d95

Please sign in to comment.