Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: added theme analytics for the users (#5097)

Vikrant Guptab84970571082
diff --git a/frontend/src/AppRoutes/index.tsx b/frontend/src/AppRoutes/index.tsx
index 7bc58c509e..945ac8b6be 100644
--- a/frontend/src/AppRoutes/index.tsx
+++ b/frontend/src/AppRoutes/index.tsx
@@ -9,13 +9,14 @@ import ROUTES from 'constants/routes';
import AppLayout from 'container/AppLayout';
import useAnalytics from 'hooks/analytics/useAnalytics';
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 useLicense, { LICENSE_PLAN_KEY } from 'hooks/useLicense';
import { NotificationProvider } from 'hooks/useNotifications';
import { ResourceProvider } from 'hooks/useResourceAttribute';
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 { QueryBuilderProvider } from 'providers/QueryBuilder';
import { Suspense, useEffect, useState } from 'react';
@@ -46,12 +47,14 @@ function App(): JSX.Element {
const dispatch = useDispatch<Dispatch<AppActions>>();
- const { trackPageView } = useAnalytics();
+ const { trackPageView, trackEvent } = useAnalytics();
const { hostname, pathname } = window.location;
const isCloudUserVal = isCloudUser();
+ const isDarkMode = useIsDarkMode();
+
const featureResponse = useGetFeatureFlag((allFlags) => {
const isOnboardingEnabled =
allFlags.find((flag) => flag.name === FeatureKeys.ONBOARDING)?.active ||
@@ -174,6 +177,25 @@ function App(): JSX.Element {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [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 (
<ConfigProvider theme={themeConfig}>
<Router history={history}>
diff --git a/frontend/src/constants/localStorage.ts b/frontend/src/constants/localStorage.ts
index 85f46ab892..481bf5dab0 100644
--- a/frontend/src/constants/localStorage.ts
+++ b/frontend/src/constants/localStorage.ts
@@ -18,4 +18,5 @@ export enum LOCALSTORAGE {
DASHBOARD_VARIABLES = 'DASHBOARD_VARIABLES',
SHOW_EXPLORER_TOOLBAR = 'SHOW_EXPLORER_TOOLBAR',
PINNED_ATTRIBUTES = 'PINNED_ATTRIBUTES',
+ THEME_ANALYTICS = 'THEME_ANALYTICS',
}
diff --git a/frontend/src/hooks/useDarkMode/index.tsx b/frontend/src/hooks/useDarkMode/index.tsx
index 00df811704..d7e3a279e0 100644
--- a/frontend/src/hooks/useDarkMode/index.tsx
+++ b/frontend/src/hooks/useDarkMode/index.tsx
@@ -30,6 +30,7 @@ export function ThemeProvider({ children }: ThemeProviderProps): JSX.Element {
setTheme(THEME_MODE.LIGHT);
set(LOCALSTORAGE.THEME, THEME_MODE.LIGHT);
}
+ set(LOCALSTORAGE.THEME_ANALYTICS, '');
}, [theme]);
const value = useMemo(