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

View File

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