Starting Monday, July 1, 2019, you will be able to filter data by an analytics label.
Data messages sent without an analytics label might not be represented in this dashboard after that date.
So I tried to associate a label with the message's analytics data using fcm_options and
analytics_label but still it does not work so I'm not sure I'm doing it right.
Here's my code:
B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim m As Map = CreateMap("to": $"/topics/${Topic}"$, "priority": "HIGH")
Dim data As Map = CreateMap("title": Title, "body": Body)
Dim fcm As String = $"{"analytics_label":"Testnotification"}"$
m.Put("data", data)
m.Put("fcm_options", fcm)
Dim jg As JSONGenerator
jg.Initialize(m)
Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub
Can anyone check if this code sounds correct?
And if yes, do you have an idea why data messages do not show up in the Firebase console?
Thanks Erel. A map was my first attempt but then I noticed the following in the documentation:
B4X:
{
"name": string,
"data": {
string: string,
...
},
"notification": {
object (Notification)
},
"android": {
object (AndroidConfig)
},
"webpush": {
object (WebpushConfig)
},
"apns": {
object (ApnsConfig)
},
"fcm_options": {
object (FcmOptions)
},
// Union field target can be only one of the following:
"token": string,
"topic": string,
"condition": string
// End of list of possible types for union field target.
}
and then
data
map (key: string, value: string)
Input only. Arbitrary key/value payload. The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm").
It means that messages don't show up in the Firebase Console.
The analytics label should be visible in the Console as a possible option to filter the messages.
But still... nothing is shown