我正在尝试使用firebase云消息服务向应用程序用户发送推送通知。已成功发送通知,但未在"报告"选项卡下添加分析标签这是我的admin nodejs脚本
admin.database().ref('chat/qa/branches/1510/lasid/1510/threads/fcmCampaign/fcmBody/')
.once('value', (snapshot) => {
let val = snapshot.val();
if(val){
if(val.title)
payload.notification.title = val.title;
if(val.body)
payload.notification.body = val.body;
if(val.image)
payload.notification.image = val.image;
if(val.nTitle)
payload.data.nTitle = val.nTitle;
if(val.nMessage1)
payload.data.nMessage1 = val.nMessage1;
if(val.label)
payload.fcmOptions.analyticsLabel = val.label;
if(val.showNotifications)
payload.data.showNotifications = val.showNotifications;
admin.database().ref('chat/qa/branches/1510/lasid/1510/threads/fcmCampaign/fcmToken/')
.once('value', (snapshot) => {
var val = snapshot.val();
if(!val){
res.send('something went wrong');
return
}
fcmList = [];
console.log('fcm_tokens val'+JSON.stringify(val));
let keys = Object.keys(val);
//NEW - block changes
for(let i=0;i<keys.length;i++){
fcmList.push(val[keys[i]]);
if((i+1) % breakPoint == 0){
sendMessageToDevices(fcmList);
fcmList = [];
}
if(i == keys.length-1 && fcmList.length!=0){
sendMessageToDevices(fcmList);
fcmList = [];
}
}
});
}
});
function sendMessageToDevices(fcm_tokens) {
console.log('fcm_tokens' + JSON.stringify(fcm_tokens));
//admin.messaging().sendToDevice(fcm_tokens,payload,options)
payload.tokens = fcm_tokens;
console.log('payload data ',JSON.stringify(payload));
admin.messaging().sendMulticast(payload)
.then((response) => {
console.log('Successfully sent message : ' + JSON.stringify(response));
res.status(200).send('Notification send successfully')
})
.catch((error) => {
console.log('Error sending message : '+error);
res.status(400).send('something went wrong')
})
})
有效负载具有fcmOptions.analyticLabel,但标签仍未添加到reports选项卡下,因此无法跟踪消息。如果有人能提供一些见解,那就太好了。谢谢
代码似乎没有任何问题。Firebase有时需要超过24小时来处理分析。我花了48个小时。