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
d97544da
Commit
d97544da
authored
Feb 13, 2025
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
traffic monitor
parent
c8d6980b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
37 deletions
+50
-37
init.ts
lib/growthbook/init.ts
+3
-3
useLoadFeatures.ts
lib/growthbook/useLoadFeatures.ts
+4
-3
getUuid.ts
lib/mixpanel/getUuid.ts
+0
-20
index.ts
lib/mixpanel/index.ts
+0
-2
useInit.tsx
lib/mixpanel/useInit.tsx
+5
-5
PageNextJs.tsx
nextjs/PageNextJs.tsx
+1
-0
getServerSideProps.ts
nextjs/getServerSideProps.ts
+34
-1
_app.tsx
pages/_app.tsx
+3
-3
No files found.
lib/growthbook/init.ts
View file @
d97544da
...
...
@@ -9,7 +9,7 @@ export interface GrowthBookFeatures {
test_value
:
string
;
}
export
const
growthBook
=
((
)
=>
{
export
const
initGrowthBook
=
(
uuid
:
string
)
=>
{
const
feature
=
config
.
features
.
growthBook
;
if
(
!
feature
.
isEnabled
)
{
...
...
@@ -21,7 +21,7 @@ export const growthBook = (() => {
clientKey
:
feature
.
clientKey
,
enableDevMode
:
config
.
app
.
isDev
,
attributes
:
{
id
:
mixpanel
.
getUuid
()
,
id
:
uuid
,
chain_id
:
config
.
chain
.
id
,
},
trackingCallback
:
(
experiment
,
result
)
=>
{
...
...
@@ -37,7 +37,7 @@ export const growthBook = (() => {
});
},
});
}
)()
;
};
function
getStorageValue
():
Array
<
unknown
>
|
undefined
{
const
item
=
window
.
localStorage
.
getItem
(
STORAGE_KEY
);
...
...
lib/growthbook/useLoadFeatures.ts
View file @
d97544da
...
...
@@ -2,9 +2,10 @@ import React from 'react';
import
{
SECOND
}
from
'
lib/consts
'
;
import
{
g
rowthBook
}
from
'
./init
'
;
import
{
initG
rowthBook
}
from
'
./init
'
;
export
default
function
useLoadFeatures
()
{
export
default
function
useLoadFeatures
(
uuid
:
string
)
{
const
growthBook
=
initGrowthBook
(
uuid
);
React
.
useEffect
(()
=>
{
growthBook
?.
setAttributes
({
...
growthBook
.
getAttributes
(),
...
...
@@ -13,5 +14,5 @@ export default function useLoadFeatures() {
});
growthBook
?.
loadFeatures
({
timeout
:
SECOND
});
},
[]);
},
[
growthBook
]);
}
lib/mixpanel/getUuid.ts
deleted
100644 → 0
View file @
c8d6980b
import
*
as
cookies
from
'
lib/cookies
'
;
import
*
as
growthBook
from
'
lib/growthbook/consts
'
;
import
isBrowser
from
'
lib/isBrowser
'
;
export
default
function
getUuid
()
{
const
cookie
=
cookies
.
get
(
cookies
.
NAMES
.
UUID
);
if
(
cookie
)
{
return
cookie
;
}
const
uuid
=
crypto
.
randomUUID
();
cookies
.
set
(
cookies
.
NAMES
.
UUID
,
uuid
);
if
(
isBrowser
())
{
window
.
localStorage
.
removeItem
(
growthBook
.
STORAGE_KEY
);
}
return
uuid
;
}
lib/mixpanel/index.ts
View file @
d97544da
import
getPageType
from
'
./getPageType
'
;
import
getUuid
from
'
./getUuid
'
;
import
logEvent
from
'
./logEvent
'
;
import
reset
from
'
./reset
'
;
import
useInit
from
'
./useInit
'
;
...
...
@@ -12,7 +11,6 @@ export {
useLogPageView
,
logEvent
,
getPageType
,
getUuid
,
userProfile
,
reset
,
};
lib/mixpanel/useInit.tsx
View file @
d97544da
...
...
@@ -10,7 +10,6 @@ import * as cookies from 'lib/cookies';
import
dayjs
from
'
lib/date/dayjs
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getUuid
from
'
./getUuid
'
;
import
*
as
userProfile
from
'
./userProfile
'
;
export
default
function
useMixpanelInit
()
{
...
...
@@ -30,7 +29,8 @@ export default function useMixpanelInit() {
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
),
};
const
isAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
));
const
userId
=
getUuid
();
const
uuid
=
cookies
.
get
(
cookies
.
NAMES
.
UUID
);
mixpanel
.
init
(
feature
.
projectToken
,
mixpanelConfig
);
mixpanel
.
register
({
...
...
@@ -41,9 +41,9 @@ export default function useMixpanelInit() {
'
Viewport height
'
:
window
.
innerHeight
,
Language
:
window
.
navigator
.
language
,
'
Device type
'
:
capitalize
(
deviceType
),
'
User id
'
:
u
serI
d
,
'
User id
'
:
u
ui
d
,
});
mixpanel
.
identify
(
u
serI
d
);
mixpanel
.
identify
(
u
ui
d
);
userProfile
.
set
({
'
Device Type
'
:
capitalize
(
deviceType
),
...(
isAuth
?
{
'
With Account
'
:
true
}
:
{}),
...
...
@@ -56,7 +56,7 @@ export default function useMixpanelInit() {
if
(
debugFlagQuery
.
current
&&
!
debugFlagCookie
)
{
cookies
.
set
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
,
'
true
'
);
}
},
[]);
},
[
]);
return
isInited
;
}
nextjs/PageNextJs.tsx
View file @
d97544da
...
...
@@ -11,6 +11,7 @@ import * as metadata from 'lib/metadata';
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
interface
Props
<
Pathname
extends
Route
[
'
pathname
'
]
>
{
uuid
:
string
;
pathname
:
Pathname
;
children
:
React
.
ReactNode
;
query
?:
PageProps
<
Pathname
>
[
'
query
'
];
...
...
nextjs/getServerSideProps.ts
View file @
d97544da
...
...
@@ -9,6 +9,7 @@ import config from 'configs/app';
const
rollupFeature
=
config
.
features
.
rollup
;
const
adBannerFeature
=
config
.
features
.
adsBanner
;
import
isNeedProxy
from
'
lib/api/isNeedProxy
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
type
*
as
metadata
from
'
lib/metadata
'
;
export
interface
Props
<
Pathname
extends
Route
[
'
pathname
'
]
=
never
>
{
...
...
@@ -19,9 +20,10 @@ export interface Props<Pathname extends Route['pathname'] = never> {
// if apiData is undefined, Next.js will complain that it is not serializable
// so we force it to be always present in the props but it can be null
apiData
:
metadata
.
ApiData
<
Pathname
>
|
null
;
uuid
:
string
;
}
export
const
base
=
async
<
Pathname
extends
Route
[
'
pathname
'
]
=
never
>
({
req
,
query
}:
GetServerSidePropsContext
):
export
const
base
=
async
<
Pathname
extends
Route
[
'
pathname
'
]
=
never
>
({
req
,
res
,
query
}:
GetServerSidePropsContext
):
Promise
<
GetServerSidePropsResult
<
Props
<
Pathname
>>>
=>
{
const
adBannerProvider
=
(()
=>
{
if
(
adBannerFeature
.
isEnabled
)
{
...
...
@@ -36,6 +38,36 @@ Promise<GetServerSidePropsResult<Props<Pathname>>> => {
return
null
;
})();
let
uuid
=
cookies
.
getFromCookieString
(
req
.
headers
.
cookie
||
''
,
cookies
.
NAMES
.
UUID
);
if
(
!
uuid
)
{
uuid
=
crypto
.
randomUUID
();
res
.
setHeader
(
'
Set-Cookie
'
,
`
${
cookies
.
NAMES
.
UUID
}
=
${
uuid
}
`
);
}
const
isTrackingDisabled
=
process
.
env
.
DISABLE_TRACKING
===
'
true
'
;
if
(
!
isTrackingDisabled
)
{
// log pageview
const
hostname
=
req
.
headers
.
host
;
const
timestamp
=
new
Date
().
toISOString
();
const
chainId
=
process
.
env
.
NEXT_PUBLIC_NETWORK_ID
;
const
chainName
=
process
.
env
.
NEXT_PUBLIC_NETWORK_NAME
;
const
publicRPC
=
process
.
env
.
NEXT_PUBLIC_NETWORK_RPC_URL
;
fetch
(
'
https://monitor.blockscout.com/count
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
({
hostname
,
timestamp
,
chainId
,
chainName
,
publicRPC
,
uuid
,
}),
});
}
return
{
props
:
{
query
,
...
...
@@ -43,6 +75,7 @@ Promise<GetServerSidePropsResult<Props<Pathname>>> => {
referrer
:
req
.
headers
.
referer
||
''
,
adBannerProvider
:
adBannerProvider
,
apiData
:
null
,
uuid
,
},
};
};
...
...
pages/_app.tsx
View file @
d97544da
...
...
@@ -15,7 +15,7 @@ import { MarketplaceContextProvider } from 'lib/contexts/marketplace';
import
{
RewardsContextProvider
}
from
'
lib/contexts/rewards
'
;
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
import
{
SettingsContextProvider
}
from
'
lib/contexts/settings
'
;
import
{
g
rowthBook
}
from
'
lib/growthbook/init
'
;
import
{
initG
rowthBook
}
from
'
lib/growthbook/init
'
;
import
useLoadFeatures
from
'
lib/growthbook/useLoadFeatures
'
;
import
useNotifyOnNavigation
from
'
lib/hooks/useNotifyOnNavigation
'
;
import
{
clientConfig
as
rollbarConfig
,
Provider
as
RollbarProvider
}
from
'
lib/rollbar
'
;
...
...
@@ -47,10 +47,10 @@ const ERROR_SCREEN_STYLES: ChakraProps = {
};
function
MyApp
({
Component
,
pageProps
}:
AppPropsWithLayout
)
{
useLoadFeatures
();
useLoadFeatures
(
pageProps
.
uuid
);
useNotifyOnNavigation
();
const
growthBook
=
initGrowthBook
(
pageProps
.
uuid
);
const
queryClient
=
useQueryClientConfig
();
const
getLayout
=
Component
.
getLayout
??
((
page
)
=>
<
Layout
>
{
page
}
</
Layout
>);
...
...
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