17

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...

Kostyantin2216
  • 616
  • 1
  • 6
  • 15

3 Answers3

27

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.

Kostyantin2216
  • 616
  • 1
  • 6
  • 15
  • 2
    How to create an audience in firebase analytics? – wonsuc Sep 28 '17 at 19:48
  • 1
    Thanks! Did you find solution with it? Are you using `setUserId`for filtering or `setUserProperty`? – wonsuc Oct 01 '17 at 11:13
  • 1
    Using setUserProperty("userId", 1234) when your user logs in and using setUserProperty("userId", null) when user logs out will be a better solution. It will allow you to filter the event. Isn`t it ? – binaryKarmic Nov 10 '17 at 07:43
  • @binaryKarmic why is it necessary to call setUserProperty with null? – Gruntcakes Nov 08 '19 at 18:44
  • So that if any events are generated post user signs out then they will not be attributed that user. – binaryKarmic Nov 11 '19 at 10:45
  • by creating audience, is it possible to filter data using USER ID ? – shaqir saiyed Feb 13 '20 at 10:11
  • 1
    @shaqirsaiyed this might be outdated since i have not worked with firebase for over a year but from what i remember back then if you create an audience you will be able to filter data by user id but you will only see data that was created after creating the audience. – Kostyantin2216 Feb 18 '20 at 09:20
  • @Kostyantin2216 I am able to see audience for particular group of users but I am not sure if I can see user_id of those users... – shaqir saiyed Feb 19 '20 at 09:12
  • Thanks for the answer. This is so stupid that setUserId() is official api and can not really us it to filter events. This is kind of very basic use case. Firebase, is there a better way? – HBB20 Oct 02 '20 at 19:50
9

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. New user property

And... that worked...Now I can filter new events based on user id. enter image description here

HBB20
  • 2,743
  • 1
  • 24
  • 35
  • 1
    I tried it, but it says "User properties cannot be named 'user_id'" :( – gustavopch Aug 26 '21 at 17:27
  • 2
    I checked. Looks like Google changed something again. Why google why? Old project still have it but can not add to new project. They are making sure you never find user_id in firebase. A way to push for big-query? or hopefully they made it easier. – HBB20 Aug 26 '21 at 20:25
1

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 ?

bugdayci
  • 948
  • 7
  • 15
  • 3
    what's the difference between using setUserId() and setUserProperty() and how does this affect being able to search/filter for a particular user id within an audience? – Gruntcakes Nov 08 '19 at 18:19