@@ -50,41 +50,37 @@ export class Experiment {
5050 currentActiveExperiments : Set < string > ,
5151 experimentInfoMap : Map < string , FirebaseExperimentDescription >
5252 ) : void {
53+ const customProperty : Record < string , string | null > = { } ;
5354 for ( const [ experimentId , experimentInfo ] of experimentInfoMap . entries ( ) ) {
5455 if ( ! currentActiveExperiments . has ( experimentId ) ) {
55- void this . addExperimentToAnalytics (
56- experimentId ,
57- experimentInfo . variantId
58- ) ;
56+ customProperty [ experimentId ] = experimentInfo . variantId ;
5957 }
6058 }
59+ void this . addExperimentToAnalytics ( customProperty ) ;
6160 }
6261
6362 private removeInactiveExperiments (
6463 currentActiveExperiments : Set < string > ,
6564 experimentInfoMap : Map < string , FirebaseExperimentDescription >
6665 ) : void {
66+ const customProperty : Record < string , string | null > = { } ;
6767 for ( const experimentId of currentActiveExperiments ) {
6868 if ( ! experimentInfoMap . has ( experimentId ) ) {
69- void this . removeExperimentFromAnalytics ( experimentId ) ;
69+ customProperty [ experimentId ] = null ;
7070 }
7171 }
72+ void this . addExperimentToAnalytics ( customProperty ) ;
7273 }
7374
7475 private async addExperimentToAnalytics (
75- experimentId : string ,
76- variantId : string | null
76+ customProperty : Record < string , string | null >
7777 ) : Promise < void > {
78- const analytics = await this . analyticsProvider . get ( ) ;
79- const customProperty = {
80- [ experimentId ] : variantId
81- } ;
82- analytics . setUserProperties ( { properties : customProperty } ) ;
83- }
84-
85- private async removeExperimentFromAnalytics (
86- experimentId : string
87- ) : Promise < void > {
88- void this . addExperimentToAnalytics ( experimentId , null ) ;
78+ try {
79+ const analytics = await this . analyticsProvider . get ( ) ;
80+ analytics . setUserProperties ( { properties : customProperty } ) ;
81+ } catch ( error ) {
82+ console . error ( `Failed to add experiment to analytics :` , error ) ;
83+ return ;
84+ }
8985 }
9086}
0 commit comments