How to get user email using firebase analytics event parameter?

Viewed 337

I'm making app using firebase on back-end part. User can log in myApp using google account and can backup their data.

I want to delete some doc at cloud when user uninstall myApp.
collection ID is user email. So I need to know user email but I don't know how to get this.

exports.appUninstall = functions.analytics.event("app_remove").onLog((event)=>{
  const userEmail = event.user.email;
  database.doc(userEmail + "/user_logged_in").delete();
  return console.log("Deleted user_logged_in because user uninstalled app");
});
1 Answers

I don't think this is possible with the structure you currently have. As you can see here, the onLog() returns a AnalyticsEvent object that has a UserDimensions object inside of it, however, that object stores the userId and an object with the userProperties.

I can' t say for sure that this userProperties will store the email of your user so you can fetch in firestore, so you need to test this. If not, you will have to find a way get the user document with it's userId, maybe by adding it to the document itself on creation.

This would be easier if you changed the documentId to be the userId instead of the email, if you do that you can simply use the mentioned userId of the event to get the document and delete it.

Related