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

被刻印的时光 ゝ 提交于 2020-01-24 10:27:05

问题


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);

回答1:


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.




回答2:


From looking at the commit history of the messaging section of the SDK, it seems like support for this header has not been added to the Firebase Admin SDK for Java yet.

You might want to file a feature request or (even better) open a PR. I left a comment on this existing feature request, which seemed most relevant to what you're asking.



来源:https://stackoverflow.com/questions/56920853/how-do-i-add-an-analytics-label-to-data-messages-with-the-java-firebase-admin-sd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!