Search code examples
androidpush-notificationfirebase-cloud-messagingandroid-push-notification

Difference between "topic messages", "target messages", and "user segments" in Firebase Cloud Messaging


I want to send push notifications using Firebase Cloud Messaging to users of my App. I have two categories:

  1. Country 1
  2. Country 2

In the settings of the app, users have radio buttons to subscribe to either Country 1 or Country 2. I already completed the steps described at https://firebase.google.com/docs/cloud-messaging/android/client and when I use FirebaseInstanceId.getInstance().getToken(), I am obtaining the device token successfully. I was able to send notifications to single devices by using the compose message section of the Firebase console. The Firebase console has three radio buttons:

1) User segment 2) Topic 3) Single device

I understand how to send messages to single devices by using the device token. Now I am trying to fully understand the difference between "topic messages", "target messages", and "user segments". I was reading at https://firebase.google.com/docs/cloud-messaging/android/topic-messaging the following information:

Topic messages are optimized for throughput rather than latency. For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens, not topics.

For what I need, I think using "topic messages" would be convenient, where I would have two topics: "Country 1" and "Country 2", and users decide to subscribe to the country they want to receive promotions from in this case.

"User segments" means that I take a group of device tokens and add them to a segment, and then I broadcast a push notification to that segment, correct? In the case of "topic messages", I would let users to subscribe to the country they want, and in my code I would have something such as the following lines to let someone subscribe to a specific country, correct?:

FirebaseMessaging.getInstance().subscribeToTopic("country1");
FirebaseMessaging.getInstance().subscribeToTopic("country2");

Similarly, I would simply use unsubscribeFromTopic("country1") and unsubscribeFromTopic("country2") for unsubscribing users from topics.

I would appreciate if you could help by letting me know if my statements are correct or if you see that I am misunderstanding the conceptual differences between "topic messages", "target messages", and "user segments". Thank you.


Solution

  • The conceptual answer that I was looking for is at https://firebase.google.com/docs/cloud-messaging/android/send-multiple

    Send Messages to Multiple Devices: Firebase Cloud Messaging provides two ways to target a message to multiple devices: Topic messaging, which allows you to send a message to multiple devices that have opted in to a particular topic. Device group messaging, which allows you to send a message to multiple devices that belong to a group you define.