Wix CRM events are fired in your site's backend when certain events related to site contacts 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 contact related events.
Note: Backend events don't work when previewing your site.
To add a CRM 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:
For example, an event handler that handles contact updates looks like this:
Triggered when a contact is created.
Information about the contact that was created and metadata for the event.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a contact is deleted.
If a contact is deleted as part of a merge, the originatedFrom
property is sent as merge
.
Otherwise, originatedFrom
isn't returned.
Metadata for the event.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when one or more source contacts are merged into a target contact.
Information about the source and target contacts, and metadata for the event.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a contact is updated.
Information about the contact that was updated and metadata for the event.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a label is created.
Information about the task that was created and metadata for the event.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a label is deleted.
function wixContacts_onLabelDeleted(event: LabelDeleted): void;
Metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixContacts_onLabelDeleted(event) {
console.log("Label deleted", event);
}
/* Full event object:
* {
* "metadata": {
* "id": "64c54bac-5c9c-42b6-b43b-9143e6814b50",
* "entityId": "custom.customer-group-3",
* "eventTime": "2024-01-11T12:47:31.862945419Z",
* "triggeredByAnonymizeRequest": false
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.