Search...
onContactMerged( )
An event that triggers when one or more source contacts are merged into a target contact.
Description
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.
Syntax
function onContactMerged(event: ContactMergedEvent): void
onContactMerged Parameters
NAME
TYPE
DESCRIPTION
event
ContactMergedEvent
Information about the source and target contacts, and metadata for the event.
Returns
This function does not return anything.
Return Type:
void
Was this helpful?
An event fired when contacts are merged
Copy Code
1// Place this code in the events.js file2// of your site's Backend section.3// Add the file if it doesn't exist.45export function wixCrm_onContactMerged(event) {6 const eventId = event.metadata.id;7 const sourceContactIds = event.data.sourceContactIds;8 const firstSourceContactId = event.data.sourceContactIds[0];9 const targetContactId = event.data.targetContact._id;10 const targetContactName = `${event.data.targetContact.info?.name?.first} ${event.data.targetContact.info?.name?.last}`;1112 console.log('Target contact updated by merge', targetContactId);13 console.log('Source contacts deleted by merge', sourceContactIds);14}1516/* Full event object:17 * {18 * "metadata": {19 * "id": "c6f09a37-8c03-469e-bfa8-9a40939cac66",20 * "entityId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f",21 * "eventTime": "2022-02-02T22:05:47.278693Z",22 * "triggeredByAnonymizeRequest": false23 * },24 * "data": {25 * "sourceContactIds": [26 * "c8e08afd-deac-40f7-b4c1-b42409d35df7"27 * ],28 * "targetContactId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f",29 * "targetContact": {30 * "_id": "49c5d809-6bc8-40b1-86e7-4bf3f6d17adb",31 * "_createdDate": "2022-02-02T21:41:03.306Z",32 * "_updatedDate": "2022-02-02T21:52:00.048Z",33 * "revision": 6,34 * "primaryInfo": {35 * "email": "target.contact@example.com",36 * "phone": "62183848"37 * },38 * "info": {39 * "name": {40 * "first": "Updated Target"41 * },42 * "extendedFields": {43 * "contacts.displayByLastName": "Updated Target",44 * "invoices.vatId": "",45 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",46 * "emailSubscriptions.subscriptionStatus": "NOT_SET",47 * "emailSubscriptions.effectiveEmail": "source.contact@example.com",48 * "contacts.displayByFirstName": "Updated Target"49 * },50 * "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",51 * "phones": [52 * {53 * "tag": "HOME",54 * "_id": "5a53acb4-fd19-411e-93f3-3bd7ca8f9df8",55 * "formattedPhone": "+45 62183848",56 * "countryCode": "DK",57 * "e164Phone": "+4562183848",58 * "primary": true,59 * "phone": "62183848"60 * },61 * {62 * "tag": "WORK",63 * "_id": "b98e5caf-95d6-4fab-b80c-267431b82344",64 * "formattedPhone": "+45 64498094",65 * "countryCode": "DK",66 * "e164Phone": "+4564498094",67 * "primary": false,68 * "phone": "64498094"69 * }70 * ],71 * "labelKeys": [72 * "contacts.contacted-me"73 * ],74 * "picture": {75 * "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"76 * },77 * "emails": [78 * {79 * "tag": "HOME",80 * "email": "target.contact@example.com",81 * "primary": true,82 * "_id": "81109065-7b9e-4b99-b146-b523eb5338ca"83 * },84 * {85 * "tag": "WORK",86 * "email": "source.contact@example.com",87 * "primary": false,88 * "_id": "cd9ea33c-4358-457f-bd99-4384cf5f83c2"89 * }90 * ],91 * "addresses": [92 * {93 * "_id": "a3455bd0-76af-427c-9adc-8d384193f347",94 * "tag": "HOME",95 * "address": {96 * "addressLine1": "4197 Existing Street Address",97 * "city": "Klitmøller",98 * "formatted": "4197 Existing Street Address\nHovedstaden Klitmøller\nDenmark",99 * "country": "DK",100 * "postalCode": "Hovedstaden"101 * }102 * },103 * {104 * "_id": "c3bb555c-a543-4e0a-86e3-341ced30666c",105 * "tag": "WORK",106 * "address": {107 * "addressLine1": "9278 Source Street",108 * "city": "København S",109 * "formatted": "9278 Source Street\n31562 København S\nDenmark",110 * "country": "DK",111 * "postalCode": "31562",112 * "subdivision": "DK-82"113 * }114 * }115 * ]116 * },117 * "source": {118 * "sourceType": "ADMIN",119 * "appId": "manual"120 * },121 * "lastActivity": {122 * "activityDate": "2022-02-02T21:51:59.952Z",123 * "activityType": "CONTACT_MERGED"124 * }125 * }126 * }127 * }128 */