Customer
An easy way to access and use Shopify customer data within the Superfans SDK.
Description
The customer variable contains authenticated user account information from Shopify. It provides access to first name, phone number, tags, etc., allowing you to personalize the app experience, show user-specific content, and trigger conditional logic.
These variables are automatically populated when the user is logged in and refreshed whenever the customer signs in or out. Accessing them before login will return null.
Properties
The customer variable is an object with the following properties:
| Property | Type | Scope | Description | Example |
|---|---|---|---|---|
customer.id | String | Global | Unique identifier of the Shopify customer. | 6669141901500 |
customer.firstName | String | Global | Customer’s given first name. | John |
customer.lastName | String? | Global | Customer’s given last name. | Doe |
customer.email | String | Global | Customer’s given email id. | [email protected] |
customer.phoneNumber | String | Global | Customer’s given phone number. | +919840149239 |
customer.tag | String[] | Global | Array of Shopify customer tags for segmentation. | [”champion”, “multiple-purchases”] |
customer.accessToken | String | Global | Access token for Shopify API requests (read‑only). | 1e8f71a1f8793d1ac47f3b0a4cf51c3d |
customer.wishlistedProducts | Object[] | Global | List of items in the customer's wishlist. Each entry contains productId, variantId and wishlistId | [{productId: "1234234342", variantId: "28736487623", id: "876234876234"}] |
customer.metafields | Object[] | Global | Array of custom key‑value pairs. Provide a key to retrieve its value. | [{key: "customer_gender", value: "male"}] |
Example Usage
Greet the customer with name when the customer logs in.
const customer = VajroSDK.variables.customer;
if (customer) {
console.log(`Hello, ${customer.firstName}!`);
// Write business logic to display wishlist count:
console.log(`Items in wishlist: ${customer.wishlistedProducts.length}`);
} else {
// Prompt user to sign in
}Best Practices
- Check for null or empty values before accessing customer properties.
- Read-only Access: The customer data are read-only and cannot be modified.
- Refresh Data on Login/Logout: Customer data is automatically refreshed, but for manual refresh, call the SDK refresh method if needed.
Caveats
- Fields may be missing: Not every customer will have a phone number, tags, or custom metafields defined. Safely handle empty or undefined values instead of assuming every field is present.
- Sensitive data: The accessToken field grants authenticated API access on behalf of the user. Treat it as sensitive information — avoid logging it or exposing it in the UI.
Updated about 1 month ago