@@ -19,13 +19,19 @@ import { FirebaseExperimentDescription } from '../public_types';
1919import { Provider } from '@firebase/component' ;
2020import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types' ;
2121import { Logger } from '@firebase/logger' ;
22+ import { RemoteConfig } from '../remote_config' ;
23+ import { ERROR_FACTORY , ErrorCode } from '../errors' ;
2224
2325export class Experiment {
24- constructor (
25- private readonly storage : Storage ,
26- private readonly logger : Logger ,
27- private readonly analyticsProvider : Provider < FirebaseAnalyticsInternalName >
28- ) { }
26+ private storage : Storage ;
27+ private logger : Logger ;
28+ private analyticsProvider : Provider < FirebaseAnalyticsInternalName > ;
29+
30+ constructor ( rc : RemoteConfig ) {
31+ this . storage = rc . _storage ;
32+ this . logger = rc . _logger ;
33+ this . analyticsProvider = rc . _analyticsProvider ;
34+ }
2935
3036 async updateActiveExperiments (
3137 latestExperiments : FirebaseExperimentDescription [ ]
@@ -58,7 +64,7 @@ export class Experiment {
5864 customProperty [ experimentId ] = experimentInfo . variantId ;
5965 }
6066 }
61- void this . addExperimentToAnalytics ( customProperty ) ;
67+ this . addExperimentToAnalytics ( customProperty ) ;
6268 }
6369
6470 private removeInactiveExperiments (
@@ -71,22 +77,29 @@ export class Experiment {
7177 customProperty [ experimentId ] = null ;
7278 }
7379 }
74- void this . addExperimentToAnalytics ( customProperty ) ;
80+ this . addExperimentToAnalytics ( customProperty ) ;
7581 }
7682
77- private async addExperimentToAnalytics (
83+ private addExperimentToAnalytics (
7884 customProperty : Record < string , string | null >
79- ) : Promise < void > {
85+ ) : void {
86+ if ( Object . keys ( customProperty ) . length === 0 ) {
87+ return ;
88+ }
8089 try {
8190 const analytics = this . analyticsProvider . getImmediate ( { optional : true } ) ;
8291 if ( analytics ) {
8392 analytics . setUserProperties ( { properties : customProperty } ) ;
8493 } else {
94+ // TODO: Update warning message
8595 this . logger . warn ( `Analytics is not imported correctly` ) ;
8696 }
8797 } catch ( error ) {
98+ // TODO: Update error message
8899 this . logger . error ( `Failed to add experiment to analytics : ${ error } ` ) ;
89- return ;
100+ throw ERROR_FACTORY . create ( ErrorCode . ANALYTICS_UNAVAILABLE , {
101+ originalErrorMessage : ( error as Error ) ?. message
102+ } ) ;
90103 }
91104 }
92105}
0 commit comments