Search code examples
javascripttypescriptfirebase-cloud-messaginglabelsend

How do I add an analytics label to data messages with the Javascript (or typescript) Firebase Admin SDK?


I want set a label in the message.And I read the official document here and similar question here.

But I can't figure out how to write it in javascript.

my code here:

const message = {
    notification: {
        title: "myTitle",
        body: "myBody"
    },
    condition: "!('TopicA' in topics)",
    AnalyticsLabel : "mylabel"             <=== something like this?
};
const response = await admin.messaging().send(message);

Solution

  • Here is the trick...

    const message = {
        notification: {
            title: "myTitle",
            body: "myBody"
        },
        condition: "!('TopicA' in topics)",
        fcmOptions: {
            analyticsLabel : "MyLabel"
        }
    };