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,
});
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With