Wix Loyalty events are fired in your site's backend when certain events related to loyalty occur in your site's backend. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to loyalty events.
Note: Backend events don't work when previewing your site.
To add a loyalty event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.
Event handler functions are defined using the following pattern:
export function <wixAppName>_<eventName>(event) { }
For example, an event handler that handles loyalty account updates looks like this:
export function wixLoyalty_onAccountUpdated(event) {}
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
function wixLoyaltyImportsV1_onLoyaltyImportCreated(
event: LoyaltyImportCreated,
): void;
export function wixLoyaltyImportsV1_onLoyaltyImportCreated(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that triggers when the points of a loyalty account are adjusted, earned, or redeemed.
The onAccountPointsUpdated()
event handler runs when the points of a loyalty account are adjusted, earned, or redeemed. The received AccountPointsUpdated
object contains information about the loyalty account that was updated.
Note: Backend events don't work when previewing your site.
function wixLoyalty_onAccountPointsUpdated(event: AccountPointsUpdated): void;
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixLoyalty_onAccountPointsUpdated(event) {
const eventId = event.metadata.id;
const accountBalance = event.data.account.points.balance;
console.log("Current account balance: ", accountBalance);
console.log(event);
}
/* Full event object:
* {
* "metadata": {
* "id":"447912e4-b460-4eba-9bd2-3c19b64ddce0",
* "entityId":"1ab8f49c-a329-4ddc-a31d-814afbb3b565",
* "eventTime":"2023-01-18T13:16:53.000613Z",
* "triggeredByAnonymizeRequest":false
* },
* "data": {
* "account": {
* "_id":"1ab8f49c-a329-4ddc-a31d-814afbb3b565",
* "contactId":"3128dc64-74fc-442f-aa32-e8e871dad141",
* "memberId":"3128dc64-74fc-442f-aa32-e8e871dad141",
* "points": {
* "balance":95,
* "earned":45,
* "adjusted":50,
* "redeemed":0
* },
* "rewardAvailable":true,
* "_createdDate":"2022-11-28T11:57:30.722Z",
* "_updatedDate":"2023-01-18T13:16:52.982Z",
* "lastActivityDate":"2023-01-18T13:16:52.980Z",
* "revision":"13",
* "tier": {
* "_id":"a8a2bc2b-6957-40a6-9f20-a1bfe52d14de",
* "_updatedDate":"2023-01-18T13:16:52.980Z",
* "points":95
* }
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that triggers when a loyalty account is updated.
The onAccountUpdated()
event handler runs when a loyalty account is updated. The received AccountUpdated
object contains information about the loyalty account that was updated.
The event also runs every 15 minutes when loyalty points are recalculated.
Note: Backend events don't work when previewing your site.
function wixLoyalty_onAccountUpdated(event: AccountUpdated): void;
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixLoyalty_onAccountUpdated(event) {
const eventId = event.metadata.id;
const updatedDate = event.entity._updatedDate;
console.log("Account was last updated on ", updatedDate);
console.log(event);
}
/* Full event object:
* {
* "metadata": {
* "id":"e6576ab6-1439-4f20-b698-3b2aa82087c8",
* "entityId":"f0411f1a-ad5a-4b80-94c2-34350cbf1af7",
* "eventTime":"2023-01-02T00:45:02.145871Z",
* "triggeredByAnonymizeRequest":false
* },
* "entity": {
* "_id":"f0411f1a-ad5a-4b80-94c2-34350cbf1af7",
* "contactId":"8a71f711-f77b-43fe-9e3d-5c243f94b2cd",
* "points": {
* "balance":50,
* "earned":50,
* "adjusted":0,
* "redeemed":0
* },
* "rewardAvailable":false,
* "_createdDate":"2022-11-09T06:44:48.159Z",
* "_updatedDate":"2023-01-02T00:45:02.091Z",
* "lastActivityDate":"2022-11-09T14:54:57.349Z",
* "revision":"1226"
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a loyalty coupon is created.
function wixLoyalty_onCouponCreated(event: CouponCreated): void;
export function wixLoyalty_onCouponCreated(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a loyalty coupon is deleted.
function wixLoyalty_onCouponDeleted(event: CouponDeleted): void;
export function wixLoyalty_onCouponDeleted(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.