invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

🔥 remote config variables don't change when using conditionals or AB Testing #3378

Closed tutts closed 4 years ago

tutts commented 4 years ago

Issue

Describe your issue here

Hello, after identifying my user properties through analytics, I attempt to fetch the remote configs. These configs are returned however they're always the default values, and not the values I have setup as conditionals/AB tests for certain users.

I can run reports based on the user properties within Firebase, so I know it has data and its tracking correctly.

Any help greatly appreciated! Thanks 🙌🏻

Project Files

Javascript

Click To Expand

Called before loading the remote configs: ```javascript async componentDidMount() { try { await remoteConfig().setConfigSettings({ isDeveloperModeEnabled: __DEV__, minimumFetchInterval: 300, // 5 minutes }) } catch (error) { Sentry.captureException(error) } } ``` later in a saga when the user logs in: (note `activated` is always false, I attempted a workaround in another issue to`fetch` and `activate` separately but its still false.) ```javascript try { await analytics().setUserId(String(id)) await firebase.analytics().setUserProperties({ id: String(id), email, displayName, transportMode, }) const activated = await firebase.remoteConfig().fetchAndActivate() // activated always returns false if (!activated) { await remoteConfig().fetch() await remoteConfig().activate() } } catch (error) { Sentry.captureException(error) } ``` #### `package.json`: ```json "@react-native-firebase/analytics": "6.3.4", "@react-native-firebase/app": "6.3.4", "@react-native-firebase/perf": "6.3.4", "@react-native-firebase/remote-config": "6.3.4", "react": "16.9.0", "react-native": "0.61.5" ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "analytics_auto_collection_enabled": true, "database_persistence_enabled": true, "perf_auto_collection_enabled": true } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'driver' do # Pods for driver pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" pod 'React', :path => '../node_modules/react-native/' pod 'React-Core', :path => '../node_modules/react-native/' pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon" pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "React" target.remove_from_project end end end use_native_modules! end ``` #### `AppDelegate.m`: ```objc /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ @import Firebase; #import #import "AppDelegate.h" #import #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } // RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"driver" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } // Required to register for notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RNCPushNotificationIOS didReceiveLocalNotification:notification]; } @end ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS Mojave 10.14.5 CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Memory: 333.37 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.18.1 - ~/.nvm/versions/node/v10.18.1/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v10.18.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 23, 24, 25, 26, 27, 28, 29 Build Tools: 27.0.3, 28.0.3 System Images: android-26 | Google APIs Intel x86 Atom Android NDK: 16.0.4442984 IDEs: Android Studio: 3.0 AI-171.4443003 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [X] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.3.4` - **`Firebase` module(s) you're using that has the issue:** - `remote-config` - **Are you using `TypeScript`?** - `No`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

russellwheatley commented 4 years ago

The fact that your values are never fetched would suggest it is something with your remote-config/firebase project setup. I'd start a clean RN project, install only the app & remote-config packages & go through the setup process again.

tutts commented 4 years ago

hi @russellwheatley, thanks for taking time to help here. To clarify though, the values are returned successfully, however they're the default values, i.e. they're the opposite of what I want because I have conditionals/AB tests running thats meant to alter them. For example:

// returns
// { value: false, source: 'remote' }
const scanDropEnabled = await remoteConfig().getValue('drop_select_scanning')

however it should return true because I have the following conditional setup:

image

image

I'm not sure if the disconnect is either my understanding/configuration of firebase, or if theres a genuine issue here, is there a recommended approach to help debug natively?

tutts commented 4 years ago

closing this one, managed to get it to work, I'm not 100% sure what the change was that fixed it, but pretty sure it was either a caching issue, or I had an async issue where the component was loading before Firebase setup the config.

pramahaditamaputra commented 1 year ago

hi @russellwheatley, thanks for taking time to help here. To clarify though, the values are returned successfully, however they're the default values, i.e. they're the opposite of what I want because I have conditionals/AB tests running thats meant to alter them. For example:

// returns
// { value: false, source: 'remote' }
const scanDropEnabled = await remoteConfig().getValue('drop_select_scanning')

however it should return true because I have the following conditional setup:

image

image

I'm not sure if the disconnect is either my understanding/configuration of firebase, or if theres a genuine issue here, is there a recommended approach to help debug natively?

Hi @tutts do you have any idea to implement this for more than 1 user ?

pramahaditamaputra commented 1 year ago

Hi Guys,

I have a plan to do an A/B test with targeting segmented user with data from Custom User Property Analytics

in custom User Property it just support value string or number with limit 36 char, so i can't put object or array on it

let say i set the value with string 12,121,1212

how to achieve condition only true for user 12 and the 121,1212 will not true ?

i tried with this

Screen Shot 2023-01-27 at 17 23 12

but the condition will also true for 121 and 1212 too

any suggestion for achieve this ?

mikehardy commented 1 year ago

This is an issue closed for a few years - as mentioned in a separate issue you opened I am not sure this is react-native-firebase specific? I could be wrong if so please demonstrate how, otherwise I think this is probably best on stack overflow tagged up appropriately so the firebase team notices it