0

I want to send firebase Analytics custom log event from Firebase Functions (with node.js). I have searched a lot but I couldn't find any tutorial or ducumentation about it. Is there any way to send custom event to firebase analytics from backend in 2024? I have tried to send log with

admin.analytics().log()...

but there was a syntax error analytics is not a function

1 Answer 1

1

You don't send events from your backend to Firebase. Firebase is a proxy endpoint for analytics data collected from apps. It's a proxy in a sense that the analytics data in Firebase is essentially unusable. You proxy it to a GA4 instance from Firebase.

GA4 allows direct tracking from backend using the measurement protocol. Be very careful with the measurement protocol. It requires you to set a lot of ids if you want this data to be connected to the rest of it. And if this thing in Node that you want to track doesn't need to be connected to the rest of user activity, then GA/Firebase is definitely a wrong tool to use for it.

Still, you can use the Firebase sdk by routing your Node events through the apps and then having apps translating those into analytics payloads.

4
  • The problem is I want to send events whenever google send RTDN message to my server, so my app does not know about these messages Commented Jun 21 at 8:52
  • What kind of info do you get in RTDN? That's normally just purchase confirmations so that you could securely update the backend without trusting your front-end about the purchase. Front-end, however, also gets the purchase callback result. Just track that callback on the FE.
    – BNazaruk
    Commented Jun 21 at 16:43
  • RTDN is related to user purchase whenever subscription is paused or canceled or expired,renewed and so on, i want to send this information to analytics alongside putting on database. Commented Jun 21 at 17:57
  • uh, it's going to be difficult. Yeah, in that case you'll have to use the measurement protocol. However, you'll need to use the right client id otherwise you won't be able to map the event to the user. The client id is automatically generated by the firebase sdk on the first hit and then maintained. Or you could introduce user id tracking and use the same user id tracking when reporting on RTDN events. Then build your dashboards accordingly.
    – BNazaruk
    Commented Jun 21 at 21:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.