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:

PropertyTypeScopeDescriptionExample
customer.idStringGlobalUnique identifier of the Shopify customer.6669141901500
customer.firstNameStringGlobalCustomer’s given first name.John
customer.lastNameString?GlobalCustomer’s given last name.Doe
customer.emailStringGlobalCustomer’s given email id.[email protected]
customer.phoneNumberStringGlobalCustomer’s given phone number.+919840149239
customer.tagString[]GlobalArray of Shopify customer tags for segmentation.[”champion”, “multiple-purchases”]
customer.accessTokenStringGlobalAccess token for Shopify API requests (read‑only).1e8f71a1f8793d1ac47f3b0a4cf51c3d
customer.wishlistedProductsObject[]GlobalList of items in the customer's wishlist. Each entry contains productId, variantId and wishlistId[{productId: "1234234342", variantId: "28736487623", id: "876234876234"}]
customer.metafieldsObject[]GlobalArray 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

  1. Check for null or empty values before accessing customer properties.
  2. Read-only Access: The customer data are read-only and cannot be modified.
  3. Refresh Data on Login/Logout: Customer data is automatically refreshed, but for manual refresh, call the SDK refresh method if needed.

Caveats

  1. 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.
  2. 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.