Introduction

Wix events are fired in your site's backend when certain events occur in your site's store. 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 marketing events.

To add a marketing 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

For example, an event handler that handles coupon creation in a Wix site looks like this:

Copy

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

Did this help?

onCouponApplied( )


An event that is triggered when a coupon is used.

The onCouponApplied() event handler runs when an order with an applied coupon is completed, or when an order is manually marked as paid.

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

Method Declaration
Copy
Method Parameters
eventCouponAppliedEventRequired

Information about an applied coupon.

An event when a coupon is applied
JavaScript
Did this help?

onCouponCreated( )


An event that is triggered when a coupon is created.

The onCouponCreated() event handler runs when a new coupon is created.

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

Method Declaration
Copy
function onCouponCreated(event: CouponEvent): void;
Method Parameters
eventCouponEventRequired

Information about a newly created coupon.

An event when a coupon is created
JavaScript
// Place this code in the events.js file // of your site's Backend section. export function wixMarketing_onCouponCreated(event) { const newCouponId = event.entity._id; const newCouponType = event.entity.type; const couponValidFrom = event.entity.startTime; } /* Full event object * * { * "metadata": { * "id": "c4ea2c0a-0952-48ad-9b15-39e660448663", * "entityId": "03a35393-7835-44b0-af53-6019a484b48b", * "eventTime": "2021-01-17T11:40:56.795047Z", * "triggeredByAnonymizeRequest": false * }, * "entity": { * "_id": "03a35393-7835-44b0-af53-6019a484b48b", * "name": "Summer Sale 10% off", * "code": "SummerSale", * "startTime": "Wed Jun 30 2021 21:00:00 GMT+0000 (Coordinated Universal Time)", * "expirationTime": "Tue Aug 31 2021 20:59:59 GMT+0000 (Coordinated Universal Time)", * "limitPerCustomer": 1, * "active": true, * "scope": { * "namespace": "stores" * }, * "_dateCreated": "Sun Jan 17 2021 11:40:56 GMT+0000 (Coordinated Universal Time)", * "expired": false, * "displayData": null, * "limitedToOneItem": true, * "type": "PercentOff", * "percentOffRate": 10 * } * } * */
Did this help?