@@ -947,24 +947,18 @@ const Flagsmith = class {
947947 this . updateEventStorage ( ) ;
948948 } ;
949949
950- private requireEventProcessor ( ) : EventProcessor {
951- if ( ! this . eventProcessor ) {
952- throw new Error ( 'Flagsmith: events must be enabled (enableEvents: true) to use this method.' ) ;
953- }
954- return this . eventProcessor ;
955- }
956-
957950 trackEvent = ( event : string , opts ?: {
958951 identifier ?: string | null ;
959952 value ?: IFlagsmithValue ;
960953 traits ?: ITraits ;
961954 metadata ?: Record < string , unknown > ;
962955 } ) => {
963- const processor = this . requireEventProcessor ( ) ;
956+ // No-op when events are disabled, mirroring enableAnalytics: false.
957+ if ( ! this . eventProcessor ) return ;
964958 if ( event . startsWith ( '$' ) ) {
965959 throw new Error ( `Flagsmith: event names starting with "$" are reserved; use trackExposureEvent to record "${ FLAG_EXPOSURE_EVENT } ".` ) ;
966960 }
967- processor . trackEvent ( {
961+ this . eventProcessor . trackEvent ( {
968962 event,
969963 identifier : opts ?. identifier ?? this . evaluationContext . identity ?. identifier ?? null ,
970964 value : opts ?. value ?? null ,
@@ -979,8 +973,9 @@ const Flagsmith = class {
979973 traits ?: ITraits ;
980974 metadata ?: Record < string , unknown > ;
981975 } ) => {
982- const processor = this . requireEventProcessor ( ) ;
983- processor . trackExposureEvent ( {
976+ // No-op when events are disabled, mirroring enableAnalytics: false.
977+ if ( ! this . eventProcessor ) return ;
978+ this . eventProcessor . trackExposureEvent ( {
984979 featureName,
985980 identifier : opts ?. identifier ?? this . evaluationContext . identity ?. identifier ?? null ,
986981 value : opts ?. value ?? null ,
@@ -992,9 +987,10 @@ const Flagsmith = class {
992987 flushEvents = ( ) : Promise < void > => this . eventProcessor ? this . eventProcessor . flush ( ) : Promise . resolve ( ) ;
993988
994989 getExperimentFlag = ( featureName : string ) : IFlagsmithFeature | null => {
995- this . requireEventProcessor ( ) ;
996990 const key = featureName . toLowerCase ( ) . replace ( / / g, '_' ) ;
997991 const flag = ( this . flags && this . flags [ key ] ) || null ;
992+ // When events are disabled this degrades to a plain flag read.
993+ if ( ! this . eventProcessor ) return flag ;
998994 const identifier = this . evaluationContext . identity ?. identifier ;
999995 if ( ! identifier ) {
1000996 this . log ( 'Flagsmith: getExperimentFlag called without an identity; call identify() (optionally with transient: true) before using experiments to record an exposure. Returning environment flags; no exposure recorded.' ) ;
0 commit comments