JS API methods are used for client-side management of customers currently logged in to the store. Get customer details like email, group ID, and shipping address, set their tracking consent, and create custom sign-out flows.
Enable JS API on the storefront
The methods listed below require JS API to be loaded on the page. Read more on how to enable JS API.
Ecwid.Customer.get(customer)
Ecwid.Customer.get(customer)
This method receives all data on the customer currently logged in to the store.
Request example:
Ecwid.Customer.get(function(customer) {
console.log(customer.email);
});
// prints
// [email protected]
Fields available in the returned customer
object:
Name | Type | Description |
---|---|---|
billingPerson | object{Person} | Customer details including address and contact details (name and phone). |
String | Customer's email. | |
id | Number | Customer ID. |
membership | object{CustomerGroup} | Customer group details. Available only if a customer belongs to a customer group. |
ownerId | number | Ecwid Store ID. |
registered | UNIX Timestamp | Customer's registration date. |
shippingAddresses | array{ShippingAddress} | Customer’s address book. |
Person
Person
Name | Type | Description |
---|---|---|
name | string | Customer's name. |
companyName | string, optional | Company name of a customer, if available. |
street | string, optional | Shipping/billing address. Street. |
city | string, optional | Shipping/billing address. City. |
countryName | string, optional | Shipping/billing address. Country name. |
countryCode | string, optional | Shipping/billing address. Country code in ISO 3166-2. |
postalCode | string, optional | Shipping/billing address. ZIP code. |
stateOrProvinceCode | string, optional | Shipping/billing address. State code ISO 3166-2. |
phone | string, optional | Customer's phone number, if available. |
CustomerGroup
CustomerGroup
Name | Type | Description |
---|---|---|
id | number | Customer group ID. |
name | string | Customer group name. |
ownerid | number | Ecwid store ID |
ShippingAddress
ShippingAddress
Name | Type | Description |
---|---|---|
id | integer | Saved shipping address ID. |
person | object{Person} | Customer's shipping address details. |
Ecwid.getVisitorLocation();
Ecwid.getVisitorLocation();
This method gets the customer's location based on their shipping or billing address, or IP.
Request example:
Ecwid.getVisitorLocation();
// {countryCode: 'US', stateCode: 'NE', source: 'SHIPPING_ADDRESS'}
Available fields
Name | Type | Description |
---|---|---|
countryCode | string | Country code (null if not found) |
stateCode | string | State code (null if not found) |
source | string | The source of the received country code and state code. Possible values: 'SHIPPING_ADDRESS’, ‘BILLING_ADDRESS’, 'IP_ADDRESS’. |
Ecwid.Customer.signout(success,error)
Ecwid.Customer.signout(success,error)
This method signs out customer from their account.
Request example:
Ecwid.Customer.signOut(function(success,error) {
if (success == true) {
console.log("Customer signed out");
} else {
console.log("Signout failed. Error message: " + error);
}
});
// prints
// Customer signed out
Fields available in the returned object:
Name | Type | Description |
---|---|---|
success | boolean | Is true if a customer was signed out, false otherwise. |
error | string | Error message. Has value only if success is false |