FirebaseCrashlytics setUserId - Should we need set it on every app launch - android

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.

Related

When using the AppCenter API for android Kotlin, Am I allowed to change my UserId multiple times in the same session

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.

Reset user_id value in Firebase Analytics

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.

Null User Id's recorded by firebase

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.

Cross app tracking phonegap application

i have 2 different apps in the appstore, i am saving some data in a database (sql) like uid, ip, what page the user is on etc.
Is there a way to give a unique visitor an id or something like that so i can track the users activity in both apps.
And is it possible to see what buttons the user is clicking on.
I have added google analytics to the app but i only can see that there is a user on com.example.mainactivity and not the html pages that are the app.
Hope you guys understand what i mean.
You can use Google analytics to solve this problem with two different approaches. You can use the built in userId feature and it will even keep track of cross device sessions.
/**
* An example method called when a user signs in to an authentication system.
* #param User user represents a generic User object returned by an authentication system on sign in.
*/
public void onUserSignIn(User user) {
// Be careful when creating new trackers -- it is possible to create multiple trackers for the
// same tracking Id.
Tracker t = GoogleAnalytics.getInstance(context).newTracker("UA-XXXX-Y");
// You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
// sent with all subsequent hits.
t.set("&uid", user.getId());
// This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
t.send(new HitBuilders.EventBuilder().setCategory("UX").setAction("User Sign In").build());
}
Alternatively, you can use the Data Import feature to import external user infromation from multiple sources such as CRM data base and your SQL data base and you need to map their user representations to your own custom dimensions. You can follow the example in "Importing User Data to create AdWords Remarketing Lists" article. It shows how to use a custom dimension to represent a user id, and then upload even more custom dimensions about that user.
ga('create', 'UA-XXXX-Y', 'auto');
ga('require', 'displayfeatures');
ga('set', 'dimension1', 'NNNN'); // Where NNNN represents the CRM User Id.
ga('send', 'pageview');
Remember though Google Analytics does not support sending Personally Identifiable information, see the TOS.

receive on clear data

Is it possible to receive an event, if the user execute the "Clear Data" on the global app screen?
I create an account in my Application and save the name of the account as preference:
AccountManager accountManager = AccountManager.get(this.context);
Account account = new Account("my account name", "com.mchammer.cantouchthis");
accountManager.addAccountExplicitly(account, "", null);
now, if the user clears the data, the account on the system (used for synchronisation) have to removed too...
thanks for your help
You can't. Your app gets FCed on Clear Data, so you can't run any code.
BUT. You can use SharedPreferences to store a boolean pref, say isAccountInitialized.
You set it to true and store after your AccountManager logic has done creating the account. Then, every time you use the account for sync (or every time you launch your main activity, or your service is up do do something - this you'll have to figure out based on your app specifics) you pull the isAccountInitialized from shared prefs and if it's false and your account is present in AccountManager - that's your sign that user has executed Clear Data and it's time to remove the account from AccountManager. If it's false and there's no account - that's first launch.
// OFFTOP Nice package name :)
It is not possible as As soon as you press clear data. Your application process will be stopped. You can check this link for answer.

Categories

Resources