Events are triggered in your site’s backend when certain changes occur to your site’s members. You can write event handlers that react to these events. Event handler functions receive data that correspond to the backend event that has occurred. Use event handlers to create custom responses to the events.
Note: Backend events don’t work when previewing your site.
To add a members event handler, add an events.js file to the Backend or 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 the creation of a member looks like this:
export function wixMembers_onMemberCreated(event) {}
Triggered when a member receives a badge.
function wixBadges_onBadgeAssigned(event: BadgeAssignedEvent): 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 wixBadges_onBadgeAssigned(event) {
const memberId = event.data.memberId;
console.log(`Badge assgigned to member ${memberId}`);
}
/* Full event object:
* {
* "data": {
* "memberId": "ff20c02e-3d13-4412-9529-d628aa0abc12"
* },
* "metadata": {
* "entityId": "348b66e1-fb48-4b2d-8a68-6c69e3ac967b",
* "eventTime": "2024-03-22T06:09:09.752905936Z",
* "id": "25bf06fe-c6bb-4254-a1d0-a98502a6a041",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a badge is created.
function wixBadges_onBadgeCreated(event: BadgeCreated): void;
export function wixBadgesV4_onBadgeCreated(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 badge is deleted.
function wixBadges_onBadgeDeleted(event: BadgeDeleted): void;
export function wixBadgesV4_onBadgeDeleted(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 member's badge is removed.
function wixBadges_onBadgeUnassigned(event: BadgeUnassignedEvent): 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 wixBadges_onBadgeUnassigned(event) {
const memberID = event.data.memberId;
const eventTime = event.metadata.eventTime;
console.log(
`Member: ${memberID} has been unassigned from badge at ${eventTime}`,
);
}
/* Full event object:
* {
* "data": {
* "memberId": "a292ced4-245c-49e5-a368-1120b309878d"
* },
* "metadata": {
* "entityId": "baef3e0b-c3cb-455c-bed4-b139ed0dcc93",
* "eventTime": "2024-03-29T08:34:42.018598896Z",
* "id": "44b43138-5427-4557-bae3-75f4dd1670d2",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a badge is updated.
function wixBadges_onBadgeUpdated(event: BadgeUpdated): void;
export function wixBadgesV4_onBadgeUpdated(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.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Triggered when a badge is created.
function wixBadgesV4_onBadgeCreated(event: BadgeCreated): void;
export function wixBadgesV4_onBadgeCreated(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.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Triggered when a badge is deleted.
function wixBadgesV4_onBadgeDeleted(event: BadgeDeleted): void;
export function wixBadgesV4_onBadgeDeleted(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.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Triggered when a badge is updated.
function wixBadgesV4_onBadgeUpdated(event: BadgeUpdated): void;
export function wixBadgesV4_onBadgeUpdated(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.