When a visitor first interacts with your site in a number of ways — such as submitting a contact form or subscribing to a newsletter — they're added to your site's Contact List. Once that happens, their details are available through the Contacts API.
Here are some examples of how a visitor could be converted to a contact:
Appends an existing contact or creates a contact if it doesn't exist.
The appendOrCreateContact()
function returns a Promise
that resolves to a contact ID and identity type when a contact is found or created.
When called, appendOrCreateContact()
accepts an object with contact information and follows the steps below.
When one of the conditions is met, this process ends and the specified
data is handled:
appendOrCreateContact()
reconciles with the member's associated contact.appendOrCreateContact()
tries to reconcile any specified email addresses and/or phone numbers with an existing contact.appendOrCreateContact()
tries to reconcile the visitor's session identity with an existing contact.appendOrCreateContact()
reconciles with the new contact.appendOrCreateContact()
does not require member authentication,
so it does not return the entire contact object.
The contact's data can be retrieved with
getContact()
from wix-crm-backend
.
If an existing contact is found:
emails
, addresses
, phones
, and labelKeys
.Note:
If the reconciled contact belongs to a member
who isn't currently logged in to the site,
identityType
is returned as "NOT_AUTHENTICATED_MEMBER"
.
In that case, no contact properties are modified.
If a new contact is created:
function appendOrCreateContact(
contactInfo: ContactInfo,
): Promise<ContactIdentification>;
Contact's information. To reconcile with an existing contact, a phone or email must be provided, or the current session identity must be attached to a contact or member.
If no existing contact can be found, a new contact is created with the specified information.
import { createClient } from "@wix/sdk";
import { site } from "@wix/site";
import { contacts } from "@wix/site-crm";
const wixClient = createClient({
host: site.host(),
modules: { contacts },
});
// ...
const contactInfo = {
name: {
first: "Ari",
last: "Thereyet",
},
};
(async () => {
try {
const resolvedContact =
await wixClient.contacts.appendOrCreateContact(contactInfo);
return resolvedContact;
} catch (error) {
console.error(error);
}
})();
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.