使用功能在Firebase中向(分析)受众发送推送通知

使用功能在Firebase中向(分析)受众发送推送通知

问题描述:

我已经使用由Firebase功能触发的Firebase Cloud Messaging(FCM)成功发送了通知:

I have successfully send notifications using Firebase Cloud Messaging (FCM) triggered by a Firebase function:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const fs = require('fs');

admin.initializeApp();


exports.testNotif = functions.https.onRequest((request, response) => {

    const mySecretNumber = getRandomInt(147)

    var payload = {
      notification: {
        title: `You got a new Message`,
        body: `My highest break ${mySecretNumber}`,
        badge: mySecretNumber.toString(),
        sound: `notif1.aiff`,
      }
    };
 const ackString = `All done ${mySecretNumber}`;
 console.log(ackString)
 response.send(ackString);
 //send to all topic
 admin.messaging().sendToTopic(`all`, payload)
});


function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

如您所见,我正在将通知发送到名为全部"的主题.

As you can see I am sending the notifications to a topic called 'all'.

您可以在Firebase控制台中将通知发送给您可以创建的受众.以我为例,我根据分析模块中的用户属性创建了不同的受众群体.

In the firebase console you can send notifications to an audience that you can create. In my case I have created different audiences based on user properties from the analytics module.

是否还可以通过Firebase功能向受众发送通知?

没有Analytics API可以检索属于特定Analytics(分析)受众的用户.也没有FCM API可以向此类受众发送通知.

There is no Analytics API to retrieve the users that fall into a specific analytics audience. Nor is there an FCM API to send a notification to such an audience.

如果要向受众发送通知,则必须创建自己的方式来定义这些受众.最直接的方法是将Google Analytics for Firebase连接到BigQuery,然后根据您在那里收到的分析事件来定义受众.

If you want to send notifications to audiences, you'll have to create your own way of defining these audiences. The most direct way is to connect Google Analytics for Firebase to BigQuery, and then define the audience on the analytics events you receive there.