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.69k stars 2.21k forks source link

🔥Analytics().setUserProperty() never resolves #3672

Closed casconed closed 4 years ago

casconed commented 4 years ago

Issue

Describe your issue here analytics().setUserProperty('key', 'value') does not resolve

I have an onClick handler that looks like this:

  const onValueChange = async (newValue, id) => {
    console.log('above')
    const result = await analytics().setUserProperty('myKey', newValue)
    console.log('after', result)
  }

I get above in my logs, but I never get after. With -FIRDebugEnabled i can see things like the result of setUserId in the stream but no custom events.

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "scripts": { "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "web": "expo start --web", "travis": "standard" }, "jest": { "preset": "react-native", "setupFiles": [ "/scripts/jest/setup.js" ], "transform": { "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest" }, "transformIgnorePatterns": [ "node_modules/(?!(react-native|react-navigation|expo-web-browser|@unimodules|@react-native-firebase|@react-navigation|@react-native-community))" ] }, "dependencies": { "@expo/samples": "~36.0.0", "@expo/vector-icons": "~10.0.0", "@react-native-community/async-storage": "^1.7.1", "@react-native-community/blur": "^3.6.0", "@react-native-community/datetimepicker": "^2.3.2", "@react-native-community/google-signin": "^4.0.3", "@react-native-community/netinfo": "^5.7.1", "@react-native-firebase/analytics": "^6.7.2", "@react-native-firebase/app": "^6.7.1", "@react-native-firebase/auth": "^6.7.1", "@react-native-firebase/crashlytics": "^6.7.1", "@react-native-firebase/firestore": "^6.7.1", "@react-native-firebase/functions": "^6.8.1", "@react-native-firebase/messaging": "^6.7.1", "@react-native-firebase/remote-config": "^6.7.1", "@react-navigation/native": "^5.4.0", "@react-navigation/web": "~1.0.0-alpha.9", "expo": "~36.0.0", "expo-analytics-amplitude": "^8.1.0", "expo-asset": "~8.0.0", "expo-constants": "~8.0.0", "expo-font": "~8.0.0", "expo-web-browser": "^8.0.0", "json-stringify": "^1.0.0", "libphonenumber-js": "^1.7.31", "lodash": "^4.17.15", "metro-config": "latest", "moment": "^2.24.0", "react": "^16.11.0", "react-dom": "~16.9.0", "react-native": "^0.62.1", "react-native-config": "^0.12.0", "react-native-default-preference": "^1.4.2", "react-native-fbsdk": "^1.1.2", "react-native-gesture-handler": "^1.5.6", "react-native-loading-spinner-overlay": "^1.1.0", "react-native-modal": "^11.5.6", "react-native-reanimated": "^1.4.0", "react-native-screens": "2.0.0-alpha.12", "react-native-svg": "^10.0.0", "react-native-svg-transformer": "^0.14.3", "react-native-swipe-gestures": "^1.0.4", "react-native-touch-id": "^4.4.1", "react-native-ui-lib": "^5.6.1", "react-native-unimodules": "~0.7.0", "react-navigation": "~4.0.10", "react-navigation-stack": "~1.10.3", "toggle-switch-react-native": "^2.1.0" }, "devDependencies": { "@babel/core": "^7.9.6", "@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/plugin-transform-destructuring": "^7.8.3", "@babel/plugin-transform-flow-strip-types": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/preset-flow": "^7.8.3", "@babel/preset-react": "^7.8.3", "@babel/runtime": "^7.9.6", "babel-jest": "^24.9.0", "babel-polyfill": "^6.26.0", "babel-preset-expo": "~8.0.0", "babel-preset-react": "^6.24.1", "babel-preset-react-native": "^4.0.1", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.2", "eslint-config-standard": "^14.1.1", "eslint-plugin-import": "^2.20.2", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", "husky": "^4.2.5", "jest-expo": "~36.0.1", "lint-staged": "^10.2.2", "metro-react-native-babel-preset": "^0.58.0", "prettier-standard": "^16.3.0", "react-native-babel-jest": "^0.2.1", "react-test-renderer": "^16.11.0", "standard": "^14.3.1" }, "husky": { "hooks": { "pre-commit": "lint-staged" } }, "standard": { "env": [ "jest" ], "options": { "enable": true, "parser": "babel-eslint" } }, "lint-staged": { "*.js": [ "prettier-standard" ] }, "private": true } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby platform :ios, '10.0' require_relative '../node_modules/react-native-unimodules/cocoapods' def add_flipper_pods! version = '~> 0.33.1' pod 'FlipperKit', version, :configuration => 'Debug' pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug' pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug' pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug' pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug' end # Post Install processing for Flipper def flipper_post_install(installer) installer.pods_project.targets.each do |target| if target.name == 'YogaKit' target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.1' end end end end target 'Sparkles' do rnPrefix = "../node_modules/react-native" # React Native and its dependencies pod 'FBLazyVector', :path => "#{rnPrefix}/Libraries/FBLazyVector" pod 'FBReactNativeSpec', :path => "#{rnPrefix}/Libraries/FBReactNativeSpec" pod 'RCTRequired', :path => "#{rnPrefix}/Libraries/RCTRequired" pod 'RCTTypeSafety', :path => "#{rnPrefix}/Libraries/TypeSafety" pod 'React', :path => "#{rnPrefix}/" pod 'React-Core', :path => "#{rnPrefix}/" pod 'React-CoreModules', :path => "#{rnPrefix}/React/CoreModules" pod 'React-RCTActionSheet', :path => "#{rnPrefix}/Libraries/ActionSheetIOS" pod 'React-RCTAnimation', :path => "#{rnPrefix}/Libraries/NativeAnimation" pod 'React-RCTBlob', :path => "#{rnPrefix}/Libraries/Blob" pod 'React-RCTImage', :path => "#{rnPrefix}/Libraries/Image" pod 'React-RCTLinking', :path => "#{rnPrefix}/Libraries/LinkingIOS" pod 'React-RCTNetwork', :path => "#{rnPrefix}/Libraries/Network" pod 'React-RCTSettings', :path => "#{rnPrefix}/Libraries/Settings" pod 'React-RCTText', :path => "#{rnPrefix}/Libraries/Text" pod 'React-RCTVibration', :path => "#{rnPrefix}/Libraries/Vibration" pod 'React-Core/RCTWebSocket', :path => "#{rnPrefix}/" pod 'React-Core/DevSupport', :path => "#{rnPrefix}/" pod 'React-cxxreact', :path => "#{rnPrefix}/ReactCommon/cxxreact" pod 'React-jsi', :path => "#{rnPrefix}/ReactCommon/jsi" pod 'React-jsiexecutor', :path => "#{rnPrefix}/ReactCommon/jsiexecutor" pod 'React-jsinspector', :path => "#{rnPrefix}/ReactCommon/jsinspector" pod 'ReactCommon/callinvoker', :path => "#{rnPrefix}/ReactCommon" pod 'ReactCommon/turbomodule/core', :path => "#{rnPrefix}/ReactCommon" pod 'Yoga', :path => "#{rnPrefix}/ReactCommon/yoga", :modular_headers => true pod 'DoubleConversion', :podspec => "#{rnPrefix}/third-party-podspecs/DoubleConversion.podspec" pod 'glog', :podspec => "#{rnPrefix}/third-party-podspecs/glog.podspec" pod 'Folly', :podspec => "#{rnPrefix}/third-party-podspecs/Folly.podspec" # Other native modules pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec' pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec' pod 'RNScreens', :path => '../node_modules/react-native-screens' # Automatically detect installed unimodules use_unimodules! pod 'react-native-config', :path => '../node_modules/react-native-config' pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app' pod 'RNSVG', :path => '../node_modules/react-native-svg' pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage' pod 'RNFBAuth', :path => '../node_modules/@react-native-firebase/auth' pod 'RNFBFirestore', :path => '../node_modules/@react-native-firebase/firestore' pod 'RNFBCrashlytics', :path => '../node_modules/@react-native-firebase/crashlytics' pod 'RNFBRemoteConfig', :path => '../node_modules/@react-native-firebase/remote-config' pod 'RNFBFunctions', :path => '../node_modules/@react-native-firebase/functions' pod 'TouchID', :path => '../node_modules/react-native-touch-id' pod 'RNDefaultPreference', :path => '../node_modules/react-native-default-preference' # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. add_flipper_pods! pod 'react-native-blur', :path => '../node_modules/@react-native-community/blur' pod 'RNDateTimePicker', :path => '../node_modules/@react-native-community/datetimepicker' pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo' pod 'ReactNativeUiLib', :path => '../node_modules/react-native-ui-lib/lib' pod 'RNFBMessaging', :path => '../node_modules/@react-native-firebase/messaging' pod 'Firebase/Messaging', '~> 6.13.0' pod 'RNFBAnalytics', :path => '../node_modules/@react-native-firebase/analytics' pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk' pod 'RNGoogleSignin', :path => '../node_modules/@react-native-community/google-signin' post_install do |installer| flipper_post_install(installer) end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import #import #import #if DEBUG #import #import #import #import #import #import static void InitializeFlipper(UIApplication *application) { FlipperClient *client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; } #endif // Manually import Firebase and init @import Firebase; @implementation AppDelegate @synthesize window = _window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #if DEBUG InitializeFlipper(application); #endif if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"Sparkles" 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]; [super application:application didFinishLaunchingWithOptions:launchOptions]; return YES; } - (NSArray> *)extraModulesForBridge:(RCTBridge *)bridge { NSArray> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; // You can inject any extra modules that you would like here, more information at: // https://facebook.github.io/react-native/docs/native-modules-ios.html#dependency-injection return extraModules; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #ifdef DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) { return YES; } if ([RCTLinkingManager application:application openURL:url options:options]) { return [RCTLinkingManager application:application openURL:url options:options]; } return NO; } - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; } @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 10.15.4 CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz Memory: 47.23 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.20.1 - /usr/local/opt/node@10/bin/node Yarn: Not Found npm: 6.14.4 - /usr/local/opt/node@10/bin/npm Watchman: Not Found Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 27, 28, 29 Build Tools: 27.0.0, 28.0.3, 29.0.3 System Images: android-27 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64 Android NDK: Not Found IDEs: Android Studio: 3.5 AI-191.8026.42.35.6010548 Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild Languages: Java: 1.8.0_222 - /usr/bin/javac Python: 3.7.6 - /usr/local/opt/python/libexec/bin/python npmPackages: @react-native-community/cli: Not Found react: ^16.11.0 => 16.11.0 react-native: ^0.62.1 => 0.62.1 npmGlobalPackages: *react-native*: Not Found``` - **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:** - `e.g. 6.7.2` - **`Firebase` module(s) you're using that has the issue:** - `analytics` - **Are you using `TypeScript`?** - `N`


mikehardy commented 4 years ago

Very strange! This area has test coverage, implying it works just fine. What's the difference such that e2e tests pass but it doesn't work in your project?

https://github.com/invertase/react-native-firebase/blob/d2a61f5e7f8c85d31c7af77d3132ece91ab7d6bb/packages/analytics/e2e/analytics.e2e.js#L162-L232

casconed commented 4 years ago

@mikehardy I just wrapped it in a try/catch and got

[Error: firebase.analytics().setUserProperty(_, *) 'value' expected a string value.]

I was sending a Boolean. Converting toString() gets past that line now, but I still don't see the event showing up in the firebase console.

edit: hardcoding a string in that position works (i can see it in the Debug stream).

edit 2: I can reliably get properties to show up, but it seems like it only syncs to the server when the import analytics from '@react-native-firebase/analytics' happens, i.e. the first time the screen loads, and not every time I call setUserProperty

edit 3: confirming that behavior. calling setUserProperty results in a successful execution of that method, but the network request does not happen until I navigate to another screen with import analytics from '@react-native-firebase/analytics'

mikehardy commented 4 years ago

Interesting - I think this is going to be project-specific so I'm going to close this for now, something about your conversion or similar must be wrong if you're test of directly sending a string in shows it working. If you can pin down something where the module is not performing correctly we can obviously reopen

fernandopascoalbr commented 4 years ago

@mikehardy setUserProperty replaced custom dimensions and metrics? I need help to implement custom dimensions and metrics with this lib. you can help-me? I need to do something like this => https://developers.google.com/analytics/devguides/collection/android/v4/customdimsmets