Search.../

onContactMerged( )

Developer Preview

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 wixCrm_onContactMerged(event: ContactMergedEvent): void

onContactMerged Parameters

NAME
TYPE
DESCRIPTION
event
Optional
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 a contact is merged

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export 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}`;
11
12 console.log('Target contact updated by merge', targetContactId);
13 console.log('Source contacts deleted by merge', sourceContactIds);
14}
15
16/* Full event object:
17 * {
18 * "metadata": {
19 * "id": "c6f09a37-8c03-469e-bfa8-9a40939cac66",
20 * "entityId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f",
21 * "eventTime": "2024-01-14T10:26:38.848Z",
22 * "triggeredByAnonymizeRequest": false
23 * },
24 * "data": {
25 * "sourceContactIds": [
26 * "2ca312b3-e850-465a-9991-c59c9c140919"
27 * ],
28 * "targetContactId": "527676cc-2f20-4318-a76f-07854e02be2c",
29 * "targetContact": {
30 * "revision": 3,
31 * "source": {
32 * "sourceType": "ADMIN"
33 * },
34 * "lastActivity": {
35 * "activityDate": "2024-01-14T10:26:38.848Z",
36 * "activityType": "CONTACT_MERGED"
37 * },
38 * "primaryInfo": {
39 * "email": "j.jackson@example.com",
40 * "phone": "646-458-4589"
41 * },
42 * "info": {
43 * "name": {
44 * "first": "Jeremy",
45 * "last": "Jackson"
46 * },
47 * "emails": {
48 * "items": [
49 * {
50 * "tag": "UNTAGGED",
51 * "email": "j.jackson@example.com",
52 * "primary": true,
53 * "_id": "dec280b7-a8dd-45bc-a7de-0da9166caf63"
54 * }
55 * ]
56 * },
57 * "phones": {
58 * "items": [
59 * {
60 * "tag": "MOBILE",
61 * "countryCode": "US",
62 * "phone": "646-458-4589",
63 * "e164Phone": "+16464584589",
64 * "primary": true,
65 * "_id": "c40ef68a-2cc9-4ab0-adb4-97be64c57878"
66 * },
67 * {
68 * "tag": "MOBILE",
69 * "countryCode": "IL",
70 * "phone": "55-334-3434",
71 * "e164Phone": "+972553343434",
72 * "primary": false,
73 * "_id": "caa48199-d40d-4c2e-9eec-ae9bdf8e4f35"
74 * }
75 * ]
76 * },
77 * "addresses": {
78 * "items": [
79 * {
80 * "tag": "HOME",
81 * "address": {
82 * "formatted": "Israel",
83 * "country":"IL"
84 * },
85 * "_id": "6a2fd038-fa7a-486d-9230-e48bcea824bc"
86 * }
87 * ]
88 * },
89 * "labelKeys": {
90 * "items": [
91 * "custom.anonymous"
92 * ]
93 * },
94 * "extendedFields": {
95 * "items": {
96 * "contacts.displayByLastName": "Jackson Jeremy",
97 * "emailSubscriptions.effectiveEmail": "j.jackson@example.com",
98 * "custom.age": 37,
99 * "contacts.displayByFirstName": "Jeremy Jackson"
100 * }
101 * }
102 * },
103 * "_id": "527676cc-2f20-4318-a76f-07854e02be2c",
104 * "_createdDate": "2024-01-14T10:22:43.952Z",
105 * "_updatedDate": "2024-01-14T10:26:38.848Z"
106 * }
107 * }
108 * }
109 */
110
111