Reputation: 42796
We are using legacy app server protocols to send Firebase data message, for several years.
#
# headers = {'content-type': 'application/json', 'Authorization': 'key={}'.format(constants.FCM_AUTHORIZATION_KEY)}
#
# request_data = {'to' : valid_enabled_token, 'data' : {'sync': sync, 'sync_device_count': sync_device_count}}
#
r = requests.post('https://fcm.googleapis.com/fcm/send', headers=headers, json=request_data)
However, recently, we cannot see any delivery report in Firebase console.
We notice we need to add analytics label according to https://firebase.google.com/docs/cloud-messaging/understand-delivery
Important: An analytics label is required to display all types of statistics for data messages.
However, it isn't clear on how to add analytics label via legacy method.
Can anyone provide a simple example on how to do so? Thank you.
Upvotes: 0
Views: 3389
Reputation: 1898
As you already described:
You can add a label to any message sent via the HTTP v1 API by setting the fcmOptions.analyticsLabel field in the message object.
E.g.:
fcm_options: {
analytics_label: "test_label"
}
In your case you would have to add the analytics_label
to fcm_options
within your request_data
, e.g.:
const headers = {
"content-type": "application/json",
Authorization: "key={}".format(constants.FCM_AUTHORIZATION_KEY)
};
const request_data = {
to: valid_enabled_token,
data: { sync: sync, sync_device_count: sync_device_count },
fcm_options: {
analytics_label: "test_label"
}
};
const r = requests.post(
"https://fcm.googleapis.com/fcm/send",
(headers = headers),
(json = request_data)
);
Alternatively you can use the platform-specific AndroidFcmOptions
(FCM SDK for Android) or ApnsFcmOptions
(FCM SDK for iOS) fields to add the analytics_label
as described above.
Update: However it seems that the Legacy HTTP Server Protocol does not (yet) support the analytics_label and / or fcm_options.
With the HTTP v1 API, the analytics label can be set when sending the message, in order to mark the message for analytics purposes
Unfortunately the visualization data is only available for messages with notification payload or labeled data messages:
This data is available for all messages with a notification payload and all labeled data messages. To learn more about labels, see Adding analytics labels to messages.
See
Upvotes: 4