Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 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[`firebase${experimentId}`] = experimentInfo.variantId;
}
this.addExperimentToAnalytics(customProperty);
}
Expand All @@ -74,7 +71,7 @@ export class Experiment {
const customProperty: Record<string, string | null> = {};
for (const experimentId of currentActiveExperiments) {
if (!experimentInfoMap.has(experimentId)) {
customProperty[experimentId] = null;
customProperty[`firebase${experimentId}`] = null;
}
}
this.addExperimentToAnalytics(customProperty);
Expand All @@ -89,7 +86,8 @@ export class Experiment {
try {
const analytics = this.analyticsProvider.getImmediate({ optional: true });
if (analytics) {
analytics.setUserProperties({ properties: customProperty });
analytics.setUserProperties(customProperty);
analytics.logEvent(`set_firebase_experiment_state`);
} else {
this.logger.warn(`Analytics import failed`);
}
Expand Down
9 changes: 6 additions & 3 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,9 @@ describe('Experiment', () => {
expectedStoredExperiments
);
expect(analytics.setUserProperties).to.have.been.calledWith({
properties: { '_exp_3': '1' }
'firebase_exp_3': '1',
'firebase_exp_1': '2',
'firebase_exp_2': '1'
});
});

Expand All @@ -107,7 +110,7 @@ describe('Experiment', () => {
expectedStoredExperiments
);
expect(analytics.setUserProperties).to.have.been.calledWith({
properties: { '_exp_2': null }
'firebase_exp_2': null
});
});
});
Expand Down
Loading