Commit 4e370eb7 authored by Igor Stuev's avatar Igor Stuev Committed by GitHub

Merge pull request #1040 from blockscout/ga-fix

fix ga error
parents ec9c3a0b 656ab2bf
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));
}
......@@ -10,6 +10,7 @@ import * as cookies from 'lib/cookies';
import getQueryParamString from 'lib/router/getQueryParamString';
import getGoogleAnalyticsClientId from './getGoogleAnalyticsClientId';
import isGoogleAnalyticsLoaded from './isGoogleAnalyticsLoaded';
export default function useMixpanelInit() {
const [ isInited, setIsInited ] = React.useState(false);
......@@ -17,6 +18,7 @@ export default function useMixpanelInit() {
const debugFlagQuery = React.useRef(getQueryParamString(router.query._mixpanel_debug));
React.useEffect(() => {
isGoogleAnalyticsLoaded().then((isGALoaded) => {
if (!appConfig.mixpanel.projectToken) {
return;
}
......@@ -27,7 +29,6 @@ export default function useMixpanelInit() {
debug: Boolean(debugFlagQuery.current || debugFlagCookie),
};
const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN));
const userId = getGoogleAnalyticsClientId();
mixpanel.init(appConfig.mixpanel.projectToken, config);
mixpanel.register({
......@@ -37,15 +38,15 @@ export default function useMixpanelInit() {
'Viewport width': window.innerWidth,
'Viewport height': window.innerHeight,
Language: window.navigator.language,
'User id': userId,
'User id': isGALoaded ? getGoogleAnalyticsClientId() : undefined,
'Device type': _capitalize(deviceType),
});
setIsInited(true);
if (debugFlagQuery.current && !debugFlagCookie) {
cookies.set(cookies.NAMES.MIXPANEL_DEBUG, 'true');
}
});
}, []);
return isInited;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment