使用功能在Firebase中向(分析)受众发送推送通知 [英] Send push notifications in Firebase using functions to (analytics) audiences

查看:120
本文介绍了使用功能在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.

这篇关于使用功能在Firebase中向(分析)受众发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆