Conversation
🦋 Changeset detectedLatest commit: cf6e3d8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello @athiramanu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances Firebase Remote Config by adding full web support for A/B Testing and Rollouts. It modifies the core data structures to accommodate experiment metadata, introduces a dedicated class for managing the lifecycle of these experiments, and integrates with Firebase Analytics to provide crucial user property tracking. These changes allow web applications to leverage Remote Config for advanced experimentation and controlled feature rollouts, aligning the web SDK with capabilities available on other platforms. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces web support for A/B Testing and Rollouts in Remote Config. The changes include updating the fetch response to include experiment details, storing these details in IndexedDB, and setting experiment data as user properties in Firebase Analytics. The implementation looks solid, but I have a few suggestions to improve documentation, API design, and code efficiency. Specifically, I've recommended using TSDoc for better public API documentation, refining the Experiment class for better performance, and cleaning up a minor redundancy in the tests.
| // (undocumented) | ||
| affectedParameterKeys?: string[]; | ||
| // (undocumented) | ||
| experimentId: string; | ||
| // (undocumented) | ||
| experimentStartTime: string; | ||
| // (undocumented) | ||
| timeToLiveMillis: string; | ||
| // (undocumented) | ||
| triggerTimeoutMillis: string; | ||
| // (undocumented) | ||
| variantId: string; |
There was a problem hiding this comment.
The properties of the FirebaseExperimentDescription interface are marked as (undocumented). This is likely because the source code in packages/remote-config/src/public_types.ts uses // comments instead of TSDoc blocks (/** ... */). To ensure the public API is properly documented, please update the comments to TSDoc format. This will allow the API extractor to generate complete documentation.
| | [affectedParameterKeys](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptionaffectedparameterkeys) | string\[\] | | | ||
| | [experimentId](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptionexperimentid) | string | | | ||
| | [experimentStartTime](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptionexperimentstarttime) | string | | | ||
| | [timeToLiveMillis](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptiontimetolivemillis) | string | | | ||
| | [triggerTimeoutMillis](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptiontriggertimeoutmillis) | string | | | ||
| | [variantId](./remote-config.firebaseexperimentdescription.md#firebaseexperimentdescriptionvariantid) | string | | |
There was a problem hiding this comment.
The property descriptions in this generated documentation file are empty. This is a result of the API extractor not picking up the comments from the source interface (FirebaseExperimentDescription in packages/remote-config/src/public_types.ts). To fix this, the comments in the source file should be converted to TSDoc format (/** ... */).
| async updateActiveExperiments( | ||
| latestExperiments: FirebaseExperimentDescription[] | ||
| ): Promise<void> { | ||
| const currentActiveExperiments = | ||
| (await this.storage.getActiveExperiments()) || new Set<string>(); | ||
| const experimentInfoMap = this.createExperimentInfoMap(latestExperiments); | ||
| this.addActiveExperiments(experimentInfoMap); | ||
| this.removeInactiveExperiments(currentActiveExperiments, experimentInfoMap); | ||
| return this.storage.setActiveExperiments(new Set(experimentInfoMap.keys())); | ||
| } |
There was a problem hiding this comment.
The updateActiveExperiments method currently calls addActiveExperiments and removeInactiveExperiments, which results in two separate calls to analytics.setUserProperties. This can be optimized by consolidating the logic to build a single map of property changes and making only one call to setUserProperties. This improves both performance and code clarity.
With the suggested change below, the addActiveExperiments and removeInactiveExperiments methods will no longer be needed and can be removed.
async updateActiveExperiments(
latestExperiments: FirebaseExperimentDescription[]
): Promise<void> {
const currentActiveExperiments =
(await this.storage.getActiveExperiments()) || new Set<string>();
const experimentInfoMap = this.createExperimentInfoMap(latestExperiments);
const customProperties: Record<string, string | null> = {};
// Set properties for all latest experiments.
for (const [experimentId, experimentInfo] of experimentInfoMap.entries()) {
customProperties[`firebase${experimentId}`] = experimentInfo.variantId;
}
// Set null for experiments that are no longer active.
for (const experimentId of currentActiveExperiments) {
if (!experimentInfoMap.has(experimentId)) {
customProperties[`firebase${experimentId}`] = null;
}
}
this.addExperimentToAnalytics(customProperties);
return this.storage.setActiveExperiments(new Set(experimentInfoMap.keys()));
}| export interface FirebaseExperimentDescription { | ||
| // A string of max length 22 characters and of format: _exp_<experiment_id> | ||
| experimentId: string; | ||
|
|
||
| // The variant of the experiment assigned to the app instance. | ||
| variantId: string; | ||
|
|
||
| // When the experiment was started. | ||
| experimentStartTime: string; | ||
|
|
||
| // How long the experiment can remain in STANDBY state. Valid range from 1 ms | ||
| // to 6 months. | ||
| triggerTimeoutMillis: string; | ||
|
|
||
| // How long the experiment can remain in ON state. Valid range from 1 ms to 6 | ||
| // months. | ||
| timeToLiveMillis: string; | ||
|
|
||
| // Which all parameters are affected by this experiment. | ||
| affectedParameterKeys?: string[]; | ||
| } |
There was a problem hiding this comment.
The comments for the properties within FirebaseExperimentDescription are using // which are not picked up by API documentation generators. To ensure these are properly documented, they should be converted to TSDoc format (/** ... */).
Additionally, properties like triggerTimeoutMillis and timeToLiveMillis are defined as string. For better type safety and clarity in a public API, consider using the number type for millisecond values. If they must remain strings (e.g., to handle 64-bit integers without precision loss), this should be clearly explained in their TSDoc comments.
export interface FirebaseExperimentDescription {
/** A string of max length 22 characters and of format: _exp_<experiment_id> */
experimentId: string;
/** The variant of the experiment assigned to the app instance. */
variantId: string;
/** When the experiment was started. This is a UTC timestamp in ISO 8601 format. */
experimentStartTime: string;
/**
* How long the experiment can remain in STANDBY state.
* This is a string representation of a duration in milliseconds.
*/
triggerTimeoutMillis: string;
/**
* How long the experiment can remain in ON state.
* This is a string representation of a duration in milliseconds.
*/
timeToLiveMillis: string;
/** Which all parameters are affected by this experiment. */
affectedParameterKeys?: string[];
}| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); |
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
Co-authored-by: Athira M <athiramanu@google.com>
This change is part of the feature to support Web Experiments in Remote Config. Changes can be broken down as below:
Introduces the experiment details in the fetch response type
Extracts experiments received from the fetch response and saves in indexedDB
Sets the experiment and variant received as user property
Design doc (internal): go/experiments-web