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
2c18ad2f
Commit
2c18ad2f
authored
Jan 11, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manually generate uuid
parent
88dc01d5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
10 deletions
+38
-10
cookies.ts
lib/cookies.ts
+2
-1
init.ts
lib/growthbook/init.ts
+8
-4
getUuid.ts
lib/mixpanel/getUuid.ts
+14
-0
index.ts
lib/mixpanel/index.ts
+2
-0
useInit.tsx
lib/mixpanel/useInit.tsx
+5
-4
utils.ts
lib/mixpanel/utils.ts
+7
-1
No files found.
lib/cookies.ts
View file @
2c18ad2f
...
@@ -13,7 +13,8 @@ export enum NAMES {
...
@@ -13,7 +13,8 @@ export enum NAMES {
INDEXING_ALERT
=
'
indexing_alert
'
,
INDEXING_ALERT
=
'
indexing_alert
'
,
ADBLOCK_DETECTED
=
'
adblock_detected
'
,
ADBLOCK_DETECTED
=
'
adblock_detected
'
,
MIXPANEL_DEBUG
=
'
_mixpanel_debug
'
,
MIXPANEL_DEBUG
=
'
_mixpanel_debug
'
,
ADDRESS_NFT_DISPLAY_TYPE
=
'
address_nft_display_type
'
ADDRESS_NFT_DISPLAY_TYPE
=
'
address_nft_display_type
'
,
UUID
=
'
uuid
'
,
}
}
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
...
...
lib/growthbook/init.ts
View file @
2c18ad2f
import
{
GrowthBook
}
from
'
@growthbook/growthbook-react
'
;
import
{
GrowthBook
}
from
'
@growthbook/growthbook-react
'
;
import
mixpanel
from
'
mixpanel-browser
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
export
const
growthBook
=
(()
=>
{
export
const
growthBook
=
(()
=>
{
const
feature
=
config
.
features
.
growthBook
;
const
feature
=
config
.
features
.
growthBook
;
...
@@ -14,11 +14,15 @@ export const growthBook = (() => {
...
@@ -14,11 +14,15 @@ export const growthBook = (() => {
apiHost
:
'
https://cdn.growthbook.io
'
,
apiHost
:
'
https://cdn.growthbook.io
'
,
clientKey
:
feature
.
clientKey
,
clientKey
:
feature
.
clientKey
,
enableDevMode
:
config
.
app
.
isDev
,
enableDevMode
:
config
.
app
.
isDev
,
attributes
:
{
id
:
mixpanel
.
getUuid
(),
chain_id
:
config
.
chain
.
id
,
},
trackingCallback
:
(
experiment
,
result
)
=>
{
trackingCallback
:
(
experiment
,
result
)
=>
{
mixpanel
.
track
(
'
$experiment_started
'
,
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
EXPERIMENT_STARTED
,
{
'
Experiment name
'
:
experiment
.
key
,
'
Experiment name
'
:
experiment
.
key
,
'
Variant name
'
:
result
.
va
riationId
,
'
Variant name
'
:
result
.
va
lue
,
$s
ource
:
'
growthbook
'
,
S
ource
:
'
growthbook
'
,
});
});
},
},
});
});
...
...
lib/mixpanel/getUuid.ts
0 → 100644
View file @
2c18ad2f
import
*
as
cookies
from
'
lib/cookies
'
;
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
);
return
uuid
;
}
lib/mixpanel/index.ts
View file @
2c18ad2f
import
getPageType
from
'
./getPageType
'
;
import
getPageType
from
'
./getPageType
'
;
import
getUuid
from
'
./getUuid
'
;
import
logEvent
from
'
./logEvent
'
;
import
logEvent
from
'
./logEvent
'
;
import
useInit
from
'
./useInit
'
;
import
useInit
from
'
./useInit
'
;
import
useLogPageView
from
'
./useLogPageView
'
;
import
useLogPageView
from
'
./useLogPageView
'
;
...
@@ -9,4 +10,5 @@ export {
...
@@ -9,4 +10,5 @@ export {
useLogPageView
,
useLogPageView
,
logEvent
,
logEvent
,
getPageType
,
getPageType
,
getUuid
,
};
};
lib/mixpanel/useInit.tsx
View file @
2c18ad2f
...
@@ -10,6 +10,8 @@ import * as cookies from 'lib/cookies';
...
@@ -10,6 +10,8 @@ import * as cookies from 'lib/cookies';
import
{
growthBook
}
from
'
lib/growthbook/init
'
;
import
{
growthBook
}
from
'
lib/growthbook/init
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getUuid
from
'
./getUuid
'
;
export
default
function
useMixpanelInit
()
{
export
default
function
useMixpanelInit
()
{
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
const
router
=
useRouter
();
const
router
=
useRouter
();
...
@@ -25,13 +27,11 @@ export default function useMixpanelInit() {
...
@@ -25,13 +27,11 @@ export default function useMixpanelInit() {
const
mixpanelConfig
:
Partial
<
Config
>
=
{
const
mixpanelConfig
:
Partial
<
Config
>
=
{
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
),
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
),
loaded
:
function
(
mixpanel
)
{
loaded
:
function
()
{
growthBook
?.
setAttributes
({
growthBook
?.
setAttributes
({
...
growthBook
.
getAttributes
(),
...
growthBook
.
getAttributes
(),
id
:
mixpanel
.
get_distinct_id
(),
time_zone
:
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
time_zone
:
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
language
:
mixpanel
.
get_property
(
'
Language
'
),
language
:
window
.
navigator
.
language
,
chain_id
:
mixpanel
.
get_property
(
'
Chain id
'
),
});
});
},
},
};
};
...
@@ -46,6 +46,7 @@ export default function useMixpanelInit() {
...
@@ -46,6 +46,7 @@ export default function useMixpanelInit() {
'
Viewport height
'
:
window
.
innerHeight
,
'
Viewport height
'
:
window
.
innerHeight
,
Language
:
window
.
navigator
.
language
,
Language
:
window
.
navigator
.
language
,
'
Device type
'
:
_capitalize
(
deviceType
),
'
Device type
'
:
_capitalize
(
deviceType
),
'
User id
'
:
getUuid
(),
});
});
setIsInited
(
true
);
setIsInited
(
true
);
...
...
lib/mixpanel/utils.ts
View file @
2c18ad2f
...
@@ -13,7 +13,8 @@ export enum EventTypes {
...
@@ -13,7 +13,8 @@ export enum EventTypes {
CONTRACT_VERIFICATION
=
'
Contract verification
'
,
CONTRACT_VERIFICATION
=
'
Contract verification
'
,
QR_CODE
=
'
QR code
'
,
QR_CODE
=
'
QR code
'
,
PAGE_WIDGET
=
'
Page widget
'
,
PAGE_WIDGET
=
'
Page widget
'
,
TX_INTERPRETATION_INTERACTION
=
'
Transaction interpratetion interaction
'
TX_INTERPRETATION_INTERACTION
=
'
Transaction interpratetion interaction
'
,
EXPERIMENT_STARTED
=
'
Experiment started
'
,
}
}
/* eslint-disable @typescript-eslint/indent */
/* eslint-disable @typescript-eslint/indent */
...
@@ -82,5 +83,10 @@ Type extends EventTypes.PAGE_WIDGET ? {
...
@@ -82,5 +83,10 @@ Type extends EventTypes.PAGE_WIDGET ? {
Type
extends
EventTypes
.
TX_INTERPRETATION_INTERACTION
?
{
Type
extends
EventTypes
.
TX_INTERPRETATION_INTERACTION
?
{
'
Type
'
:
'
Address click
'
|
'
Token click
'
;
'
Type
'
:
'
Address click
'
|
'
Token click
'
;
}
:
}
:
Type
extends
EventTypes
.
EXPERIMENT_STARTED
?
{
'
Experiment name
'
:
string
;
'
Variant name
'
:
string
;
'
Source
'
:
'
growthbook
'
;
}
:
undefined
;
undefined
;
/* eslint-enable @typescript-eslint/indent */
/* eslint-enable @typescript-eslint/indent */
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