Count subscribers of a topic in Firebase Cloud Messaging
Asked Answered
T

3

13

What I want to do with my app is this: users can select different interests and as soon as there are more than ~5 people interested in the same thing, I want to send them a notification.

I thought Firebase + Topics would be a good choice for this.

But how do I find out how many people have subscribed to a topic?

Trinitytrinket answered 28/11, 2016 at 18:30 Comment(1)
Possible duplicate of Firebase Cloud Messaging - Check existing or available TopicsPaladin
P
17

There is no available API to check how many subscribers a topic has. (see my answer here)

You'll have to implement the mapping on your server-side, saving the name of the topics and adding in the list of subscribers. Upon subscription, add the new subscriber, check the count (see if it's within your preferred number), then trigger a notification.

Paladin answered 29/11, 2016 at 8:52 Comment(14)
Is this still the case(as this answer is 1 year old) or any API has been implemented?Gautama
@Gautama There still is no update so far, so yes. This is still the case.Paladin
Okay. Thank you!Gautama
3 year old answer, is this still the case :)Hendry
In some cases, server side solution is near to impossible.Planetary
I was storing all user deviceIDs in my db but a coding error overwrote every deviceID with an identical deviceID. And now, due to changes in how we register users to specific topics we need to get all devIDs from all the old topicIDs and register all the same deviceIDs to the new topicIDs. This won't necessarily help us correct our DB issue, but at least all the users who had subscribed to old topics (no longer being used) will still get messages to the new topicIDs. The problem is, how do we get all registered devIDs to the old topics in order to register those IDs to the new topics?Telegraph
@Telegraph I don't think there's a one-step fix for this. A solution that came to mind however would be to get all device IDs again, get the corresponding tokens, use the Instance ID API to check the list of topics they are subscribed to, then subscribe to new ones as needed. This can be expensive depending on how many you would need to "migrate". Cheers!Paladin
@AL - yeah, thats the problem, since we don't have the correct deviceIDs for each user we have no way of pulling what topics they are subscribed to. Our app does auto update our DB with the users deviceID every time the user turns on the app, however, not every user turns on the app every day, or every week or month - and as we have learned, sometimes several months. The issue overwriting the users deviceID happened about 1 month ago and to date we have only recovered about 15% of the correct deviceIDs.Telegraph
@Paladin how do we go about notifying % of the subscribers of a topic?Byebye
@Byebye AFAIK, you cant target the topic subscribers by %. It's all or nothing.Paladin
count up, 4-year-old answer, is it still the case? :DClamorous
@TranHo Yes. No API available for this yet.Paladin
5 year old answer. Is there any built in solution yet or any plans to do this?Bias
@Bias I haven't dabbled with FCM for a time, but I haven't heard of any updates about this so far. Cheers!Paladin
T
7

U can use this to get number of subscribers :

Copy as a curl. Use that to get subscribers list enter image description here

Reference: https://gist.github.com/timrijckaert/218be90541a7285e21455fafa2962dea

Toiletry answered 23/9, 2021 at 12:30 Comment(0)
T
1

There is no direct way of doing this. Your only two options are:

  1. Using stored deviceIDs in your own DB, manually script to retrieve each users subscriptions.
  2. Already track in your own DB each users deviceIDs AND every topic they subscribe to.

There are so many problems with both of these methods though. It's frustrating topic managmenet doesn't already exist in FCM Console. I wrote Google a feature request for FCM Cloud Notification Topic Management and this is the response I got:

We're aware that many developers, such as yourself, would like to have this topic management. There's actually an existing feature request regarding this. However, I can't provide any details or timelines as to when this will be available.

Telegraph answered 14/10, 2019 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.