FR: Support for targeting user properties in real time with Remote Config (parity with iOS & Android SDKs)
Operating System
MacOS
Environment (if applicable)
Any browser
Firebase SDK Version
10.9.0
Firebase SDK Product(s)
Analytics, Remote-Config
Project Tooling
Elm app
Detailed Problem Description
Our app has mobile clients on iOS and Android which use firebase-ios-sdk and firebase-android-sdk for feature flagging. The way feature flagging works on those platforms is:
- we have parameters in Remote Config with conditions based on user properties (something like
app.userProperty['some_prop'].exactlyMatches(['some_value'])) - when a user logs in, we set the user property
- we then fetch the Remote Config with a
minimumFetchIntervalof0and activate to get the updated values specific to that user
We recently implemented a web app that uses the firebase-js-sdk and realized that this approach to feature flagging is not supported on Web because there's a delay between setting the user property and seeing the correct Remote Config value for that user property in the response from getValue.
This has been reported as a bug a few times already:
- https://github.com/firebase/firebase-js-sdk/issues/8334
- https://github.com/firebase/firebase-js-sdk/issues/2990
- https://github.com/firebase/firebase-js-sdk/issues/3230
- https://github.com/firebase/firebase-js-sdk/issues/2221
The response to the bug reports has been that this is expected behavior, and it is noted in the documentation that the JS SDK differs from the mobile SDKs on this. (I think that's what this is saying:
Note: On Web, it can take several hours for a property to be available for targeting. See the documentation for user properties on Web/JavaScript for more information.
?)
I'm submitting this as a feature request in case there's any plan of supporting this functionality in the web/JS SDK.
Steps and code to reproduce issue
See the repro steps here and here:
- create a user property in Remote Config (
foo) - create a condition matching on that property (
app.userProperty['foo'].exactlyMatches(['bar'])) and a string parameterbazthat branches on that condition to return values'foo is bar'when the condition is true,'default value'as default - fetch and activate Remote Config from a JS client using
remoteConfig.settings.minimumFetchIntervalMillis = 0 - set user property (call
setUserProperty(analytics, { foo: 'bar' })) - fetch and activate again (call
fetchAndActivate(remoteConfig)) - see that the boolean returned is
falseindicating the config did not activate despite new user property - call
getValue(remoteConfig, 'baz') - see that the value is the default
'default value'
We did find that remote config firebase API request is different on web vs Mobile. Mobile in the request for remote config firebase API request appends the user properties in the body in this format "analyticsUserProperties":{"XXX":"YYYY"} It would be great if the remote config library supported this on web as otherwise we lose the ability to have user properties reflect immediately.
I would think that it would require caching the user properties and sending it via the request.
Also if there is any other work arounds you can suggest for web let us know. If we could somehow manually call this route or append params to the body easily that would be helpful.
For anyone else who runs into this issue, I've forked the firebase-js-sdk repo and made a PR here with the minimal changes necessary to allow you to specify analytics user properties when calling fetchConfig or fetchAndActivate. This circumvents the issue by telling the remote config backend what the user properties are synchronously in the request rather than waiting for the remote config backend to be notified about changes to user properties asynchronously. The easiest way to get these changes into your project is probably by using patch-package to apply my changes to the firebase package in node_modules during the postinstall phase of installing dependencies. The steps roughly are as follows:
- Clone the forked
firebase-js-sdkrepo locally - checkout the branch
fix-remote-config-fetch-config-analytics-user-properties cdintopackages/remote-config- Run
npm install,npm run build, and thennpm link(or do theyarnequivalients) - Switch to your project that depends on
firebase-js-sdk - Run
npm link @firebase/remote-configto install the locally built version of the@firebase/remote-configthat you rannpm linkfor earlier - Run
npm install --save-dev patch-package - Run
npx patch-package @firebase/remote-configto derive the patch file, which you need to check into git - Add
npx patch-packageto yourpackage.scripts.postinstallscript so that the patch gets applied when anyone clones and install your package - Update any call sites of
remoteConfig.fetchConfigorremoteConfig.fetchAndActivateto pass in{ analyticsUserProperies: object }as the second argument.Then when you run or build your project, it should use our forked version of@firebase/remote-configand the staleness issue should be resolved.
Is firebase dead?
This was opened in Dec. 2024 and no reviews or merges…
Hi Pete, Remote Config official support for Realtime in Web is launched now, so now we have realtime with Remote Config available in all major firebase supported client platforms.
Docs: https://firebase.google.com/docs/remote-config/real-time?platform=web Release notes: https://firebase.google.com/support/release-notes/js#remote-config