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
4e370eb7
Unverified
Commit
4e370eb7
authored
Jul 24, 2023
by
Igor Stuev
Committed by
GitHub
Jul 24, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1040 from blockscout/ga-fix
fix ga error
parents
ec9c3a0b
656ab2bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
28 deletions
+38
-28
isGoogleAnalyticsLoaded.ts
lib/mixpanel/isGoogleAnalyticsLoaded.ts
+9
-0
useInit.tsx
lib/mixpanel/useInit.tsx
+29
-28
No files found.
lib/mixpanel/isGoogleAnalyticsLoaded.ts
0 → 100644
View file @
4e370eb7
import
appConfig
from
'
configs/app/config
'
;
import
delay
from
'
lib/delay
'
;
export
default
function
isGoogleAnalyticsLoaded
(
retries
=
3
):
Promise
<
boolean
>
{
if
(
!
retries
||
!
appConfig
.
googleAnalytics
.
propertyId
)
{
return
Promise
.
resolve
(
false
);
}
return
typeof
window
.
ga
?.
getAll
===
'
function
'
?
Promise
.
resolve
(
true
)
:
delay
(
500
).
then
(()
=>
isGoogleAnalyticsLoaded
(
retries
-
1
));
}
lib/mixpanel/useInit.tsx
View file @
4e370eb7
...
@@ -10,6 +10,7 @@ import * as cookies from 'lib/cookies';
...
@@ -10,6 +10,7 @@ import * as cookies from 'lib/cookies';
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
getGoogleAnalyticsClientId
from
'
./getGoogleAnalyticsClientId
'
;
import
getGoogleAnalyticsClientId
from
'
./getGoogleAnalyticsClientId
'
;
import
isGoogleAnalyticsLoaded
from
'
./isGoogleAnalyticsLoaded
'
;
export
default
function
useMixpanelInit
()
{
export
default
function
useMixpanelInit
()
{
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
const
[
isInited
,
setIsInited
]
=
React
.
useState
(
false
);
...
@@ -17,35 +18,35 @@ export default function useMixpanelInit() {
...
@@ -17,35 +18,35 @@ export default function useMixpanelInit() {
const
debugFlagQuery
=
React
.
useRef
(
getQueryParamString
(
router
.
query
.
_mixpanel_debug
));
const
debugFlagQuery
=
React
.
useRef
(
getQueryParamString
(
router
.
query
.
_mixpanel_debug
));
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
if
(
!
appConfig
.
mixpanel
.
projectToken
)
{
isGoogleAnalyticsLoaded
().
then
((
isGALoaded
)
=>
{
return
;
if
(
!
appConfig
.
mixpanel
.
projectToken
)
{
}
return
;
}
const
debugFlagCookie
=
cookies
.
get
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
);
const
debugFlagCookie
=
cookies
.
get
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
);
const
config
:
Partial
<
Config
>
=
{
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
),
const
config
:
Partial
<
Config
>
=
{
};
debug
:
Boolean
(
debugFlagQuery
.
current
||
debugFlagCookie
),
const
isAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
));
};
const
userId
=
getGoogleAnalyticsClientId
();
const
isAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
));
mixpanel
.
init
(
appConfig
.
mixpanel
.
projectToken
,
config
);
mixpanel
.
init
(
appConfig
.
mixpanel
.
projectToken
,
config
);
mixpanel
.
register
({
mixpanel
.
register
({
'
Chain id
'
:
appConfig
.
network
.
id
,
'
Chain id
'
:
appConfig
.
network
.
id
,
Environment
:
appConfig
.
isDev
?
'
Dev
'
:
'
Prod
'
,
Environment
:
appConfig
.
isDev
?
'
Dev
'
:
'
Prod
'
,
Authorized
:
isAuth
,
Authorized
:
isAuth
,
'
Viewport width
'
:
window
.
innerWidth
,
'
Viewport width
'
:
window
.
innerWidth
,
'
Viewport height
'
:
window
.
innerHeight
,
'
Viewport height
'
:
window
.
innerHeight
,
Language
:
window
.
navigator
.
language
,
Language
:
window
.
navigator
.
language
,
'
User id
'
:
userId
,
'
User id
'
:
isGALoaded
?
getGoogleAnalyticsClientId
()
:
undefined
,
'
Device type
'
:
_capitalize
(
deviceType
),
'
Device type
'
:
_capitalize
(
deviceType
),
});
setIsInited
(
true
);
if
(
debugFlagQuery
.
current
&&
!
debugFlagCookie
)
{
cookies
.
set
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
,
'
true
'
);
}
});
});
setIsInited
(
true
);
if
(
debugFlagQuery
.
current
&&
!
debugFlagCookie
)
{
cookies
.
set
(
cookies
.
NAMES
.
MIXPANEL_DEBUG
,
'
true
'
);
}
},
[]);
},
[]);
return
isInited
;
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