Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
fc823380
Commit
fc823380
authored
May 11, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log page view events
parent
f361b61a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
4 deletions
+98
-4
getPageType.ts
lib/mixpanel/getPageType.ts
+47
-0
getTabName.ts
lib/mixpanel/getTabName.ts
+5
-0
index.ts
lib/mixpanel/index.ts
+7
-0
useInit.tsx
lib/mixpanel/useInit.tsx
+8
-1
useLogPageView.tsx
lib/mixpanel/useLogPageView.tsx
+27
-0
_app.tsx
pages/_app.tsx
+0
-3
Page.tsx
ui/shared/Page/Page.tsx
+4
-0
No files found.
lib/mixpanel/getPageType.ts
0 → 100644
View file @
fc823380
import
type
{
Route
}
from
'
nextjs-routes
'
;
const
PAGE_TYPE_DICT
:
Record
<
Route
[
'
pathname
'
],
string
>
=
{
'
/
'
:
'
Homepage
'
,
'
/txs
'
:
'
Transactions
'
,
'
/tx/[hash]
'
:
'
Transaction details
'
,
'
/blocks
'
:
'
Blocks
'
,
'
/block/[height]
'
:
'
Block details
'
,
'
/accounts
'
:
'
Top accounts
'
,
'
/address/[hash]
'
:
'
Address details
'
,
'
/verified-contracts
'
:
'
Verified contracts
'
,
'
/address/[hash]/contract_verification
'
:
'
Contract verification
'
,
'
/tokens
'
:
'
Tokens
'
,
'
/token/[hash]
'
:
'
Token details
'
,
'
/token/[hash]/instance/[id]
'
:
'
Token Instance
'
,
'
/apps
'
:
'
Apps
'
,
'
/apps/[id]
'
:
'
App
'
,
'
/stats
'
:
'
Stats
'
,
'
/api-docs
'
:
'
REST API
'
,
'
/graphiql
'
:
'
GraphQL
'
,
'
/search-results
'
:
'
Search results
'
,
'
/auth/profile
'
:
'
Profile
'
,
'
/account/watchlist
'
:
'
Watchlist
'
,
'
/account/api_key
'
:
'
API keys
'
,
'
/account/custom_abi
'
:
'
Custom ABI
'
,
'
/account/public_tags_request
'
:
'
Public tags
'
,
'
/account/tag_address
'
:
'
Private tags
'
,
'
/withdrawals
'
:
'
Withdrawals
'
,
'
/visualize/sol2uml
'
:
'
Solidity UML diagram
'
,
'
/csv-export
'
:
'
Export data to CSV file
'
,
'
/l2-deposits
'
:
'
Deposits (L1 > L2)
'
,
'
/l2-output-roots
'
:
'
Output roots
'
,
'
/l2-txn-batches
'
:
'
Tx batches (L2 blocks)
'
,
'
/l2-withdrawals
'
:
'
Withdrawals (L2 > L1)
'
,
// service routes, added only to make typescript happy
'
/login
'
:
'
Login
'
,
'
/api/media-type
'
:
'
Node API: Media type
'
,
'
/api/proxy
'
:
'
Node API: Proxy
'
,
'
/api/csrf
'
:
'
Node API: CSRF token
'
,
'
/auth/auth0
'
:
'
Auth
'
,
'
/graph
'
:
'
Graph
'
,
};
export
default
function
getPageType
(
pathname
:
Route
[
'
pathname
'
])
{
return
PAGE_TYPE_DICT
[
pathname
]
||
'
Unknown page
'
;
}
lib/mixpanel/getTabName.ts
0 → 100644
View file @
fc823380
import
_capitalize
from
'
lodash/capitalize
'
;
export
default
function
getTabName
(
tab
:
string
)
{
return
tab
!==
''
?
_capitalize
(
tab
.
replaceAll
(
'
_
'
,
'
'
))
:
'
Default
'
;
}
lib/mixpanel/index.ts
0 → 100644
View file @
fc823380
import
useInit
from
'
./useInit
'
;
import
useLogPageView
from
'
./useLogPageView
'
;
export
{
useInit
,
useLogPageView
,
};
lib/
hooks/useMixpanel
Init.tsx
→
lib/
mixpanel/use
Init.tsx
View file @
fc823380
import
type
{
Config
}
from
'
mixpanel-browser
'
;
import
mixpanel
from
'
mixpanel-browser
'
;
import
React
from
'
react
'
;
import
appConfig
from
'
configs/app/config
'
;
export
default
function
useMixpanelInit
()
{
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
React
.
useEffect
(()
=>
{
if
(
appConfig
.
mixpanel
.
projectToken
)
{
const
config
=
{
const
config
:
Partial
<
Config
>
=
{
debug
:
appConfig
.
isDev
,
test
:
appConfig
.
isDev
,
};
mixpanel
.
init
(
appConfig
.
mixpanel
.
projectToken
,
config
);
setIsInited
(
true
);
}
},
[]);
return
isInited
;
}
lib/mixpanel/useLogPageView.tsx
0 → 100644
View file @
fc823380
import
mixpanel
from
'
mixpanel-browser
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
appConfig
from
'
configs/app/config
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getPageType
from
'
./getPageType
'
;
import
getTabName
from
'
./getTabName
'
;
export
default
function
useLogPageView
(
isInited
:
boolean
)
{
const
router
=
useRouter
();
const
pathname
=
router
.
pathname
;
const
tab
=
getQueryParamString
(
router
.
query
.
tab
);
React
.
useEffect
(()
=>
{
if
(
!
appConfig
.
mixpanel
.
projectToken
||
!
isInited
)
{
return
;
}
mixpanel
.
track
(
'
Page view
'
,
{
page_type
:
getPageType
(
pathname
),
tab
:
getTabName
(
tab
),
});
},
[
isInited
,
pathname
,
tab
]);
}
pages/_app.tsx
View file @
fc823380
...
...
@@ -11,7 +11,6 @@ import { Chakra } from 'lib/Chakra';
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
import
getErrorStatusCode
from
'
lib/errors/getErrorStatusCode
'
;
import
useConfigSentry
from
'
lib/hooks/useConfigSentry
'
;
import
useMixpanelInit
from
'
lib/hooks/useMixpanelInit
'
;
import
{
SocketProvider
}
from
'
lib/socket/context
'
;
import
theme
from
'
theme
'
;
import
AppError
from
'
ui/shared/AppError/AppError
'
;
...
...
@@ -24,8 +23,6 @@ function MyApp({ Component, pageProps }: AppProps) {
useConfigSentry
();
useMixpanelInit
();
const
[
queryClient
]
=
useState
(()
=>
new
QueryClient
({
defaultOptions
:
{
queries
:
{
...
...
ui/shared/Page/Page.tsx
View file @
fc823380
...
...
@@ -5,6 +5,7 @@ import getErrorStatusCode from 'lib/errors/getErrorStatusCode';
import
getResourceErrorPayload
from
'
lib/errors/getResourceErrorPayload
'
;
import
useAdblockDetect
from
'
lib/hooks/useAdblockDetect
'
;
import
useGetCsrfToken
from
'
lib/hooks/useGetCsrfToken
'
;
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
AppError
from
'
ui/shared/AppError/AppError
'
;
import
AppErrorBlockConsensus
from
'
ui/shared/AppError/AppErrorBlockConsensus
'
;
import
ErrorBoundary
from
'
ui/shared/ErrorBoundary
'
;
...
...
@@ -31,6 +32,9 @@ const Page = ({
useAdblockDetect
();
const
isMixpanelInited
=
mixpanel
.
useInit
();
mixpanel
.
useLogPageView
(
isMixpanelInited
);
const
renderErrorScreen
=
React
.
useCallback
((
error
?:
Error
)
=>
{
const
statusCode
=
getErrorStatusCode
(
error
)
||
500
;
const
resourceErrorPayload
=
getResourceErrorPayload
(
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment