Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't log an analytics event on Firebase Cloud Function [duplicate]

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,
    });
   }
like image 495
k10a Avatar asked Sep 15 '26 16:09

k10a


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.

like image 120
Doug Stevenson Avatar answered Sep 18 '26 14:09

Doug Stevenson