A structured data 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
public struct EncoreAttributes {
// 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 dateOfBirth: String?
public let gender: String?
public let language: String?
// 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?
// In-App Purchase Integration
public let iapProductId: 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,
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,
iapProductId: String? = nil,
custom: [String: String] = [:]
)
}
Field Reference
Identity & Basic Info
| Field | Type | Format | Example | Description |
|---|
email | String? | email address | [email protected] | 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 |
|---|
dateOfBirth | String? | ISO 8601 date | 1990-05-21 | User’s date of birth |
gender | String? | free-form string | female | User’s gender |
language | String? | ISO 639-1 | en | Preferred language |
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 |
In-App Purchase Integration
| Field | Type | Format | Example | Description |
|---|
iapProductId | String? | Apple IAP Product ID | monthly_premium | If set, the SDK automatically presents Apple’s native subscription UI after an Encore offer is completed. |
When iapProductId is configured, completing an Encore offer automatically triggers Apple’s IAP purchase flow. If the user subscribes, their IAP subscription grants access via your existing IAP manager—you don’t need to check Encore entitlements.
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 = EncoreAttributes(
email: "[email protected]",
subscriptionTier: "premium",
monthsSubscribed: "6",
iapProductId: "monthly_premium" // Optional: Show Apple IAP after offer completion
)
Encore.shared.setUserAttributes(attributes)