Structure
public struct UserAttributes {
// Identity & Basic Info
public let email: String?
public let firstName: String?
public let lastName: String?
public let phoneNumber: String?
// Location
public let postalCode: String?
public let city: String?
public let state: String?
public let countryCode: String?
public let latitude: String?
public let longitude: String?
// Demographics
public let age: Int?
public let dateOfBirth: String?
public let gender: String?
@available(*, deprecated, message: "Use Encore.shared.setLanguage(_:). Removed in the next major version.")
public var language: String? { get }
// Subscription & Billing
public let subscriptionTier: String?
public let monthsSubscribed: String?
public let billingCycle: String?
public let lastPaymentAmount: String?
// Engagement
public let lastActiveDate: String?
public let totalSessions: String?
// Custom Attributes
public let custom: [String: String]
public init(
email: String? = nil,
firstName: String? = nil,
lastName: String? = nil,
phoneNumber: String? = nil,
postalCode: String? = nil,
city: String? = nil,
state: String? = nil,
countryCode: String? = nil,
latitude: String? = nil,
longitude: String? = nil,
age: Int? = nil,
dateOfBirth: String? = nil,
gender: String? = nil,
language: String? = nil,
subscriptionTier: String? = nil,
monthsSubscribed: String? = nil,
billingCycle: String? = nil,
lastPaymentAmount: String? = nil,
lastActiveDate: String? = nil,
totalSessions: String? = nil,
custom: [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 | Alternative phone number |
Location
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
postalCode | String? | postal/ZIP code | SW1A 1AA | Alternative postal code key |
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 | Int? | 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 | User’s 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(), the property is read-only, and passing language: to the initializer calls setLanguage(_:) for you and logs a warning once per launch. Removed at the next major release. See Localization |
Subscription & Billing
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
subscriptionTier | String? | plan name | free, premium, pro | Current subscription plan/tier |
monthsSubscribed | String? | integer string | 6 | Number of months subscribed |
billingCycle | String? | enum string | monthly, annual | Billing frequency |
lastPaymentAmount | String? | decimal as string | 9.99 | Amount of last payment |
Engagement
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
lastActiveDate | String? | ISO 8601 datetime | 2024-03-15T14:30:00Z | Timestamp of last activity |
totalSessions | String? | integer string | 42 | Total number of sessions |
Custom Attributes
| Field | Type | Format | Example | Description |
|---|---|---|---|---|
custom | [String: String] | JSON object (string:string) | { "churnRisk": "high" } | For any additional attributes not covered above |
Usage
let attributes = UserAttributes(
email: "user@example.com",
subscriptionTier: "premium",
monthsSubscribed: "6"
)
Encore.shared.setUserAttributes(attributes)