【问题标题】:Send push notifications in Firebase using functions to (analytics) audiences在 Firebase 中使用函数向(分析)受众发送推送通知
【发布时间】:2018-04-29 21:39:04
【问题描述】:

我已使用 Firebase 函数触发的 Firebase 云消息传递 (FCM) 成功发送通知:

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));
}

如您所见,我将通知发送到名为“全部”的主题。

在 Firebase 控制台中,您可以向可以创建的受众发送通知。在我的例子中,我根据分析模块中的用户属性创建了不同的受众。

是否也可以通过 Firebase 函数向受众发送通知?

【问题讨论】:

    标签: firebase firebase-cloud-messaging


    【解决方案1】:

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

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

    另见:How to send firebase notifications to audience via HTTP

    【讨论】:

    • 那太可惜了;本来不错。您知道 export.myevent = functions.analytics.event('myEvent').onLog((event) => {...} 是否适用于所有类型的事件或仅适用于购买事件?
    • 您只能在转化事件上触发 Cloud Functions。但 BigQuery 导出将包含所有 Analytics 事件。
    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2020-07-05
    • 2018-12-29
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    相关资源
    最近更新 更多