Get notified each time a new user opens your app the first time or removes your app from their device.
This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Analytics triggered Function.
See file functions/index.js for the code.
Sending the notification is done using the Firebase Admin SDK.
The dependencies are listed in functions/package.json.
The functions triggers every time a new user opens your app the first time or removes your app from their device.
To deploy and test the sample:
-
Create a Firebase project on the Firebase Console
-
In the Firebase Console, under
Analytics, in theEventstab, mark theapp_removeevent a conversion event by switching the toggle. Thefirst_openevent should already be marked as such. -
Install the required dependencies by running
npm installin thefunctionsdirectory -
Add this log to your android project:
Log.d("Firebase", "token "+ FirebaseInstanceId.getInstance().getToken());
-
Run your app on your device and copy the device token from the android logcat
-
Set the
dev_motivator.device_tokenGoogle Cloud environment variables. For this use:firebase functions:secrets:set DEV_MOTIVATOR_DEVICE_TOKEN
-
Deploy your project's code using
firebase deploy -
You'll now get a notification on your mobile when a user opens your app for the first time and when they uninstall your app.