Skip to main content
A structured type for storing user metadata used in offer targeting, personalization, and analytics. All fields are optional and will be merged with existing attributes when set.

Structure

interface UserAttributes {
  // Identity & Basic Info
  email?: string;
  firstName?: string;
  lastName?: string;
  phoneNumber?: string;

  // Location
  postalCode?: string;
  city?: string;
  state?: string;
  countryCode?: string;
  latitude?: string;
  longitude?: string;

  // Demographics
  dateOfBirth?: string;
  gender?: string;
  language?: string;

  // Subscription & Billing
  subscriptionTier?: string;
  monthsSubscribed?: string;
  billingCycle?: string;
  lastPaymentAmount?: string;

  // Engagement
  lastActiveDate?: string;
  totalSessions?: string;

  // Custom Attributes
  custom?: Record<string, string>;
}

Field Reference

Identity & Basic Info

FieldTypeFormatExampleDescription
emailstring?email addressuser@example.comUser’s email address
firstNamestring?free-form stringJaneUser’s first name
lastNamestring?free-form stringDoeUser’s last name
phoneNumberstring?E.164 or local+442071838750Phone number

Location

FieldTypeFormatExampleDescription
postalCodestring?postal/ZIP codeSW1A 1AAPostal code
citystring?free-form stringSan FranciscoCity name
statestring?abbr or fullCAState/province
countryCodestring?ISO 3166-1 alpha-2USCountry code
latitudestring?decimal degrees37.7749Geographic latitude
longitudestring?decimal degrees-122.4194Geographic longitude

Demographics

FieldTypeFormatExampleDescription
dateOfBirthstring?ISO 8601 date1990-05-21Date of birth
genderstring?free-form stringfemaleGender
languagestring?ISO 639-1enPreferred language

Subscription & Billing

FieldTypeFormatExampleDescription
subscriptionTierstring?plan namefree, premium, proCurrent subscription tier
monthsSubscribedstring?integer string6Months subscribed
billingCyclestring?enum stringmonthly, annualBilling frequency
lastPaymentAmountstring?decimal as string9.99Last payment amount

Engagement

FieldTypeFormatExampleDescription
lastActiveDatestring?ISO 8601 datetime2024-03-15T14:30:00ZLast activity timestamp
totalSessionsstring?integer string42Total sessions

Custom Attributes

FieldTypeFormatExampleDescription
customRecord<string, string>key-value pairs{ churnRisk: 'high' }Additional custom attributes

Usage

await Encore.setUserAttributes({
  email: 'user@example.com',
  subscriptionTier: 'premium',
  monthsSubscribed: '6',
});