Skip to content

Commit cf30ee8

Browse files
committed
Refactor telemetry configuration to use boolean flags for debug mode. Update related components to ensure consistent telemetry data handling across the application.
1 parent 9c5b660 commit cf30ee8

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

packages/react/src/contexts/TelemetryContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createContext } from 'react';
33
export interface TelemetryConfig {
44
projectId: string;
55
disabled?: boolean;
6-
mode?: 'debug' | 'production';
6+
isDebugMode?: boolean;
77
isDefaultTheme?: boolean;
88
hasCustomerSupportEmail?: boolean;
99
darkMode?: 'on' | 'off' | 'auto';

packages/react/src/hocs/CorbadoProvider.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import { TelemetryProvider } from '../contexts/TelemetryProvider';
1313
import { ThemeProvider } from '../contexts/ThemeProvider';
1414
import { handleDynamicLocaleSetup } from '../i18n';
1515

16-
export interface TelemetryConfig {
17-
disabled?: boolean;
18-
mode?: 'debug';
19-
}
16+
export type TelemetryConfig =
17+
| false
18+
| {
19+
debug?: boolean;
20+
disabled?: boolean;
21+
};
2022

2123
export interface CorbadoProviderProps extends PropsWithChildren<CorbadoConfig> {
2224
corbadoAppInstance?: CorbadoApp;
@@ -54,8 +56,9 @@ const CorbadoProvider: FC<CorbadoProviderProps> = ({
5456
return (
5557
<TelemetryProvider
5658
telemetryConfig={{
57-
...telemetry,
5859
projectId,
60+
disabled: telemetry === false || telemetry?.disabled === true,
61+
isDebugMode: telemetry && telemetry.debug,
5962
isPreviewMode,
6063
isDevMode,
6164
hasCustomerSupportEmail: Boolean(customerSupportEmail),

packages/react/src/hooks/useTelemetry.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function useTelemetry() {
2121
}
2222

2323
const { telemetryConfig, setTelemetryConfig } = context;
24-
const { projectId, disabled, mode } = telemetryConfig;
24+
const { projectId, disabled, isDebugMode } = telemetryConfig;
2525
const packageMetadataSent = useRef(false);
2626

2727
const disableTelemetry = useCallback(() => {
@@ -45,10 +45,10 @@ export function useTelemetry() {
4545
sdkVersion: SDK_VERSION,
4646
sdkName: SDK_NAME,
4747
identifier: projectId,
48-
debugMode: mode === 'debug',
48+
debugMode: isDebugMode,
4949
});
5050
},
51-
[projectId, mode, disabled],
51+
[projectId, isDebugMode, disabled],
5252
);
5353

5454
const logPackageMetadata = useCallback(() => {
@@ -87,11 +87,11 @@ export function useTelemetry() {
8787
sdkVersion: SDK_VERSION,
8888
sdkName: SDK_NAME,
8989
identifier: projectId,
90-
debugMode: mode === 'debug',
90+
debugMode: isDebugMode,
9191
});
9292

9393
packageMetadataSent.current = true;
94-
}, [projectId, mode, disabled, telemetryConfig]);
94+
}, [projectId, isDebugMode, disabled, telemetryConfig]);
9595

9696
return {
9797
disableTelemetry,

playground/react/src/hoc/withCorbadoProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function withCorbadoProvider<T extends JSX.IntrinsicAttributes>(WrappedComponent
1919
darkMode={darkMode ? 'on' : 'off'}
2020
isDevMode={true}
2121
frontendApiUrlSuffix={import.meta.env.REACT_APP_CORBADO_FRONTEND_API_URL_SUFFIX}
22+
telemetry={{ debug: true }}
2223
>
2324
<WrappedComponent {...(props as T)} />
2425
</CorbadoProvider>

playground/web-js-script/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
projectId: projectId,
2929
frontendApiUrlSuffix: 'frontendapi.cloud.corbado-staging.io',
3030
darkMode: 'auto',
31+
telemetry: { debug: true }
3132
});
3233
}
3334

0 commit comments

Comments
 (0)