What it does
This template sends up to three emails over five days, depending on whether the customer redeems their coupon. If they redeem on day one, follow-ups stop. If they do not redeem, they get a reminder on day three and a final message before expiry.
Codes are generated in JavaScript and stored in MongoDB. Redemption is checked from that collection, so you keep the data and avoid a separate voucher API.
How it runs
A new customer hits the trigger. A script generates a unique code in the format
WELCOME-<prefix>-<random>, sets a 15% discount, and stamps an expiry seven days out. That
voucher is saved to MongoDB with redeemed: false, then Gmail sends the welcome email with the
code.
The workflow waits three days and checks MongoDB. If redeemed is true, it exits. If not, it
sends a reminder, waits two more days, and checks again. If the code is still unused, it sends a
final expiry email. If redemption happens at any point, the workflow exits quietly. Your checkout
must set redeemed to true when the code is used.
The steps
- JavaScript (map_input): Pulls email, name, and a source ID from the trigger payload.
- JavaScript (generate_voucher): Builds the unique code, sets the discount label, and calculates the 7-day expiry.
- MongoDB (store_voucher): Inserts the voucher document. This is the source of truth for redemption status.
- Gmail (gmail_send_welcome): Welcome email with the code, discount, and expiry date.
- Wait (wait_1): 3 days.
- MongoDB (check_redemption): Looks up the voucher to see if it has been redeemed.
- Switch (check_redeemed_branch): Redeemed exits. Not redeemed continues to the reminder sequence.
- Gmail (gmail_send_reminder): Day 3 reminder with the same code.
- Wait (wait_2): 2 more days.
- MongoDB (check_redemption_final): Second redemption check.
- Switch (final_expiry_branch): Redeemed exits. Still unused sends the final expiry email.
- Gmail (gmail_send_expiry): Last-chance email before the code expires.
Design notes
Redemption is checked before each reminder, not after. If a customer redeems on day two, they do not receive the day-three reminder. That avoids sending a discount reminder after the code is already used.
The voucher code is generated locally and stored in MongoDB, not pulled from a voucher service.
Your checkout should set redeemed: true when the code is used, usually a small update in your
order flow. Once that is wired, the workflow runs without external voucher dependencies.
Setup
- Connect your MongoDB and Gmail integrations.
- Create a
voucherscollection (no schema required; the workflow writes the document shape). - Replace the
fromaddress in the three Gmail steps with your verified sender. - Set the
shop_urlworkflow variable to your storefront link. - Update
vouchers.redeemedtotruein checkout when a code is used, filtering by thecodefield. - Trigger with a payload containing
subscriberEmail,subscriberName, andsubscriberSourceId.
When to use it
- E-commerce welcome flows where you want unique-per-customer codes instead of a shared
WELCOME15. - You want to stop follow-ups after a customer has already purchased.
- You prefer not to pay a separate voucher platform per code.