Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/remote-config/src/abt/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Experiment {
const currentActiveExperiments =
(await this.storage.getActiveExperiments()) || new Set<string>();
const experimentInfoMap = this.createExperimentInfoMap(latestExperiments);
this.addActiveExperiments(currentActiveExperiments, experimentInfoMap);
this.addActiveExperiments(experimentInfoMap);
this.removeInactiveExperiments(currentActiveExperiments, experimentInfoMap);
return this.storage.setActiveExperiments(new Set(experimentInfoMap.keys()));
}
Expand All @@ -55,14 +55,11 @@ export class Experiment {
}

private addActiveExperiments(
currentActiveExperiments: Set<string>,
experimentInfoMap: Map<string, FirebaseExperimentDescription>
): void {
const customProperty: Record<string, string | null> = {};
for (const [experimentId, experimentInfo] of experimentInfoMap.entries()) {
if (!currentActiveExperiments.has(experimentId)) {
customProperty[experimentId] = experimentInfo.variantId;
}
customProperty[experimentId] = experimentInfo.variantId;
}
this.addExperimentToAnalytics(customProperty);
}
Expand Down Expand Up @@ -90,6 +87,7 @@ export class Experiment {
const analytics = this.analyticsProvider.getImmediate({ optional: true });
if (analytics) {
analytics.setUserProperties({ properties: customProperty });
analytics.logEvent(`Received ABT experiment update`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are event names allowed to have spaces? I think it might be safer to use "set_firebase_experiment_state" as Sam suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else {
this.logger.warn(`Analytics import failed`);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/remote-config/test/abt/experiment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe('Experiment', () => {
storage.getActiveExperiments = sinon.stub();
storage.setActiveExperiments = sinon.stub();
analyticsProvider.getImmediate = sinon.stub().returns({
setUserProperties: sinon.stub()
setUserProperties: sinon.stub(),
logEvent: sinon.stub()
});
});

Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Experiment', () => {
expectedStoredExperiments
);
expect(analytics.setUserProperties).to.have.been.calledWith({
properties: { '_exp_3': '1' }
properties: { '_exp_3': '1', '_exp_1': '2', '_exp_2': '1' }
});
});

Expand Down
Loading