Pull request Compare This branch is 3 commits ahead, 114 commits behind Node-8.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
functions Upgrade all firebase-admin imports to 5.11.0 Apr 3, 2018
firebase.json Changing the coupon-on-crash ample to coupon-on-purchase Mar 7, 2017


Send a coupon via FCM to users who have completed a purchase

This sample shows how to send a coupon to your users who have just purchased something. For instance: 10% off on your next purchase!

Functions Code

See file functions/index.js for the trigger and the FCM code.

The function assumes that you are setting the Firebase Analytics User ID to be the same as the Firebase Auth uid using the setUserId API. Also it is assumed that the FCM Device Tokens need to be saved in the Firebase Realtime Database under /users/$uid/tokens.

The dependencies are listed in functions/package.json.

Trigger rules

The function triggers on changes to in_app_purchase Firebase Analytics events. For other automatically logged events see: https://support.google.com/firebase/answer/6317485

Deploy and test

This sample can be tested on your Android and iOS app. To test it out:

  • Set the project to your Firebase project using firebase use --add then select your projec tin the list.
  • Deploy your project using firebase deploy
  • Make your app crash (somehow).
  • Within a few hours the coupon will be sent by an FCM notification.