How do I add an analytics label to data messages with the java Firebase Admin SDK?

Daniel Tonks :

As of July 1, Firebase requires the addition of labels to messages in order for analytics to show about the number of data message sends etc.

'Starting Monday, 1 July 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.'

The problem is that the link to the documentation provided by firebase here, does not help. It only refers to HTTP requests whilst I am using the Firebase Admin SDK running on a Java app engine instance.

This is the barebones of the code I am using to currently send data messages. How can I adapt this to send my messages with an analytics label?

Message message = Message.builder()
                .putData("data",data)
                .setToken(deviceID)
                .build();


        String response = FirebaseMessaging.getInstance().send(message);
Dencho :

I think I found it:

Message message = Message.builder()
    .putData("data",data)
    .setFcmOptions(FcmOptions.withAnalyticsLabel("MyLabel"))
    .setToken(deviceID)
    .build();

I can see messages in Firebase console -> Reports -> Data tab.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=122673&siteId=1