Comments (5)
Hi @gpkamp,
As per the FCM docs, set the fcm_options.analytics_label
param using the following code:
var gcm = require('node-gcm');
// Set up the sender with your GCM/FCM API key (declare this once for multiple messages)
var sender = new gcm.Sender('YOUR_API_KEY_HERE');
// Prepare a message to be sent
var message = new gcm.Message({
data: { key1: 'msg1' },
fcm_options: {
analytics_label: 'call-notification'
}
});
// Specify which registration IDs to deliver the message to
var regTokens = ['YOUR_REG_TOKEN_HERE'];
// Actually send the message
sender.send(message, { registrationTokens: regTokens }, function (err, response) {
if (err) console.error(err);
else console.log(response);
});
from node-gcm.
I tried with 1.0.3 , it didnt work
`var gcm = require('node-gcm');
// Set up the sender with your GCM/FCM API key (declare this once for multiple messages)
var sender = new gcm.Sender('.....');
// Prepare a message to be sent
var message = new gcm.Message({
notification: {
title: 'Title of your push notification',
body: 'Body of your push notification'
},
data: { key1: 'msg1' },
fcm_options: {
analytics_label: 'call-notification'
}
});
// Specify which registration IDs to deliver the message to
var regTokens = ['.....'];
// Actually send the message
sender.send(message, { registrationTokens: regTokens }, function (err, response) {
if (err) console.error(err);
else console.log(response);
});`
from node-gcm.
Hi @ltnilaysahu,
When debugging node-gcm
, I could confirm that using your exact sample code, the fcm_options.analytics_label
is passed in the request to the FCM API:
Therefore, there is no bug in node-gcm
. Instead, check for a delay in the analytics being posted to the Firebase dashboard, or using the wrong label ID.
from node-gcm.
Hi @eladnava . Correct its getting passed to the FCM API that node-gcm
is using but according to the docs Labeling messages is very useful for custom analysis, allowing you to filter delivery statistics by labels or sets of labels. You can add a label to any message sent via the HTTP v1 API by setting the fcmOptions.analyticsLabel field in the message object, or in the platform-specific AndroidFcmOptions or ApnsFcmOptions fields.
And i believe node-gcm
is not using HTTP v1 API which is POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
as per https://firebase.google.com/docs/cloud-messaging/migrate-v1
from node-gcm.
Hi @ltnilaysahu,
Nice catch. Indeed this parameter is not supported in the FCM Legacy HTTP Server API.
Currently, node-gcm
is specifically built to support the legacy API format and there are no current plans to migrate to the FCM HTTP v1 API.
I'd recommend checking out the official firebase
package to send notifications.
You can then add an analytics label by setting the fcm_options.analytics_label
field in the message
object:
https://firebase.google.com/docs/cloud-messaging/send-message
from node-gcm.
Related Issues (20)
- Address deprecation of request package HOT 2
- Unable to send push to browser(firefox, chrome) always getting InvalidRegistration HOT 4
- Make send URI configurable HOT 1
- fcm_options and analytics_label fields are not sent to FCM servers? HOT 2
- TypeError: Cannot read property 'error' of undefined failed_tokens example HOT 1
- Not receiving notifications - ios HOT 2
- Add snyk to fix vulnerabilities faster HOT 15
- Add missing GitHub releases and version tags
- Add CI to require passing tests before release HOT 2
- didReceiveRemoteNotification:fetchCompletionHandler not called. HOT 6
- readme error in failedTokens snippets HOT 1
- Removing no longer valid FCM tokens HOT 1
- Add release automation HOT 2
- Support for Google Service Accounts authorization HOT 2
- Firebase Legacy HTTP API discontinued by June 20, 2024 HOT 12
- request package security issue. HOT 3
- Handle non-HTTP errors HOT 1
- Handle all HTTP errors
- Migration from legacy FCM to HTTP v1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-gcm.