Code Monkey home page Code Monkey logo

Comments (5)

eladnava avatar eladnava commented on September 28, 2024 1

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.

ltnilaysahu avatar ltnilaysahu commented on September 28, 2024

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.

eladnava avatar eladnava commented on September 28, 2024

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:

Screen Shot 2020-07-24 at 10 59 59 AM

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.

ltnilaysahu avatar ltnilaysahu commented on September 28, 2024

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.

eladnava avatar eladnava commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.