3

I want to add analytics events when the user make a post on the app on Firebase Cloud Function.

The error:

TypeError: functions.analytics.logEvent is not a function

The code:

const functions = require("firebase-functions");
const firestore = require("@google-cloud/firestore");

exports.userPosts = functions.firestore
  .document("posts/{postId}")
  .onUpdate((change, context) => {
    const data = change.after.data();
    const { name, uid } = data;

    functions.analytics.logEvent("make_post", {
      name: name,
      uid: uid,
    });
   }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
k10a
  • 947
  • 2
  • 11
  • 30

1 Answers1

4

It's not possible to log an analytics from backend code. functions.analytics is just used for declaring an Analytics function that triggers when a conversion event occurs. It can't log anything, nor are there any other SDKs that can do so. If you must have this event, you will need to somehow get the client app to log it for the user.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441