B4J Question Use of analytics_label with Firebase Messaging

avalle

Active Member
Licensed User
Longtime User
Hello, while using Firebase Messaging I noticed that messages I send using code from the sample B4J app posted at https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/ are delivered to my B4A mobile app but don't show up in the Firebase Cloud Messaging console.

I noted the warning on the console page:
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
Andrea
 

avalle

Active Member
Licensed User
Longtime User
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").

fcm_options
object (FcmOptions)

Input only. Template for FCM SDK feature options to use across all platforms.

upload_2019-11-18_14-45-39.png


Still does not work even if using a Map...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Still does not work even if using a Map...
What do you mean with does not work? Do you get any error?

Note that the analytics label shouldn´t arrive in your app. At least i think it is like this.

It is only relevant if you are using Analytics and you probably get this label in some Analytics-data output/results
 
Upvote 0

avalle

Active Member
Licensed User
Longtime User
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
 
Upvote 0
Top