File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed
Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,12 @@ import { Storage } from '../storage/storage';
1818import { FirebaseExperimentDescription } from '../public_types' ;
1919import { Provider } from '@firebase/component' ;
2020import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types' ;
21+ import { Logger } from '@firebase/logger' ;
2122
2223export class Experiment {
2324 constructor (
2425 private readonly storage : Storage ,
26+ private readonly logger : Logger ,
2527 private readonly analyticsProvider : Provider < FirebaseAnalyticsInternalName >
2628 ) { }
2729
@@ -76,10 +78,14 @@ export class Experiment {
7678 customProperty : Record < string , string | null >
7779 ) : Promise < void > {
7880 try {
79- const analytics = await this . analyticsProvider . get ( ) ;
80- analytics . setUserProperties ( { properties : customProperty } ) ;
81+ const analytics = this . analyticsProvider . getImmediate ( { optional : true } ) ;
82+ if ( analytics ) {
83+ analytics . setUserProperties ( { properties : customProperty } ) ;
84+ } else {
85+ this . logger . warn ( `Analytics is not imported correctly` ) ;
86+ }
8187 } catch ( error ) {
82- console . error ( `Failed to add experiment to analytics :` , error ) ;
88+ this . logger . error ( `Failed to add experiment to analytics : ${ error } ` ) ;
8389 return ;
8490 }
8591 }
Original file line number Diff line number Diff line change @@ -111,7 +111,11 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
111111 // config.
112112 return false ;
113113 }
114- const experiment = new Experiment ( rc . _storage , rc . _analyticsProvider ) ;
114+ const experiment = new Experiment (
115+ rc . _storage ,
116+ rc . _logger ,
117+ rc . _analyticsProvider
118+ ) ;
115119 const updateActiveExperiments = lastSuccessfulFetchResponse . experiments
116120 ? experiment . updateActiveExperiments (
117121 lastSuccessfulFetchResponse . experiments
Original file line number Diff line number Diff line change @@ -22,11 +22,13 @@ import { FirebaseExperimentDescription } from '../../src/public_types';
2222import { Storage } from '../../src/storage/storage' ;
2323import { Provider } from '@firebase/component' ;
2424import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types' ;
25+ import { Logger } from '@firebase/logger' ;
2526
2627describe ( 'Experiment' , ( ) => {
2728 const storage = { } as Storage ;
2829 const analyticsProvider = { } as Provider < FirebaseAnalyticsInternalName > ;
29- const experiment = new Experiment ( storage , analyticsProvider ) ;
30+ const logger = { } as Logger ;
31+ const experiment = new Experiment ( storage , logger , analyticsProvider ) ;
3032
3133 describe ( 'updateActiveExperiments' , ( ) => {
3234 beforeEach ( ( ) => {
You can’t perform that action at this time.
0 commit comments