firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: Support for targeting user properties in real time with Remote Config (parity with iOS & Android SDKs)

Open pete-murphy opened this issue 1 year ago • 3 comments

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 minimumFetchInterval of 0 and 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 parameter baz that 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 false indicating the config did not activate despite new user property
  • call getValue(remoteConfig, 'baz')
  • see that the value is the default 'default value'

pete-murphy avatar Dec 03 '24 18:12 pete-murphy

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.

DavidCorrado avatar Dec 03 '24 18:12 DavidCorrado

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:

  1. Clone the forked firebase-js-sdk repo locally
  2. checkout the branch fix-remote-config-fetch-config-analytics-user-properties
  3. cd into packages/remote-config
  4. Run npm install, npm run build, and then npm link (or do the yarn equivalients)
  5. Switch to your project that depends on firebase-js-sdk
  6. Run npm link @firebase/remote-config to install the locally built version of the @firebase/remote-config that you ran npm link for earlier
  7. Run npm install --save-dev patch-package
  8. Run npx patch-package @firebase/remote-config to derive the patch file, which you need to check into git
  9. Add npx patch-package to your package.scripts.postinstall script so that the patch gets applied when anyone clones and install your package
  10. Update any call sites of remoteConfig.fetchConfig or remoteConfig.fetchAndActivate to 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-config and the staleness issue should be resolved.

derrickbeining avatar Dec 24 '24 16:12 derrickbeining

Is firebase dead?

This was opened in Dec. 2024 and no reviews or merges…

theonetheycallneo avatar Apr 23 '25 23:04 theonetheycallneo

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

tusharkhandelwal8 avatar Sep 22 '25 08:09 tusharkhandelwal8