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.
Related
I am preparing an application and this application has a login and registration system. The user's data will be kept on Firebase.
But there is a problem with this application. Every time the user opens the application, that login or register screen will come again. As a matter of fact, this will be very annoying and the user will be bored.
I want the user to log in or register the first time she opens the application, and then every time she opens the application, the account is open.
How should I go about this? How can I solve this problem? Thanks in advance for your ideas.
You simply do a check if the user is already signed in.
From the docs:
var user = FirebaseAuth.instance.currentUser;
if (user != null) {
// user is logged in
return app();
}
// otherwise, show login/register
return splashScreen();
You can also listen with AuthStateListener (best for your use case)
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.
I would like to show custom lock screen specific to app if the user has entered the wrong device credentials(PIN/Pattern/Password) 3 times.
I have tried with AuthenticationFailed() using BiometricPrompt and onActivityResult using createConfirmDeviceCredentialIntent().
Both are conveying if the user has cancelled the flow but not the invalid credentials.
Is there any call back methods which will identify the wrong pin entry?
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 using Crashlytics in my application and I wanted to get user id and email along with each crash. I did something like this:
Crashlytics.setUserEmail(tokenModel.getEmail());
Crashlytics.setUserIdentifier(String.valueOf(tokenModel.getPk()));
I am doing this in my login screen, after the user has provided his email and successfully registered with the app, so as to get user id. The problem is, I am not getting these data in the crash reports.
What is the lifecycle and working of Crashlytics in above context? Do I need to set these fields every time the app opens?
I am not sure if it needs to be done every time you launch the app and the Crashlytics docs don't explicitly say it neither.
I know that we do it with every launch and it works - provided user info is displayed properly in the dashboard.
My suggestion would be to try send this information every time you initalize Crashlytics with Fabric.with(this, new Crashlytics());, as soon as you have your user data provided (for example after fetching his user profile from your server).
You need to select the issue, click in more details and at the top right corner you can see a label with Identifier.
You need to set it every time you initialise the Crashlytics. At least doing this it works.
if you are using this Crashlytics.setUserIdentifier(""); you can check in data tab in firebase. Fabric.with(this, new Crashlytics()); working fine.
If you look into codes of FirebaseCrashlytics than you can see that userId is being saved into the session. So I am sure that after restarting application your id will be restored.