We are linking our firebase analytics data to BigQuery and upon analyzing found that the user id's are null for several users.
In what scenarios can this happen? and what is the solution for the same.
The bad behavior was when the user_id property was populated with a value. The property user_id should be null except if you set it explicitly with a call to that function:
android function: setUserId(...)
ios function: setUserId(...)
If you don't explicitly call setUserId, which is common, then the id you should use in BigQuery would be the app_instance_id.
My advice: call setUserId once you have a logged in user (in Facebook, Google sign-in or whatever method you offer). This will give you a cross-device ID. If the user is not logged in, don't call it, and use the app_instance_id id instead.
Note that the app_instance_id change if the user uninstall & reinstall your app.
Related
I was using Firebase Auth Gmail Authentication. While doing some random tests on the app, I deleted the account from Firebase Auth Console while I was still logged in.
Now even if I uninstall the App and reinstall it, I still get the UID even though that UID is not present in the Firebase Auth Console. The first lines of code as soon as I open the app are as follows:
val uidz = FirebaseAuth.getInstance().currentUser?.uid.toString()
Log.d("uid as soon as i open the app",uidz)
Logcat Reads as
2022-09-27 21:40:01.802 23060-23060/com.example.alliaiseV1 D/uid as soon as i open the app: uZOs2XhBOrX4YU8qKem3lD4C7cy1
Strange parts:
This UID if I navigate to some other page and re-check the current user changes to null
Every time I uninstall and reinstall the App I see the same UID every time
It only happens on my device for every other device when I re-install the App the current UID returns as null but for my device, it returns as the above in logcat
Deleting App Data and Cache works but again if I reinstall I see the UID
I edited the code to :
val uidz = FirebaseAuth.getInstance().currentUser?.uid.toString()
Log.d("uid as soon as i open the app",uidz)
FirebaseAuth.getInstance().signOut()
Log.d("uidlogout", "${FirebaseAuth.getInstance().currentUser?.uid.toString()}")
The logcat I read for it is as follows :
2022-09-27 21:45:06.228 23964-23964/com.example.alliaiseV1 D/uid as soon as I open the app: uZOs2XhBOrX4YU8qKem3lD4C7cy1
2022-09-27 21:45:06.229 23964-23964/com.example.alliaiseV1 D/uidlogout: null
From where is this UID coming?
Why do I see the same UID every time?
How do I get rid of it?
While doing some random tests on the app, I deleted the account from Firebase Auth Console while I was still logged in. Now even if I uninstall the App and reinstall it, I still get the UID even though that UID is not present in the Firebase Auth Console.
If you accidentally deleted a user account from the Firebase console it doesn't mean that the current token automatically expires for that account. No, the current tokens will remain valid until it expires. If you however are interested in changing the expiration interval, please note that this option is available in your Firebase console.
If you want to force a user to sign out, then you can use FirebaseAuth#signOut() method, which:
Signs out the current user and clears it from the disk cache.
To prevent that from happening, you should consider creating authorization rules. In this way, you'll be able to differentiate users with valid tokens from the ones that have deleted accounts. If you are using, for example, the Realtime Database to keep a user's data, then you can check whether that user still exists in your security rules using the following line of code:
root.child('users').child(auth.uid).exists()
For more info, I recommend you read David East's answer in the following post:
Deletion of User in firebase does not trigger onAuth method
Sorry for the ambiguity in the question but it is actually quite a simple one.
When my android Application boots up I initialize AppCenter as follows:
AppCenter.start(
this, BuildConfig.APP_CENTER_SECRET,
Analytics::class.java, Crashes::class.java, Distribute::class.java
)
if(BuildConfig.FLAVOR != ApplicationVariants.ProductFlavors.PRODUCTION){
AppCenter.setLogLevel(Log.VERBOSE)
}
AppCenter.setUserId(UUID.randomUUID().toString())
Distribute.setUpdateTrack(UpdateTrack.PUBLIC)
Distribute.checkForUpdate()
However, when the user logs into the application I would like to set the UserId to the users email as follows once the user logs in:
JwtUtils.getIdentityTokenModel(requireContext())?.let {
AppCenter.setUserId(it.email)
}
Lastly when the user logs out I reset the user Id to a random guid. The reason for this is visibility on which user has which crash logs. This is a requirement from business.
However, in the app center crash logs, it seems the UserId never changes to the email even if an error occurs while the user is logged in.
My question is simple. Is there a restriction on how many times I am allowed to change the AppCenter User Id? I cannot seem to find it anywhere in the docs.
Thanks in advance
Please see these docs about userId API:
The value for the user ID is limited to 256 characters. It will be
shown with your crash reports but not used for aggregation or counts
of affected users. In case you set user ID multiple times, only the
last user ID will be used. You need to set the user ID yourself before
each application launch, because this value isn't stored by the SDK
between launches.
For FirebaseCrashlytics i am setting the user id once user logged in then store its credentials in sharedpreference.
FirebaseCrashlytics.getInstance().setUserId("12345");
On next App launch User will be automatically logged in. So Should I set user id on every app launch or its the one time function call. What should I do in case on user logged out and switch to another account on same device
You will have to implement a method to associate User ID's with devices/users. You can do something like this UUID uuid = UUID.randomUUID();, to associate randomized UUID's to the setUserId method. You can read more about this here https://www.baeldung.com/java-uuid.
Depending on your method, you can log certain identifiable information based on how your user logs into your app. Such as via email or something, but that's discouraged for privacy reasons.
I am trying to use
mLinphoneCore.clearAuthInfos()
mLinphoneCore.clearProxyConfigs();
Neither methods, but has good results.
After all, how should I cancel the registration?
I tried to successfully log out of the account on the server using the following method.
https://i.stack.imgur.com/sCfod.png
proxyCfg:This is the LinphoneProxyConfig object at login time.
name,password,host:These are the usernames, passwords, and domain names that are logged in.
Because the method used by iOS is not the same, so I am not sure if it is completely correct.
Actual event logs taking a few hours to reflects on the dashboard. So I am using DebugView to analyse events.
My app has a login/logout feature. App can be used by multiple users.
On successful login, calling FirebaseAnalytics.getInstance(context).setUserId("user id").
Then after all the further logs goes under given user ID. Till now its good.
But If I login with different user then user id doesn't get change and all logs events goes under previous one.
How to reset User Id on each login call?
You can remove the User ID by setting it to null or replace it with a new user ID. userID is just a user property that goes with all events after it is set so you need to set it to null when user logs out and set a new user ID when a different user logs in.