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

查看:19
本文介绍了在 Firebase 中使用函数向(分析)受众发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用 Firebase 函数触发的 Firebase 云消息传递 (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 函数向受众发送通知?

推荐答案

没有分析 API 来检索属于特定分析受众的用户.也没有 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通过 HTTP 向观众发送通知

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

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