Introduction

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:

Copy
export function <wixAppName>_<eventName>(event) { }

For example, an event handler that handles loyalty account updates looks like this:

Copy
export function wixLoyalty_onAccountUpdated(event) {}
Did this help?

onLoyaltyImportCreated( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Method Declaration
Copy
function wixLoyaltyImportsV1_onLoyaltyImportCreated(
  event: LoyaltyImportCreated,
): void;
Method Parameters
eventLoyaltyImportCreated
onLoyaltyImportCreated example
JavaScript
export function wixLoyaltyImportsV1_onLoyaltyImportCreated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onAccountPointsUpdated( )


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.

Method Declaration
Copy
function wixLoyalty_onAccountPointsUpdated(event: AccountPointsUpdated): void;
Method Parameters
eventAccountPointsUpdated
An event that triggered when a the points of a loyalty account is updated
JavaScript
// 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 * } * } * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onAccountUpdated( )


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.

Method Declaration
Copy
function wixLoyalty_onAccountUpdated(event: AccountUpdated): void;
Method Parameters
eventAccountUpdated
An event that triggers when a loyalty account is updated
JavaScript
// 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" * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onCouponCreated( )


Triggered when a loyalty coupon is created.

Method Declaration
Copy
function wixLoyalty_onCouponCreated(event: CouponCreated): void;
Method Parameters
eventCouponCreated
onCouponCreated example
JavaScript
export function wixLoyalty_onCouponCreated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onCouponDeleted( )


Triggered when a loyalty coupon is deleted.

Method Declaration
Copy
function wixLoyalty_onCouponDeleted(event: CouponDeleted): void;
Method Parameters
eventCouponDeleted
onCouponDeleted example
JavaScript
export function wixLoyalty_onCouponDeleted(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onProgramUpdated( )


An event that triggers when a loyalty program is updated.

The onProgramUpdated() event handler runs when the name or the point definition of the loyalty program is updated. The received ProgramUpdated object contains information about the program that was updated.

onProgramUpdated() does not trigger when the loyalty program's status changes.

Note: Backend events don't work when previewing your site.

Method Declaration
Copy
function wixLoyalty_onProgramUpdated(event: ProgramUpdated): void;
Method Parameters
eventProgramUpdated

Information about the loyalty program that was updated and metadata for the event.

An event triggered when a loyalty program is updated
JavaScript
// 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_onProgramUpdated(event) { const eventId = event.metadata.id; const programName = event.entity.name; const updatedDate = event.entity._updatedDate; console.log("Program last updated: ", updatedDate); console.log(event); } /* Full event object: * { * "metadata": { * "id":"bc647d5a-0d2c-46db-b241-8eb82c431e86", * "entityId":"settings", * "eventTime":"2022-11-09T07:58:42.945654Z", * "triggeredByAnonymizeRequest":false * }, * "entity": { * "name":"Frequent Flower Program", * "pointDefinition": { * "customName":"Petals", * "icon":"shapes/8de38e8fe76f4e9f937ae23e9ba1eb04.svg" * }, * "status":"ACTIVE", * "_createdDate":"2022-11-07T15:26:12.798Z", * "_updatedDate":"2022-11-09T07:58:42.936Z" * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onRewardCreated( )


Triggered when a reward is created.

Method Declaration
Copy
function wixLoyalty_onRewardCreated(event: RewardCreated): void;
Method Parameters
eventRewardCreated
onRewardCreated example
JavaScript
export function wixLoyalty_onRewardCreated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onRewardDeleted( )


Triggered when a reward is deleted.

Method Declaration
Copy
function wixLoyalty_onRewardDeleted(event: RewardDeleted): void;
Method Parameters
eventRewardDeleted
onRewardDeleted example
JavaScript
export function wixLoyalty_onRewardDeleted(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onRewardUpdated( )


Triggered when a reward is updated.

Method Declaration
Copy
function wixLoyalty_onRewardUpdated(event: RewardUpdated): void;
Method Parameters
eventRewardUpdated
onRewardUpdated example
JavaScript
export function wixLoyalty_onRewardUpdated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onTierCreated( )


Triggered when a tier has been created.

Method Declaration
Copy
function wixLoyalty_onTierCreated(event: TierCreated): void;
Method Parameters
eventTierCreated
onTierCreated example
JavaScript
export function wixLoyalty_onTierCreated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onTierDeleted( )


Triggered when a tier is deleted.

Method Declaration
Copy
function wixLoyalty_onTierDeleted(event: TierDeleted): void;
Method Parameters
eventTierDeleted
onTierDeleted example
JavaScript
export function wixLoyalty_onTierDeleted(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onTierUpdated( )


Triggered when a tier is updated.

Method Declaration
Copy
function wixLoyalty_onTierUpdated(event: TierUpdated): void;
Method Parameters
eventTierUpdated
onTierUpdated example
JavaScript
export function wixLoyalty_onTierUpdated(event) { const eventId = event.metadata.id; const entityId = event.entity._id; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?