init()

init takes a public key and public secret and returns an object of type Voxie.

It is used to initialize the library. Call Voxie.init() with an object containing public key and secret as below:

const voxie = await Voxie.init({
  publicKey: "<YOUR_WRITE_KEY>",
  publicSecret: "<YOUR_SECRET_KEY>",
});
const voxie = await Voxie.init({
  publicKey: "<YOUR_WRITE_KEY>",
  publicSecret: "<YOUR_SECRET_KEY>",
});

return: Voxie

capture()

Using the initialized Voxie class instance, you can then capture contact information.

Only phone is required.
Further contact info is optional.

*Phone number is validated to E.164 phone format and will return an error if invalid.

voxie.capture("+15551231234", {
  firstName: "John",
  lastName: "Doe",
  // tags and custom attribute keys must be lowercase
  tags: ["purchased", "online"],
  customAttributes: {
    last_purchase_sku: "vxe123",
    last_product_viewed_sku: "vxe456",
  },
  subscriptionStatuses: {
    marketing: "opt_in"
  },
});
voxie.capture("+15551231234", {
  firstName: "John",
  lastName: "Doe",
  // tags and custom attribute keys must be lowercase
  tags: ["purchased", "online"],
  customAttributes: {
    last_purchase_sku: "vxe123",
    last_product_viewed_sku: "vxe456",
  },
  subscriptionStatuses: {
    marketing: "opt_in"
  }
});

Note:

  • tags must be unique (i.e. set type)
  • customAttributes must have unique key (i.e. map type)

return: Promise

share()

Using the initialized Voxie class instance, you can then share form information with Voxie on submit.

The form element and form field phone mapping is required.
Further mapping for first name, last name, and email are optional.
You can apply optional metadata to all contacts such as tags and custom attributes.

*Phone number is validated to E.164 phone format and will return an error if invalid.

voxie.share(
  document.getElementById("purchase"),
  {
    // values are field names within the form
    phone: "phone",
    firstName: "first-name",
    lastName: "last-name",
    email: "email",
  },
  {
    // tags and custom attribute keys must be lowercase
    tags: ["purchased", "online"],
    customAttributes: {
      last_purchase_sku: "vxe123",
      last_product_viewed_sku: "vxe456",
    },
  }
);