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"
});| Parameter | Type | Required | Description |
|---|---|---|---|
tag | String | Yes | Customer tag to add. Must be a non-empty string. The tag is sent as given. |
Structure of Response
| Status | Response |
|---|---|
| Success | The 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
- Call this only when the shopper is logged in. If
Superfans.variables.customer.idis missing, open login first. - Send one tag string. Do not send an array of tags.
- Handle a rejection with
try/catchand showerror.errorMessagein a toast.
Caveats
- A blank or whitespace-only tag is rejected before anything is sent.
- The promise resolving means native accepted the tag. Re-read
Superfans.variables.customerafter the next customer update to see the tag on the customer.
Updated about 2 hours ago
Did this page help you?