-
Notifications
You must be signed in to change notification settings - Fork 973
Integrate experiments with firebase analytics internal #9278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
athiramanu
wants to merge
29
commits into
web-experiment
Choose a base branch
from
web-exp-ga
base: web-experiment
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−19
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2ec305d
feat: Process experiment metadata in RC fetch response
5eb6b8d
feat: Add ABT support for remote config
08c8863
feat: Integrate firebase internal analytics with ABT
4af3eb9
Merge branch 'web-experiment' into web-exp-fetch
b6f2ac9
Merge branch 'web-exp-fetch' into web-exp-abt
55db6e0
Merge branch 'web-exp-abt' into web-exp-ga
24848c4
[Fix] Storage cache is not updating when there are no experiments in …
455b8e3
[Fix] Update experiments after checking fetch response
e2024d7
Merge branch 'web-exp-abt' into web-exp-ga
bec6e56
feat: Process experiment metadata in RC fetch response
ee703b9
[Fix] Storage cache is not updating when there are no experiments in …
7c67f85
Add result of running yarn docgen:all
06398f6
feat: Process experiment metadata in RC fetch response
fd049e2
feat: Add ABT support for remote config
638cc2c
[Fix] Storage cache is not updating when there are no experiments in …
900eff5
Merge conflict fix
432ac24
Yarn format fix
ccc71e1
Fix merge conflicts
5836eaf
merge web-exp-abt
6be23df
Integrate ABT with Firebase analytics to add experiment as UP
66b104b
Fix yarn format errors
b289636
Address review comments
d3e0838
Fix yarn format failures
aa7751e
yarn docgen changes added
19c0fd6
Export firebaseExperimentDescription
b3f5fa1
Merge branch 'web-exp-fetch' into web-exp-abt
27cb4b2
Merge branch 'web-exp-abt' into web-exp-ga
d09a338
Merge branch 'web-experiment' into web-exp-ga
4c19690
Address review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,14 @@ | |
*/ | ||
import { Storage } from '../storage/storage'; | ||
import { FirebaseExperimentDescription } from '../public_types'; | ||
import { Provider } from '@firebase/component'; | ||
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types'; | ||
|
||
export class Experiment { | ||
constructor(private readonly storage: Storage) {} | ||
constructor( | ||
private readonly storage: Storage, | ||
private readonly analyticsProvider: Provider<FirebaseAnalyticsInternalName> | ||
) {} | ||
|
||
async updateActiveExperiments( | ||
latestExperiments: FirebaseExperimentDescription[] | ||
|
@@ -45,32 +50,37 @@ export class Experiment { | |
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)) { | ||
this.addExperimentToAnalytics(experimentId, experimentInfo.variantId); | ||
customProperty[experimentId] = experimentInfo.variantId; | ||
} | ||
} | ||
void this.addExperimentToAnalytics(customProperty); | ||
} | ||
|
||
private removeInactiveExperiments( | ||
currentActiveExperiments: Set<string>, | ||
experimentInfoMap: Map<string, FirebaseExperimentDescription> | ||
): void { | ||
const customProperty: Record<string, string | null> = {}; | ||
for (const experimentId of currentActiveExperiments) { | ||
if (!experimentInfoMap.has(experimentId)) { | ||
this.removeExperimentFromAnalytics(experimentId); | ||
customProperty[experimentId] = null; | ||
} | ||
} | ||
void this.addExperimentToAnalytics(customProperty); | ||
} | ||
|
||
private addExperimentToAnalytics( | ||
_experimentId: string, | ||
_variantId: string | ||
): void { | ||
// TODO | ||
} | ||
|
||
private removeExperimentFromAnalytics(_experimentId: string): void { | ||
// TODO | ||
private async addExperimentToAnalytics( | ||
customProperty: Record<string, string | null> | ||
): Promise<void> { | ||
try { | ||
const analytics = await this.analyticsProvider.get(); | ||
analytics.setUserProperties({ properties: customProperty }); | ||
} catch (error) { | ||
console.error(`Failed to add experiment to analytics :`, error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use |
||
return; | ||
} | ||
} | ||
athiramanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think we talked about this before, but being able to use this requires the developer to have called
import { anything } from 'firebase/analytics'
. If they don't, this line will hang. I'm actually a little concerned about the messaging implementation (the pattern you took this from) running into this. I think the best way to handle this might be to usegetImmediate({ optional: true })
instead. Example: https://github.com/firebase/firebase-js-sdk/blob/main/packages/storage/src/service.ts#L286This returns undefined if the developer did not import 'firebase/analytics'. You could use that to log a warning message, or continue if it was found. You'd also want to make it clear in documentation that users that use this feature must also import and initialize analytics.