Add Customer Tag

Adds a tag to the current customer.

Description

The addCustomerTag action adds one tag to the current customer. The block supplies the tag string. Native adds that tag to the shopper's customer record.

Function Signature

await Superfans.actions.addCustomerTag({
  tag: "vip"
});
ParameterTypeRequiredDescription
tagStringYesCustomer tag to add. Must be a non-empty string. The tag is sent as given.

Structure of Response

StatusResponse
SuccessThe promise resolves with no value once native accepts the tag.
Missing payload{ "errorCode": 400, "errorType": "ERROR_INVALID_INPUT", "errorMessage": "Add customer tag payload should be provided." }
Missing tag{ "errorCode": 400, "errorType": "ERROR_INVALID_INPUT", "errorMessage": "Tag must be provided." }
Invalid tag{ "errorCode": 400, "errorType": "ERROR_INVALID_INPUT_TYPE", "errorMessage": "Invalid tag. It must be a non-empty string." }

Example Usage

const customer = Superfans.variables.customer;

if (!customer || !customer.id) {
  await Superfans.actions.openAuthentication({ type: "login" });
} else {
  try {
    await Superfans.actions.addCustomerTag({
      tag: "vip"
    });
  } catch (error) {
    await Superfans.actions.showToast({
      title: "Something went wrong",
      message: error.errorMessage || "Please try again."
    });
  }
}

Best Practices

  1. Call this only when the shopper is logged in. If Superfans.variables.customer.id is missing, open login first.
  2. Send one tag string. Do not send an array of tags.
  3. Handle a rejection with try/catch and show error.errorMessage in a toast.

Caveats

  1. A blank or whitespace-only tag is rejected before anything is sent.
  2. The promise resolving means native accepted the tag. Re-read Superfans.variables.customer after the next customer update to see the tag on the customer.

Did this page help you?