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
df59efab
Commit
df59efab
authored
May 11, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug flag
parent
f06ce9f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
cookies.ts
lib/cookies.ts
+1
-0
useInit.tsx
lib/mixpanel/useInit.tsx
+11
-1
No files found.
lib/cookies.ts
View file @
df59efab
...
...
@@ -9,6 +9,7 @@ export enum NAMES {
COLOR_MODE
=
'
chakra-ui-color-mode
'
,
INDEXING_ALERT
=
'
indexing_alert
'
,
ADBLOCK_DETECTED
=
'
adblock_detected
'
,
MIXPANEL_DEBUG
=
'
_mixpanel_debug
'
,
}
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
...
...
lib/mixpanel/useInit.tsx
View file @
df59efab
import
_capitalize
from
'
lodash/capitalize
'
;
import
type
{
Config
}
from
'
mixpanel-browser
'
;
import
mixpanel
from
'
mixpanel-browser
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
{
deviceType
}
from
'
react-device-detect
'
;
import
appConfig
from
'
configs/app/config
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getGoogleAnalyticsClientId
from
'
./getGoogleAnalyticsClientId
'
;
export
default
function
useMixpanelInit
()
{
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
const
router
=
useRouter
();
const
debugFlagQuery
=
React
.
useRef
(
getQueryParamString
(
router
.
query
.
_mixpanel_debug
));
React
.
useEffect
(()
=>
{
if
(
!
appConfig
.
mixpanel
.
projectToken
)
{
return
;
}
const
debugFlagCookie
=
cookies
.
get
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
);
const
config
:
Partial
<
Config
>
=
{
debug
:
appConfig
.
isDev
,
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
)
,
};
const
isAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
));
const
userId
=
getGoogleAnalyticsClientId
();
...
...
@@ -36,6 +42,10 @@ export default function useMixpanelInit() {
});
setIsInited
(
true
);
if
(
debugFlagQuery
.
current
&&
!
debugFlagCookie
)
{
cookies
.
set
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
,
'
true
'
);
}
},
[]);
return
isInited
;
...
...
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