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
age?: number;
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
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
email | string? | email address | user@example.com | User’s email address |
firstName | string? | free-form string | Jane | User’s first name |
lastName | string? | free-form string | Doe | User’s last name |
phoneNumber | string? | E.164 or local | +442071838750 | Phone number |
Location
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
postalCode | string? | postal/ZIP code | SW1A 1AA | Postal code |
city | string? | free-form string | San Francisco | City name |
state | string? | abbr or full | CA | State/province |
countryCode | string? | ISO 3166-1 alpha-2 | US | Country code |
latitude | string? | decimal degrees | 37.7749 | Geographic latitude |
longitude | string? | decimal degrees | -122.4194 | Geographic longitude |
Demographics
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
age | number? | whole years, 0 to 120 | 25 | The user’s age. Send the lowest end of a range. A user under 18 is served age-appropriate offers with no per-user personalization. Not saved between launches: pass dateOfBirth, or set age on every launch |
dateOfBirth | string? | YYYY-MM-DD | 2001-04-18 | The user’s date of birth. The SDK works the age out from it on the device and never sends the date. Given age too, the lower age is used. An unreadable or future date gives no age |
gender | string? | free-form string | female | Gender. Accepted only from an app rated 18+ in its store listing |
language | string? | BCP-47 tag | es, es-MX | Deprecated. Use setLanguage() instead. From the release that adds setLanguage(), setting this field calls it for you and logs a warning once. Removed at the next major release. See Localization |
Subscription & Billing
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
subscriptionTier | string? | plan name | free, premium, pro | Current subscription tier |
monthsSubscribed | string? | integer string | 6 | Months subscribed |
billingCycle | string? | enum string | monthly, annual | Billing frequency |
lastPaymentAmount | string? | decimal as string | 9.99 | Last payment amount |
Engagement
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
lastActiveDate | string? | ISO 8601 datetime | 2024-03-15T14:30:00Z | Last activity timestamp |
totalSessions | string? | integer string | 42 | Total sessions |
Custom Attributes
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
custom | Record<string, string> | key-value pairs | { churnRisk: 'high' } | Additional custom attributes |
Usage
await Encore.setUserAttributes({
email: 'user@example.com',
subscriptionTier: 'premium',
monthsSubscribed: '6',
});