Can't log an analytics event on Firebase Cloud Function

Viewed 735

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,
    });
   }
1 Answers

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.

Related