@@ -12,7 +12,6 @@ import {
1212
1313import type { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
1414
15- import { logger } from './logger'
1615
1716// Re-export types from core for backwards compatibility
1817export type { AnalyticsClientWithIdentify as AnalyticsClient } from '@codebuff/common/analytics-core'
@@ -74,6 +73,17 @@ function resolveDeps(): ResolvedAnalyticsDeps {
7473 }
7574}
7675
76+ function logAnalyticsDebug ( message : string , data : Record < string , unknown > ) {
77+ if ( ! DEBUG_ANALYTICS ) {
78+ return
79+ }
80+ try {
81+ console . debug ( message , data )
82+ } catch {
83+ // Ignore console errors in restricted environments
84+ }
85+ }
86+
7787/** Get current distinct ID (real user ID if identified, otherwise anonymous ID) */
7888function getDistinctId ( ) : string | undefined {
7989 return currentUserId ?? anonymousId
@@ -173,7 +183,11 @@ export function trackEvent(
173183
174184 if ( ! isProd ) {
175185 if ( DEBUG_ANALYTICS ) {
176- logger . debug ( { event, properties, distinctId } , `[analytics] ${ event } ` )
186+ logAnalyticsDebug ( `[analytics] ${ event } ` , {
187+ event,
188+ properties,
189+ distinctId,
190+ } )
177191 }
178192 return
179193 }
@@ -212,10 +226,11 @@ export function identifyUser(userId: string, properties?: Record<string, any>) {
212226
213227 if ( ! isProd ) {
214228 if ( DEBUG_ANALYTICS ) {
215- logger . debug (
216- { userId, previousAnonymousId, properties } ,
217- '[analytics] user identified' ,
218- )
229+ logAnalyticsDebug ( '[analytics] user identified' , {
230+ userId,
231+ previousAnonymousId,
232+ properties,
233+ } )
219234 }
220235 return
221236 }
0 commit comments