Add environment to the admin analytics calls the correct way

This commit is contained in:
ivanThePleasant 2022-07-20 11:05:26 +03:00
parent 42261b8a0a
commit cc4a3ba507
2 changed files with 12 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import {
useNotification, useNotification,
TrackingContext, TrackingContext,
prefixFileUrlWithBackendUrl, prefixFileUrlWithBackendUrl,
useAppInfos,
} from '@strapi/helper-plugin'; } from '@strapi/helper-plugin';
import { SkipToContent } from '@strapi/design-system/Main'; import { SkipToContent } from '@strapi/design-system/Main';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
@ -34,6 +35,7 @@ function App() {
const { updateProjectSettings } = useConfigurations(); const { updateProjectSettings } = useConfigurations();
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const [{ isLoading, hasAdmin, uuid }, setState] = useState({ isLoading: true, hasAdmin: false }); const [{ isLoading, hasAdmin, uuid }, setState] = useState({ isLoading: true, hasAdmin: false });
const appInfo = useAppInfos();
const authRoutes = useMemo(() => { const authRoutes = useMemo(() => {
return makeUniqueRoutes( return makeUniqueRoutes(
@ -85,8 +87,8 @@ function App() {
uuid, uuid,
deviceId, deviceId,
properties: { properties: {
environment: process.env.NODE_ENV environment: appInfo.currentEnvironment,
} },
}), }),
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -107,6 +109,7 @@ function App() {
}; };
getData(); getData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [toggleNotification, updateProjectSettings]); }, [toggleNotification, updateProjectSettings]);
const setHasAdmin = hasAdmin => setState(prev => ({ ...prev, hasAdmin })); const setHasAdmin = hasAdmin => setState(prev => ({ ...prev, hasAdmin }));

View File

@ -1,17 +1,23 @@
import { useContext, useRef } from 'react'; import { useContext, useRef } from 'react';
import axios from 'axios'; import axios from 'axios';
import TrackingContext from '../../contexts/TrackingContext'; import TrackingContext from '../../contexts/TrackingContext';
import useAppInfos from '../useAppInfos';
const useTracking = () => { const useTracking = () => {
const trackRef = useRef(); const trackRef = useRef();
const uuid = useContext(TrackingContext); const uuid = useContext(TrackingContext);
const appInfo = useAppInfos();
trackRef.current = (event, properties) => { trackRef.current = (event, properties) => {
if (uuid) { if (uuid) {
try { try {
axios.post('https://analytics.strapi.io/track', { axios.post('https://analytics.strapi.io/track', {
event, event,
properties: { ...properties, projectType: strapi.projectType, environment: process.env.NODE_ENV }, properties: {
...properties,
projectType: strapi.projectType,
environment: appInfo.currentEnvironment,
},
uuid, uuid,
}); });
} catch (err) { } catch (err) {