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.
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Triggered when the "About" section content is created.
function wixMembersAbout_onMemberAboutCreated(event: MemberAboutCreated): void;
export function wixMembersAbout_onMemberAboutCreated(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 the "About" section content is deleted.
function wixMembersAbout_onMemberAboutDeleted(event: MemberAboutDeleted): void;
export function wixMembersAbout_onMemberAboutDeleted(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 the "About" section content is updated.
function wixMembersAbout_onMemberAboutUpdated(event: MemberAboutUpdated): void;
export function wixMembersAbout_onMemberAboutUpdated(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 member is created.
The site owner can configure the site to automatically approve members or require manual approval.
A member who has been approved either automatically or manually has a status
of APPROVED
. A created member waiting for approval has a status
of PENDING
. A PENDING
member cannot log into the site.
function wixMembers_onMemberCreated(event: MemberCreated): void;
Information about the member that was created.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixMembers_onMemberCreated(event) {
const memberNickname = event.entity.profile.nickname;
const creationEventId = event.metadata.id;
const memberId = event.entity._id;
console.log(`Member with member ID: ${memberId} created.`);
}
/* Full event object:
* {
* "metadata": {
* "id": "b91e0e4e-1869-4705-ae8c-70b456b2ceed",
* "entityId": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "eventTime": "2021-12-10T15:00:29.236054Z",
* "triggeredByAnonymizeRequest": false
* },
* "entity": {
* "loginEmail": "john@example.com",
* "privacyStatus": "PUBLIC",
* "_id": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "_createdDate": "2021-12-10T10:44:37.000Z",
* "_updatedDate": "2021-12-10T10:44:36.939Z",
* "activityStatus": "ACTIVE",
* "profile": {
* "profilePhoto": {
* "_id": "a27d24_0dd318%7Emv2.jpg",
* "url": "http://static.wixstatic.com/media/a27d24_0dd318%7Emv2.jpg",
* "height": 0,
* "width": 0
* },
* "slug": "john40355",
* "coverPhoto": {
* "_id": "",
* "url": "https://example.com/myimage.jpg",
* "height": 0,
* "width": 0
* },
* "title": "Awesome title",
* "nickname": "John Doe"
* },
* "status": "APPROVED",
* "contactId": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "contactDetails": {
* "customFields": {
* "custom.pet-name": {
* "name": "Pet Name",
* "value": "Bob"
* }
* },
* "company": "Wix",
* "phones": [],
* "lastName": "Doe",
* "firstName": "John",
* "birthdate": "2000-01-01",
* "jobTitle": "Developer",
* "emails": [
* "john@example.com"
* ],
* "addresses": [
* {
* "city": "Jewell",
* "addressLine": "10 Cedarstone Drive",
* "_id": "156e50e8-8127-4617-a052-da66bb9a96a0",
* "country": "US",
* "postalCode": "43530",
* "subdivision": "US-OH"
* }
* ]
* }
* }
*}
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a member is deleted.
function wixMembers_onMemberDeleted(event: MemberDeleted): void;
Information about the site member that was deleted.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixMembers_onMemberDeleted(event) {
const deletionEventId = event.metadata.id;
}
/* Full event object:
* {
* "metadata": {
* "id": "6ee4c618-d1f9-4b4b-aca0-270d6984b79a",
* "entityId": "b00d7cd4-9413-4d4f-b9b1-9890f3ce27b9",
* "eventTime": "2021-12-13T09:33:13.654270Z",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
function wixMembers_onMemberUpdated(event: MemberUpdated): void;
Information about the site member that was updated.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixMembers_onMemberUpdated(event) {
const memberUpdateDate = event.entity._updatedDate;
const updateEventId = event.metadata.id;
}
/* Full event object:
*{
* "metadata": {
* "id": "b91e0e4e-1869-4705-ae8c-70b456b2ceed",
* "entityId": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "eventTime": "2021-12-10T15:00:29.236054Z",
* "triggeredByAnonymizeRequest": false
* },
* "entity": {
* "loginEmail": "john@example.com",
* "privacyStatus": "PUBLIC",
* "_id": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "_createdDate": "2021-12-10T10:44:37.000Z",
* "_updatedDate": "2021-12-10T10:44:36.939Z",
* "activityStatus": "ACTIVE",
* "profile": {
* "profilePhoto": {
* "_id": "a27d24_0dd318%7Emv2.jpg",
* "url": "http://static.wixstatic.com/media/a27d24_0dd318%7Emv2.jpg",
* "height": 0,
* "width": 0
* },
* "slug": "john40355",
* "coverPhoto": {
* "_id": "",
* "url": "https://example.com/myimage.jpg",
* "height": 0,
* "width": 0
* },
* "title": "Awesome title",
* "nickname": "John Doe"
* },
* "status": "APPROVED",
* "contactId": "583b58eb-708e-4eba-bb8d-af7f9914721b",
* "contactDetails": {
* "customFields": {
* "custom.pet-name": {
* "name": "Pet Name",
* "value": "Bob"
* }
* },
* "company": "Wix",
* "phones": [],
* "lastName": "Doe",
* "firstName": "John",
* "birthdate": "2000-01-01",
* "jobTitle": "Developer",
* "emails": [
* "john@example.com"
* ],
* "addresses": [
* {
* "city": "Jewell",
* "addressLine": "10 Cedarstone Drive",
* "_id": "156e50e8-8127-4617-a052-da66bb9a96a0",
* "country": "US",
* "postalCode": "43530",
* "subdivision": "US-OH"
* }
* ]
* }
* }
*}
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.