Firebase Analytics Filter By User ID - android

The Firebase Android SDK for analytics provides a method named setUserId(String id), now i enabled firebase logging and every time i called the method setUserId(1234) i see this in the logs Setting user property (FE): _id, 1234.
My question is how come the Firebase dashboard does not let us filter by this property, there is no property not for userId and not _id, i even tried to add _id as a property in the dashboard but Firebase does not allow property names to start with an underscore.
Do i really have to stop calling that method and just do setUserProperty("userId", 1234) or am i missing something...

I have spent a few hours on this and found the answer i was looking for more or less, hopefully this might save someone else some time.
The only way to filter by Firebase's User Id property is by creating an audience, there you will be able to pick the user id property that is supplied from the setUserId(String id) method.
It is a downer though because you won't see any events for the user/user's you want from before the audience was created.

I was scratching my head with this issue. Initially, I felt so dumb when I could not find how to use user id for filtering in Firebase analytics dashboard that I am setting with official API setUserId(). When I try to look for answer, I realized that I am not the only one. Finally, this is how I was able to filter events based on user id.
In Android Code, I set user id using setUserId() method. When I read bigQuery has this property as user_id, I thought to give it a try by adding a new user property in Firebase Dashboard with the hope that it will fetch the reported id.
And... that worked...Now I can filter new events based on user id.

In audience you have to select contains, exactly match or regular expression for a field.
So to filter for a user you have to add all your users to the audience, which looks cumbersome.
Isn't using setUserProperty is better? Have you faced any problems with using it ?

Related

How to give data access in cloud firestore to another added users in android?

I wanna ask about the concept and logically ways to give another user the privilege to access other's users' data. What I want to do exactly is like this :
Basically, collection 1 contains several Users ID (UID) from authentication, then the user will have their own data collected in collection 2 which contain the data ID.
So, it's like giving access to another user to collaborate with the data like Google Docs Apps where we can add another user to edit our documents. I've been thinking of how to do this, but still, I got stuck.
My question is, how can I possibly do this? cause from what I've read, cloud firestore don't use such a foreign key like MySQL. Thank You
haven't tried something like this but i think this approch overcomes your problem.
modify your structure according to above image. userID collection will contain userIds which are allowed to edit their parent collection.and create firestore rules according to your use to check weather the userId is allowed to edit the Collection or not.
in your case when 'user 2' will have reference to 'collection 2', he/she will try to change data. firebase rule will check if auth.userId is inside the 'collection2.UserIDs' or not and will allow according that.

Querying firebase, without duplication

I am new to coding and I am just playing around to build an app where everyone can post new events. So I have already created notes like "user" and "events". The problem I face off is that I dont know how to avoid duplication like for example if two users are posting the excat same event.
I don't want to show them twice in my RecyclerView.
So I have to compare the date, the location and the description, due to this many queries, is the Firebase Realtimedatabase the right "tool"? Or should I use another software.
------/Events
---------/LbwXYVICCl9xd5m..
--------------datum: 10.04.2019
--------------userid: OncDIQis...
--------------location:New York
--------------description:Coldplay
You seem to define two events as being the same based on some of their properties having the same value. In a scenario like that, I'd use those combined properties as the key of the event.
So if you say that two events are the same if they have the same date, location, and description, then you can create the unique key of that event as ${date}_${location}_${description}. For example:
20190410_New York_Coldplay
I've put the date in an easier to search for format, which also filters the .s (since those are not allowed in keys. Now you can store the event under that key:
Events
20190410_New York_Coldplay
datum: 10.04.2019
userid: OncDIQis...
location:New York
description:Coldplay
With the above structure, if another user tries to create an equivalent event, it will get the same key.
Firebase Real-time database is the right tool for you as it updates the database in real time.
At the time of fetching the data from the firebase, you can check whether it is already present in your local database(where you are collecting data fetched from the firebase) or not.
I hope this will help you out.

How to get the number of users logged in in the firebase database (Without addValueEventListener() )?

I have been looking for this quite some time now and i haven't found any answer related to my problem, so before you tag my question duplicate, at least read it first.
First i have just started firebase and only know basic things about it, i am trying to make a simple single user (1 to 1) chat app.
I want to get the number of users logged in in the database.
I have a child to the root of my database called users which have the list of the users who have logged in.
I know about the datashot.getchildrencount() but that works when some update/event happens, but i want it to give me the number of users whenever i want, not only on some event (For example in messenger number of current active users are shown continuously,i dont want active user tho, i just want total logged in users).
I thought of the another way to make a child called NumberofUsers so i store number of users there but then firebase dont allow to getvalue of the child,only set value (it does allow to get value but only on some event). Any idea what should i do?
UPDATE
i thought of another way to do this, though its not working at the moment but i think solving it is easier than thinking of another method to solve my original problem.
so I made one more child of NumberofUsers with key "02" and random value. now everytime i want data of "01" i change the value "02" after enabling the addChildEventListener for "NumberofUsers". Code that does this. Error its giving me. .new database.
Apparently I cant access child data using datasnapshot, any solution?
Any idea how to solve either of this?
Thank you.
Unfortunately, there is no way in which you can read data from a Firebase Database without attaching a listener. Regarding Firebase, everything it's about listeners. In your case, i think you want a callback to be called once and then immediately removed. If so, i recomand you using addListenerForSingleValueEvent() method to simplify this scenario. It triggers once and then does not trigger again.
This is useful for data that only needs to be loaded once and isn't expected to change frequently or require active listening.
Hope it helps.

Android Firebase User ID mapping issue

I had integrated Firebase analytics in Android few months back.
Initially I was setting the user_id wrongly, by using the following code :
mFirebaseAnalytics.setUserProperty("userId", "<value_of_type_1_for_user_id>");
As a result my user_id column in bigquery was null. Hence on my next release, I corrected it and used the following method :
mFirebaseAnalytics.setUserId("<value_of_type_2_for_user_id>");
This created a problem as all those users who had installed/used the app between those two release dates have an extra user property key named "userId". And this has some wrong values of user_id.
Now, another strange thing that has happened is that there are many new users who are onboarding the platform now with the latest version of APK. A small percent of these users still have the malicious key of "userId" under user_properties.
I need help in understanding the following :
- Understanding the reason behind why new users (a random small group of them) are still being affected by this wrong mapping ?
- How to clean up the user property field of old users by removing this property key for all users.
You can set the user property "userId" to null/empty and the user property will be removed from the future events. User property will stick with events until you explicitly remove it.

Firebase Analytics events dont show values

I am new in Firebase and I am trying to understand it, I want to track whitch achievements( by my id) my users unlocks
I saw lot of post about this like this where it says
Currently, parameter reporting is offered only on a subset of suggested events. If you need to access your custom parameters, you can link your app to BigQuery and run queries on the raw data there.
So as far as I understand, It should show the values of the suggested events,but I dont even get that values, I am getting the events but not the values, My console shows no values.
I am doing something bad on the code? I am misunderstanding events? Or is Firebase not working as it should?
Code sending to firebase my id
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ACHIEVEMENT_ID, Integer.toString(lm.logros[a].id));
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.UNLOCK_ACHIEVEMENT, bundle);
For accessing all the data(in your case the values part) that you log in Firebase Analytics.. you have to link firebase to use Google Big Query service that's not available for Free.

Categories

Resources