onContactMerged( )


An event that triggers when one or more source contacts are merged into a target contact.

The onContactMerged() event handler runs when a contact is merged. The received ContactMergedEvent object contains event metadata.

Merging contacts triggers these events:

  • onContactMerged() is triggered.
  • onContactUpdated() is triggered for the target contact. metadata.originatedFrom is sent as "merge".
  • onContactDeleted() is triggered for each source contact. metadata.originatedFrom is sent as "merge".

If you handle the originating merge event, you can ignore update and delete events where metadata.originatedFrom is set to "merge". When onContactUpdated() and onContactDeleted() are not triggered from a merge, originatedFrom is omitted from their event object.

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

Method Declaration
Copy
function onContactMerged(event: ContactMergedEvent): void;
Method Parameters
eventContactMergedEventRequired

Information about the source and target contacts, and metadata for the event.

An event fired when contacts are merged
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 wixCrm_onContactMerged(event) { const eventId = event.metadata.id; const sourceContactIds = event.data.sourceContactIds; const firstSourceContactId = event.data.sourceContactIds[0]; const targetContactId = event.data.targetContact._id; const targetContactName = `${event.data.targetContact.info?.name?.first} ${event.data.targetContact.info?.name?.last}`; console.log("Target contact updated by merge", targetContactId); console.log("Source contacts deleted by merge", sourceContactIds); } /* Full event object: * { * "metadata": { * "id": "c6f09a37-8c03-469e-bfa8-9a40939cac66", * "entityId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f", * "eventTime": "2022-02-02T22:05:47.278693Z", * "triggeredByAnonymizeRequest": false * }, * "data": { * "sourceContactIds": [ * "c8e08afd-deac-40f7-b4c1-b42409d35df7" * ], * "targetContactId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f", * "targetContact": { * "_id": "49c5d809-6bc8-40b1-86e7-4bf3f6d17adb", * "_createdDate": "2022-02-02T21:41:03.306Z", * "_updatedDate": "2022-02-02T21:52:00.048Z", * "revision": 6, * "primaryInfo": { * "email": "target.contact@example.com", * "phone": "62183848" * }, * "info": { * "name": { * "first": "Updated Target" * }, * "extendedFields": { * "contacts.displayByLastName": "Updated Target", * "invoices.vatId": "", * "emailSubscriptions.deliverabilityStatus": "NOT_SET", * "emailSubscriptions.subscriptionStatus": "NOT_SET", * "emailSubscriptions.effectiveEmail": "source.contact@example.com", * "contacts.displayByFirstName": "Updated Target" * }, * "profilePicture": "https://img-wixmp-8be454c954980f083caba37c.wixmp.com/sites/7b940519-404c-4972-9f03-9a430b68d52c/49c5d809-6bc8-40b1-86e7-4bf3f6d17adb/ecb8b31b-845c-4bc6-b868-73df78a92313-avatar-v2.jpeg::fil:100_100", * "phones": [ * { * "tag": "HOME", * "_id": "5a53acb4-fd19-411e-93f3-3bd7ca8f9df8", * "formattedPhone": "+45 62183848", * "countryCode": "DK", * "e164Phone": "+4562183848", * "primary": true, * "phone": "62183848" * }, * { * "tag": "WORK", * "_id": "b98e5caf-95d6-4fab-b80c-267431b82344", * "formattedPhone": "+45 64498094", * "countryCode": "DK", * "e164Phone": "+4564498094", * "primary": false, * "phone": "64498094" * } * ], * "labelKeys": [ * "contacts.contacted-me" * ], * "picture": { * "image": "https://img-wixmp-8be454c954980f083caba37c.wixmp.com/sites/7b940519-404c-4972-9f03-9a430b68d52c/49c5d809-6bc8-40b1-86e7-4bf3f6d17adb/ecb8b31b-845c-4bc6-b868-73df78a92313-avatar-v2.jpeg::fil:100_100" * }, * "emails": [ * { * "tag": "HOME", * "email": "target.contact@example.com", * "primary": true, * "_id": "81109065-7b9e-4b99-b146-b523eb5338ca" * }, * { * "tag": "WORK", * "email": "source.contact@example.com", * "primary": false, * "_id": "cd9ea33c-4358-457f-bd99-4384cf5f83c2" * } * ], * "addresses": [ * { * "_id": "a3455bd0-76af-427c-9adc-8d384193f347", * "tag": "HOME", * "address": { * "addressLine1": "4197 Existing Street Address", * "city": "Klitmøller", * "formatted": "4197 Existing Street Address\nHovedstaden Klitmøller\nDenmark", * "country": "DK", * "postalCode": "Hovedstaden" * } * }, * { * "_id": "c3bb555c-a543-4e0a-86e3-341ced30666c", * "tag": "WORK", * "address": { * "addressLine1": "9278 Source Street", * "city": "København S", * "formatted": "9278 Source Street\n31562 København S\nDenmark", * "country": "DK", * "postalCode": "31562", * "subdivision": "DK-82" * } * } * ] * }, * "source": { * "sourceType": "ADMIN", * "appId": "manual" * }, * "lastActivity": { * "activityDate": "2022-02-02T21:51:59.952Z", * "activityType": "CONTACT_MERGED" * } * } * } * } */
Errors

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

Did this help?