Skip to content

Commit a484891

Browse files
authored
improve overlay, portfolio, and marketplace metrics (#1173)
1 parent 7e9a38b commit a484891

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/backend/metrics/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ export interface ClientUpdateDownloaded {
416416
sensitiveProperties?: never
417417
}
418418

419+
export interface AccountDropdownPortfolioClicked {
420+
event: 'Portfolio Clicked in Account Dropdown'
421+
properties?: never
422+
sensitiveProperties?: never
423+
}
424+
419425
export type PossibleMetricPayloads =
420426
| MetricsOptIn
421427
| MetricsOptOut
@@ -458,5 +464,6 @@ export type PossibleMetricPayloads =
458464
| PatchingSuccess
459465
| PatchingFailed
460466
| PatchingTooSlow
467+
| AccountDropdownPortfolioClicked
461468

462469
export type PossibleMetricEventNames = PossibleMetricPayloads['event']

src/frontend/OverlayManager/Overlay/NavBarOverlayWrapper/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import styles from './index.module.scss'
33
import {
44
NavBarOverlay,
@@ -15,12 +15,22 @@ import { useFlags } from 'launchdarkly-react-client-sdk'
1515

1616
export function NavBarOverlayWrapper({ appName, runner }: BrowserGameProps) {
1717
const location = useLocation()
18-
const { pathname } = location
18+
const { pathname, search } = location
1919
const [collapsed, setCollapsed] = useState(false)
2020
const { t } = useTranslation()
2121
const comingSoonText = t('overlay.comingSoon', 'Coming Soon')
2222
const flags = useFlags()
2323

24+
const searchParams = new URLSearchParams(search)
25+
const urlQueryParam = searchParams.get('url')
26+
27+
useEffect(() => {
28+
window.api.trackScreen('Overlay Page', {
29+
pathname: pathname === '/' ? '/quests' : pathname,
30+
url: urlQueryParam ?? undefined
31+
})
32+
}, [pathname])
33+
2434
const linkItems: NavBarOverlayProps['linkItems'] = [
2535
<NavItem
2636
title={'Quests'}

src/frontend/components/UI/AccountDropdown/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ const WalletDropdown: React.FC = observer(() => {
114114
? 'topElementWalletDropdown'
115115
: undefined
116116
}
117+
onClick={async () =>
118+
window.api.trackEvent({
119+
event: 'Portfolio Clicked in Account Dropdown'
120+
})
121+
}
117122
>
118123
<div className={`body ${styles.itemContents}`}>
119124
{t('hyperplay.viewPortfolio', `View portfolio`)}

src/frontend/screens/MetaMaskPortfolio/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
import React, { useRef } from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import MetaMaskPortfolioStyles from './index.module.scss'
33
import { useParams } from 'react-router-dom'
44
import { getMetaMaskPortfolioPageUrl } from 'common/constants'
5+
import { DidNavigateInPageEvent, WebviewTag } from 'electron'
56

67
const MetaMaskPortfolio = function () {
78
const trueAsStr = 'true' as unknown as boolean | undefined
89
const { page = '' } = useParams() as { page: string }
9-
const webviewRef = useRef<HTMLWebViewElement>(null)
10+
const webviewRef = useRef<WebviewTag>(null)
11+
12+
useEffect(() => {
13+
const handleNavigation = (e: DidNavigateInPageEvent) => {
14+
const url = new URL(e.url)
15+
window.api.trackScreen('MetaMask Portfolio', {
16+
pathname: url.pathname
17+
})
18+
}
19+
webviewRef.current?.addEventListener(
20+
'did-navigate-in-page',
21+
handleNavigation
22+
)
23+
return () => {
24+
webviewRef.current?.removeEventListener(
25+
'did-navigate-in-page',
26+
handleNavigation
27+
)
28+
}
29+
}, [webviewRef])
1030

1131
return (
1232
<>

0 commit comments

Comments
 (0)