FaxStore
A reference for the routes, events and functions behind Abandoned Carts, for staff who build apps or integrations. Apps can listen for the events below with faxstore.on(), the same way as the other FaxStore Events.
Table of Contents
Saving carts. Every change to a cart goes through faxstore.carts.save(), which saves users.cart and stamps users.cartUpdatedAt. Guests' carts go through faxstore.carts.saveGuest() into the guestcarts table, kept by the fxcart cookie.
The sweep. Every 10 minutes a sweep runs, and does five things:
Abandoned carts: carts left for longer than Count a cart as abandoned after become rows in the abandonedcarts table, and cartAbandoned fires. Guests count only once they've given their email and ticked the reminders box.
Lost carts: open carts left for longer than Mark a cart lost after become lost.
Reminders: the next reminder that's due is sent for each open cart, by email, Discord DM or both, unless it's quiet hours for the customer. cartReminderSent fires.
Browse reminders: these go out to customers who viewed a product often enough (recorded in productviews by faxstore.carts.viewed()), and browseReminderSent fires.
Cleanup: once a day, expired recovery coupons that were never used, and guest carts unused for 60 days, are deleted.
Checkouts. When a checkout finishes, faxstore.carts.converted() marks the customer's cart recovered or purchased, and cartRecovered fires. This covers PayPal, Stripe, Square, free checkouts and Tebex.
Survey answers. When a customer answers the survey (from an email or the exit offer), cartFeedback fires.
Signing in. When a guest signs in to a verified account, getUserInfo() calls faxstore.carts.mergeGuest(), which adds their guest cart to the account's cart.
A cart's last activity is the later of its last change and the last time the customer started checkout (from checkout_sessions).
Listen with faxstore.on(name, function(...) {}). Each event passes the cart object first, then an object with more detail. cartAbandoned doesn't fire for older carts (carts from before this update). For guests, its second argument includes guest: true. For carts started by the exit offer, it includes source: 'exit-offer'.
Name | Arguments | Description | Type |
|---|---|---|---|
|
| A cart has been left for longer than Count a cart as abandoned after. | on |
|
| A reminder was sent. | on |
|
| The customer checked out. | on |
|
| The customer answered the survey. | on |
|
| A browse reminder was sent for a product the customer viewed | on |
The existing checkout events still fire as before: createCheckout, checkoutReturn, checkoutCancel and checkoutExpired.
Example. An app that posts recovered carts to a Discord channel:
module.exports = function(app, connection, bot, faxstore) {
faxstore.on('cartRecovered', function(cart, details) {
if(details.status !== 'recovered') return;
const channel = faxstore.discord.bot.channels.cache.get('1093456789012345678');
channel?.send(`A customer came back and spent $${details.total} (${details.via}).`).catch(() => {});
});
};The first argument to every event is the cart's row from the abandonedcarts table. The link token and timeline are left out.
Field | Description |
|---|---|
| The cart's ID. |
| The customer's user ID, or an empty string for a guest. |
| For guests: their |
| When the customer used the exit offer. |
| The cart's contents, in the same format as |
| The number of items. |
| The cart's value at list price. |
|
|
|
|
|
|
| When the cart was found to be abandoned (milliseconds). |
| The customer's last activity in the cart. |
| The last reminder sent (0 to 3). |
| Reminder emails sent. |
| When the last reminder was sent. |
| Clicks on the email's button, and the first click. |
| When the customer opened their cart from the on-site reminder. |
| Whether automatic reminders are stopped, and why: |
| The recovery coupon's |
| The customer's survey answer: the reason's key, their comment and when they answered. The label they saw is kept in the timeline. |
| How the cart was closed. |
| When the row was created. |
Function | Description |
|---|---|
| Saves a cart, given as an array of entries or a comma-separated string, and returns the saved entries. It also sets |
| The same for a signed-out visitor. The first save creates their |
| For |
| Adds a guest cart to a signed-in account's cart, moves its open abandoned cart to the account, and clears the cookie. Returns the merged cart, or |
| Whether guest carts are on. |
| Call after a checkout finishes. Marks the customer's latest open or lost cart from the last 30 days as |
| Records a signed-in customer viewing a product page, for browse reminders. Each customer and product is written at most once every 30 minutes. |
| What the cart page's exit offer shows: `{mode: 'coupon' |
| Builds or emails the abandoned carts summary. |
|
|
| Records that the customer opened their cart from the on-site reminder. |
| Returns |
| Runs the sweep straight away. Returns |
| Reads the settings JSON, filling in defaults. |
| The default settings. |
| The survey reasons in a settings JSON, as |
Settings are saved as JSON in sitesettings.abandonedCarts. Missing or out-of-range values fall back to these defaults:
{
"enabled": false,
"abandonAfterMinutes": 60,
"minValue": 0,
"lostAfterDays": 14,
"steps": [
{"enabled": true, "delayHours": 1, "coupon": false, "channel": "email", "subject": "Did you forget something?", "subjectB": "", "message": "..."},
{"enabled": true, "delayHours": 24, "coupon": false, "channel": "email", "subject": "Your cart is still waiting", "subjectB": "", "message": "..."},
{"enabled": false, "delayHours": 72, "coupon": true, "channel": "email", "subject": "Here's {{DISCOUNT}} off your cart", "subjectB": "", "message": "..."}
],
"coupon": {"enabled": false, "percent": 10, "expiresDays": 3, "cooldownDays": 30, "prefix": "COMEBACK"},
"feedback": {
"enabled": true,
"question": "What stopped you from checking out?",
"prompt": "Not ready to buy? Tell us why:",
"comment": true,
"thanks": "Your answer helps us make the store better.",
"reasons": [
{"key": "price", "label": "Too expensive", "enabled": true, "email": true},
{"key": "browsing", "label": "Just browsing", "enabled": true, "email": true},
{"key": "payment", "label": "Payment problem", "enabled": true, "email": true},
{"key": "info", "label": "Needed more info", "enabled": true, "email": true},
{"key": "elsewhere", "label": "Bought elsewhere", "enabled": true, "email": false},
{"key": "other", "label": "Something else", "enabled": true, "email": true}
]
},
"nudge": {"enabled": true, "afterMinutes": 60},
"alerts": {"enabled": false, "minValue": 50, "discordChannel": "", "recovered": true},
"guests": {"enabled": true, "capture": true},
"exitOffer": {"enabled": false, "offer": "auto", "minValue": 0, "mobileDelay": 30, "title": "Wait, before you go!", "message": "..."},
"browse": {"enabled": false, "minViews": 2, "afterHours": 24, "withinDays": 14, "cooldownDays": 7, "channel": "email", "subject": "Still thinking about {{PRODUCT_NAME}}?", "message": "..."},
"extras": {"ratings": true, "stock": true, "suggestions": 3},
"quietHours": {"enabled": false, "start": 21, "end": 8}
}Field | Range |
|---|---|
| 15 to 1,440 |
| 1 to 90 |
| 1 to 720. Each turned-on reminder must be later than the one before. |
|
|
| Up to 150 characters. Empty means no A/B test. |
|
|
| 5 to 300 seconds |
| 1 to 20 |
| 1 to 168 hours, 1 to 60 days, and 0 to 90 days |
| 0 to 4 |
| 0 to 23 (hours). The window can wrap past midnight. |
| 1 to 90 |
| 1 to 30 |
| 0 to 365 |
| Up to 12 letters and numbers |
| 5 to 10,080 |
| Up to 120 characters |
| Up to 500 characters |
| Up to 10. Each |
Reminders use files/email-templates/cart.html, which is based on the generic template. FaxStore sends this template to abandoned cart customers and guests. To edit the template and change any pre-fills see the Email System & Notifications guide.