Skip to content

Commit 6a4dd15

Browse files
author
Nicolas Garnier
committed
Changing the coupon-on-crash ample to coupon-on-purchase
Change-Id: I409d39403c36da6acc3d246fc2405056f2a490c2
1 parent bebf747 commit 6a4dd15

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ Uses an Auth trigger.
139139
This sample shows how to send a survey to your users who have updated your app. App Update is detected using a Firebase Analytics event.
140140
Uses an Analytics trigger.
141141

142-
### [Send a coupon to users who experienced a crash](/coupon-on-crash)
142+
### [Send a coupon to user who have completed a purchase](/coupon-on-purchase)
143143

144-
This sample shows how to send a coupon to your users if a crash has been detected though a Firebase analytics event.
144+
This sample shows how to send a coupon to your users who have just purchased something. 10% off on your next purchase!
145145
Uses an Analytics trigger.
146146

147147
### [Delete Inactive Users Accounts Cron](/delete-unused-accounts-cron)

coupon-on-crash/README.md renamed to coupon-on-purchase/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Send a coupon via FCM when there is a crash
1+
# Send a coupon via FCM to users who have completed a purchase
22

3-
This sample shows how to send a coupon to your users if a crash has been detected though Firebase analytics.
3+
This sample shows how to send a coupon to your users who have just purchased something. For instance: 10% off on your next purchase!
44

55

66
## Functions Code
@@ -14,14 +14,13 @@ The dependencies are listed in [functions/package.json](functions/package.json).
1414

1515
## Trigger rules
1616

17-
The function triggers on changes to `app_exception` Firebase Analytics events. For other automatically logged events see: https://support.google.com/firebase/answer/6317485
17+
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
1818

1919

2020
## Deploy and test
2121

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

24-
- Make sure you set the `app_exception` events as being a **Conversion event** in your project. You can do this on the Analytics section > Events tab.
2524
- Set the project to your Firebase project using `firebase use --add` then select your projec tin the list.
2625
- Deploy your project using `firebase deploy`
2726
- Make your app crash (somehow).
File renamed without changes.

coupon-on-crash/functions/index.js renamed to coupon-on-purchase/functions/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ admin.initializeApp(functions.config().firebase);
2121

2222
// [START all]
2323
/**
24-
* After a user has experienced a crash of the app. Send them a coupon via FCM.
24+
* After a user has completed a purchase. Send them a coupon via FCM valid on their next purchase.
2525
*/
2626
// [START trigger]
27-
exports.sendCouponOnCrash = functions.analytics.event('app_exception').onLog(event => {
27+
exports.sendCouponOnPurchase = functions.analytics.event('in_app_purchase').onLog(event => {
2828
// [END trigger]
2929
// [START attributes]
3030
const user = event.data.user;
3131
const uid = user.userId; // The user ID set via the setUserId API.
32-
const lifetimeValue = user.ltvInUSD; // Lifetime Value revenue of the user in USD.
32+
const purchaseValue = event.data.valueInUSD; // Amount of the purchase in USD.
3333
const userLanguage = user.deviceInfo.userDefaultLanguage; // The user language in language-country format.
3434
// [END attributes]
3535

36-
// For users with a lifetime revenue above 2000 USD we send a coupon of higher value.
37-
if (lifetimeValue > 2000) {
36+
// For purchases above 500 USD we send a coupon of higher value.
37+
if (purchaseValue > 500) {
3838
return sendHighValueCouponViaFCM(uid, userLanguage);
3939
}
4040
return sendCouponViaFCM(uid, userLanguage);
4141
});
4242
// [END all]
4343

4444
/**
45-
* Sends the given coupon Code via FCM to the list of device tokens.
45+
* Sends a coupon code via FCM to the given user.
4646
*
4747
* @param {string} uid The UID of the user.
4848
* @param {string} userLanguage The user language in language-country format.
@@ -54,17 +54,17 @@ function sendCouponViaFCM(uid, userLanguage) {
5454
// Notification details.
5555
let payload = {
5656
notification: {
57-
title: 'Special Offer!',
58-
body: 'Get 10$ off your next purchase with "CRASH10".'
57+
title: 'Thanks for your Purchase!',
58+
body: 'Get 10% off your next purchase with "COMEBACK10".'
5959
}
6060
};
6161

6262
// Notification in French.
6363
if (userLanguage.split('-')[0] === 'fr') {
6464
payload = {
6565
notification: {
66-
title: 'Offre Speciale!',
67-
body: 'Obtenez 10$ de réduction sur votre prochain achat avec "CRASH10".'
66+
title: 'Merci pour votre achat!',
67+
body: 'Obtenez 10% de réduction sur votre prochain achat avec "COMEBACK10".'
6868
}
6969
};
7070
}
@@ -76,7 +76,7 @@ function sendCouponViaFCM(uid, userLanguage) {
7676
}
7777

7878
/**
79-
* Sends the given coupon Code via FCM to the list of device tokens.
79+
* Sends a high value coupon vode via FCM to the given user.
8080
*
8181
* @param {string} uid The UID of the user.
8282
* @param {string} userLanguage The user language in language-country format.
@@ -88,17 +88,17 @@ function sendHighValueCouponViaFCM(uid, userLanguage) {
8888
// Notification details.
8989
let payload = {
9090
notification: {
91-
title: 'Special Offer!',
92-
body: 'Get 30$ off your next purchase with "CRASH30".'
91+
title: 'Thanks for your Purchase!',
92+
body: 'Get 10% off your next purchase with "COMEBACK30".'
9393
}
9494
};
9595

9696
// Notification in French.
9797
if (userLanguage.split('-')[0] === 'fr') {
9898
payload = {
9999
notification: {
100-
title: 'Offre Speciale!',
101-
body: 'Obtenez 30$ de réduction sur votre prochain achat avec "CRASH30".'
100+
title: 'Merci pour votre achat!',
101+
body: 'Obtenez 10% de réduction sur votre prochain achat avec "COMEBACK30".'
102102
}
103103
};
104104
}

0 commit comments

Comments
 (0)