1

I'm building an app using Firebase Notifications where a user can enter their zip code and then receive notifications for specific events happening in their locality.

How do I only send notifications to a specific user? I've tried including Zip Code in the Advanced Options sections of Firebase Notifications, but it still sends the notification to all users.

3 Answers 3

2

Seems like Topics is what you are looking for. When the user enters their zipcode you can subscribe them to a topic eg: /topics/zip then you can send to the appropriate zipcode from the console. Subscribing will create the topic if it does not already exist.

Note: Topics can take up to 24 hours to show up in the console after they are created.

Sign up to request clarification or add additional context in comments.

Comments

0

It seems you are trying to Send Notifications to a User Segment in the Firebase Console. However, it seems that the specific detail you're targeting is not an option that is available in the console.

As of right now, the only available User Segments you can send to are (these can be modified in the Target Section when Sending a Notification):

  • (User) Audience
    • All Users
    • Purchasers
  • (Device) Language
    • English (I think it may vary depending on the language you're using)
  • (App) Version
    • Contains
    • Does not contain
    • Exact Match
    • Regular Expression

With the above being clear, I think the only way for you to send to those specific users in a specific Zip Code, you should be implementing the push from your server app, wherein you collect the users profiles with the corresponding Zip Code, and then push the messages to their registration tokens.

I think the links mentioned in this answer will help you:

Firebase Cloud Messaging has server-side APIs that you can call to send messages. See https://firebase.google.com/docs/cloud-messaging/server.

Sending a message can be as simple as using curl to call a HTTP end-point. See https://firebase.google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol

curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<YOUR_DEVICE_ID_TOKEN>\",\"notification\":{\"body\":\"Yellow\"} \"priority":\"10"}"

Comments

0

There will be below ways to do it,

  1. Topic messaging - subscribe to a topic with a specific audience, and send notifications with that topic name.

  2. Firebase Tokens - You can write the logic on the server to send the notifications to specific firebase token IDs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.