mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 04:52:03 +08:00
chore: added theme analytics for the users (#5097)
* chore: added theme analytics for the users * chore: added error handling * fix: refactor code
This commit is contained in:
parent
c913c8bf20
commit
b849705710
@ -9,13 +9,14 @@ import ROUTES from 'constants/routes';
|
|||||||
import AppLayout from 'container/AppLayout';
|
import AppLayout from 'container/AppLayout';
|
||||||
import useAnalytics from 'hooks/analytics/useAnalytics';
|
import useAnalytics from 'hooks/analytics/useAnalytics';
|
||||||
import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys';
|
import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys';
|
||||||
import { useThemeConfig } from 'hooks/useDarkMode';
|
import { useIsDarkMode, useThemeConfig } from 'hooks/useDarkMode';
|
||||||
|
import { THEME_MODE } from 'hooks/useDarkMode/constant';
|
||||||
import useGetFeatureFlag from 'hooks/useGetFeatureFlag';
|
import useGetFeatureFlag from 'hooks/useGetFeatureFlag';
|
||||||
import useLicense, { LICENSE_PLAN_KEY } from 'hooks/useLicense';
|
import useLicense, { LICENSE_PLAN_KEY } from 'hooks/useLicense';
|
||||||
import { NotificationProvider } from 'hooks/useNotifications';
|
import { NotificationProvider } from 'hooks/useNotifications';
|
||||||
import { ResourceProvider } from 'hooks/useResourceAttribute';
|
import { ResourceProvider } from 'hooks/useResourceAttribute';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { identity, pickBy } from 'lodash-es';
|
import { identity, pick, pickBy } from 'lodash-es';
|
||||||
import { DashboardProvider } from 'providers/Dashboard/Dashboard';
|
import { DashboardProvider } from 'providers/Dashboard/Dashboard';
|
||||||
import { QueryBuilderProvider } from 'providers/QueryBuilder';
|
import { QueryBuilderProvider } from 'providers/QueryBuilder';
|
||||||
import { Suspense, useEffect, useState } from 'react';
|
import { Suspense, useEffect, useState } from 'react';
|
||||||
@ -46,12 +47,14 @@ function App(): JSX.Element {
|
|||||||
|
|
||||||
const dispatch = useDispatch<Dispatch<AppActions>>();
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
||||||
|
|
||||||
const { trackPageView } = useAnalytics();
|
const { trackPageView, trackEvent } = useAnalytics();
|
||||||
|
|
||||||
const { hostname, pathname } = window.location;
|
const { hostname, pathname } = window.location;
|
||||||
|
|
||||||
const isCloudUserVal = isCloudUser();
|
const isCloudUserVal = isCloudUser();
|
||||||
|
|
||||||
|
const isDarkMode = useIsDarkMode();
|
||||||
|
|
||||||
const featureResponse = useGetFeatureFlag((allFlags) => {
|
const featureResponse = useGetFeatureFlag((allFlags) => {
|
||||||
const isOnboardingEnabled =
|
const isOnboardingEnabled =
|
||||||
allFlags.find((flag) => flag.name === FeatureKeys.ONBOARDING)?.active ||
|
allFlags.find((flag) => flag.name === FeatureKeys.ONBOARDING)?.active ||
|
||||||
@ -174,6 +177,25 @@ function App(): JSX.Element {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
const isThemeAnalyticsSent = getLocalStorageApi(
|
||||||
|
LOCALSTORAGE.THEME_ANALYTICS,
|
||||||
|
);
|
||||||
|
if (!isThemeAnalyticsSent) {
|
||||||
|
trackEvent('Theme Analytics', {
|
||||||
|
theme: isDarkMode ? THEME_MODE.DARK : THEME_MODE.LIGHT,
|
||||||
|
user: pick(user, ['email', 'userId', 'name']),
|
||||||
|
org,
|
||||||
|
});
|
||||||
|
setLocalStorageApi(LOCALSTORAGE.THEME_ANALYTICS, 'true');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.error('Failed to parse local storage theme analytics event');
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigProvider theme={themeConfig}>
|
<ConfigProvider theme={themeConfig}>
|
||||||
<Router history={history}>
|
<Router history={history}>
|
||||||
|
@ -18,4 +18,5 @@ export enum LOCALSTORAGE {
|
|||||||
DASHBOARD_VARIABLES = 'DASHBOARD_VARIABLES',
|
DASHBOARD_VARIABLES = 'DASHBOARD_VARIABLES',
|
||||||
SHOW_EXPLORER_TOOLBAR = 'SHOW_EXPLORER_TOOLBAR',
|
SHOW_EXPLORER_TOOLBAR = 'SHOW_EXPLORER_TOOLBAR',
|
||||||
PINNED_ATTRIBUTES = 'PINNED_ATTRIBUTES',
|
PINNED_ATTRIBUTES = 'PINNED_ATTRIBUTES',
|
||||||
|
THEME_ANALYTICS = 'THEME_ANALYTICS',
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ export function ThemeProvider({ children }: ThemeProviderProps): JSX.Element {
|
|||||||
setTheme(THEME_MODE.LIGHT);
|
setTheme(THEME_MODE.LIGHT);
|
||||||
set(LOCALSTORAGE.THEME, THEME_MODE.LIGHT);
|
set(LOCALSTORAGE.THEME, THEME_MODE.LIGHT);
|
||||||
}
|
}
|
||||||
|
set(LOCALSTORAGE.THEME_ANALYTICS, '');
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
const value = useMemo(
|
const value = useMemo(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user