Customer

Customer variables contain authenticated user account information from Shopify including profile data, order history, and marketing preferences. These variables are populated when a user is logged in and are refreshed when the customer signs in/out.

Access in App Studio SDK

Tapcart.variables.customer

Basic Customer Information

PropertyTypeDescriptionAvailability
customer.idstringUnique customer identifier (cleaned of Shopify GID prefix)When logged in
customer.firstNamestringCustomer's first nameWhen logged in
customer.lastNamestringCustomer's last nameWhen logged in
customer.displayNamestringCustomer's display nameWhen logged in
customer.emailstringCustomer's email addressWhen logged in
customer.phonestringCustomer's phone numberIf provided
customer.imageUrlstringURL to customer's profile imageIf available

Account Metadata

PropertyTypeDescriptionAvailability
customer.createdAtstringISO timestamp when account was createdWhen logged in
customer.updatedAtstringISO timestamp when account was last updatedWhen logged in
customer.tagsstring[]Array of customer tags for segmentationIf available

Order Information

PropertyTypeDescriptionAvailability
customer.ordersobjectConnection object containing customer's order historyIf available
customer.hasPreviousOrdersbooleanWhether the customer has placed orders beforeAlways

Default Address

PropertyTypeDescriptionAvailability
customer.address.address1stringPrimary address lineIf address set
customer.address.address2stringSecondary address lineIf provided
customer.address.citystringCity nameIf address set
customer.address.provincestringProvince/state nameIf address set
customer.address.provinceCodestringProvince/state codeIf address set
customer.address.countrystringCountry nameIf address set
customer.address.countryCodestringCountry codeIf address set
customer.address.zipstringPostal/ZIP codeIf address set

Marketing Preferences

PropertyTypeDescriptionAvailability
customer.marketing.emailbooleanWhether customer accepts email marketingIf available
customer.marketing.phonebooleanWhether customer accepts SMS marketingIf available

Session Information

PropertyTypeDescriptionAvailability
customer.customerSessionobjectAuthentication tokens and session dataWhen logged in

Custom Data

PropertyTypeDescriptionAvailability
customer.metafieldsarrayArray of custom metafield objects with namespace, key, valueIf configured
customer.dataobjectRaw customer data passed through from ShopifyWhen logged in

Usage Examples

// Check if customer is logged in
const isLoggedIn = !!variables.customer?.id;

// Display customer name
const customerName = variables.customer?.firstName || 'Guest';
const fullName = `${variables.customer?.firstName || ''} ${variables.customer?.lastName || ''}`.trim();

// Check previous order status
const isNewCustomer = !variables.customer?.hasPreviousOrders;

// Access customer address
const hasAddress = !!variables.customer?.address;
const shippingCity = variables.customer?.address?.city;

// Marketing preferences
const canEmailMarketing = variables.customer?.marketing?.email === true;

// Access metafields
const loyaltyPoints = variables.customer?.metafields?.find(
  field => field.namespace === 'loyalty' && field.key === 'points'
)?.value;

// Customer tags for segmentation
const isVipCustomer = variables.customer?.tags?.includes('VIP');

Metafields Configuration

📘

Note on metafields

Before using metafields in your block, you'll need to:

  1. Enable metafields for your Tapcart app
  2. Configure specific metafields that your app should access
  3. Reference metafields by their specific namespace and key
// Metafield structure
const metafield = {
  namespace: 'loyalty',
  key: 'tier', 
  value: 'gold'
};

Availability

Customer variables are only available when a user is authenticated (logged in). When logged out, the customer variable will be undefined. Always check for existence before accessing properties.

Use Cases

  • Personalization: Display personalized content and recommendations
  • Order History: Show previous purchases and order status
  • Shipping: Pre-fill forms with saved address information
  • Marketing: Respect customer communication preferences
  • Segmentation: Show different content based on customer tags
  • Authentication: Conditionally display login/logout options
  • Loyalty Programs: Access custom loyalty data via metafields