运行 分析云在本地运行并将分析事件存储到 firestore 集合中?

running an analytic cloud functions locally and storing analytic event into a firestore collection?

我有一个关于 运行 分析云函数的问题,该函数非常简单,只要发生任何注册然后它就会触发,并且该事件存储在我正在使用 firebase 的集合中 emulators:start - - 仅对 运行 函数起作用,当我 运行 宁函数时,正常函数 运行 很好,而不是解析函数,这里是我的代码? 我也想知道这是存储到 firestore 集合中的正确方法吗?

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

const serviceAccountKey = require('./keyv2.json')

admin.initializeApp({
    credential: admin.credential.cert(serviceAccountKey),
});
const db = admin.firestore()
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.helloWorld = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
 console.log('hello')
});

exports.eventStore = functions.analytics.event('sign_up').onLog(async event => {
    console.log('hello')
    console.log(event)
    const user = event.user
    await db.collection('EventLogs').add(user)
    console.log('eventLog is added in the EventLogs collection')
})

Google Firebase 模拟器当前未实现 Analytics for Firebase 事件。请参阅有关模拟器套件的 Firebase 文档,特别是 which Firebase features and platforms are supported?

部分

您的 Analytics 触发函数的代码看起来不错,但您需要:

  1. 确保您的代码 returns 与 Cloud Functions 环境相关,以便它知道您的代码何时完成。在这种情况下,函数末尾的简单 return true 就足够了。
  2. 我不完全确定 event.user 是否可以序列化为 JSON,因此可能值得将其包装在 JSON.parse(JSON.stringify(user)).