4
votes

First I apologize for my English :-) I am working on a big project and I encountered a problem with using Firebase in my Android app. I have RemoteConfig with conditions using Analytics user property. When I set user property in app, fetch data and after it's successfully completed, I activate fetched data, I still get default value for parameters from RemoteConfig, even when RemoteConfig condition is true. Code is written in Kotlin.

This is an example of my code (this code is in onCreate() method in class, which extends Appliaction class:

FirebaseAnalytics.getInstance(this).setUserProperty("testprop", "a");
FirebaseRemoteConfig.getInstance().fetch(0).addOnCompleteListener {
    if (it.isSuccessful) {
        FirebaseRemoteConfig.getInstance().activateFetched();
            val a = FirebaseRemoteConfig.getInstance().getString("test_param");
            Log.i("TOAPP", "Test param is $a");
        } else {
            Log.i("TOAPP", "Error: ${it.exception?.localizedMessage}");
            it.exception?.printStackTrace();
        }
    }
}

RemoteConfig in Firebase:
Parameter = test_param
- MyUser = develop
- Default value: = production

Condition:
MyUser - applies if User property testprop exactly matches a

When I run this, I get this in console:
I/TOAPP: Test param is production

I have these libs in gradle.build file:

// Play services
implementation "com.google.android.gms:play-services-location:11.4.2"
implementation "com.google.android.gms:play-services-maps:11.4.2"
implementation "com.google.android.gms:play-services-base:11.4.2"
implementation "com.google.android.gms:play-services-identity:11.4.2"
implementation "com.google.android.gms:play-services-places:11.4.2"

// Firebase
implementation "com.google.firebase:firebase-core:11.4.2"
implementation "com.google.firebase:firebase-config:11.4.2"
implementation "com.google.firebase:firebase-messaging:11.4.2"

Thanks for the answers.

2
Is there a typo in your post (or code)? In the post, the text describing the condition has property name testprop: applies if User property testprop exactly matches a. In the posted code, you are setting property testparam.Bob Snyder
Yes, there was a typo... I set user property testprop. I repaired post. But code still doesn't working.TomasBiesok

2 Answers

2
votes

Problem solved!

In Firebase, I have two Andorid apps (old app version and new app version). The old app works correctly, but with the new app were problems. When I opened old app in Firebase Analytics and then user properties, there were parameters which I use in remote config conditions. When I switch app to new version in Firebase Analytics, the user properties were empty. I added same properties from old app version to new app version in Firebase Analytics and new app works correctly.

0
votes

Your code looks correct. The issue is probably timing. When you call setUserProperty() it takes some time for the value to be reported to the Firebase servers where it can be used by RemoteConfig. I don't know exactly what the delay is, but it might be as much as an hour. Firebase Analytics buffers event data and sends it infrequently to reduce battery usage, as explained here:

Generally, events logged by your app are batched together over the period of approximately one hour and uploaded together. This approach conserves the battery on end users’ devices and reduces network data usage.

It's likely that user properties are handled the same way. For testing, you can enable debug mode to upload the data with minimum delay (described at link above):

adb shell setprop debug.firebase.analytics.app <package_name>

I recommend you enable debug mode, run the code to setUserProperty(), wait a few minutes, then run the code to fetch the remote config data. When I used that procedure and ran the Java equivalent of your code with version 11.4.2, it worked.

After enabling debug mode, you can use the Analytics debug view in the Firebase console to confirm that the user property value you have set has been uploaded to the Firebase servers.