> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encorekit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# UserAttributes

> Structured user attributes for targeting and analytics

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

```swift theme={null}
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 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?
  
  // 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,
    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          |
| ------------- | ------- | ---------------- | ------------ | -------------------- |
| `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   |

### Custom Attributes

| Field    | Type              | Format                      | Example                   | Description                                     |
| -------- | ----------------- | --------------------------- | ------------------------- | ----------------------------------------------- |
| `custom` | \[String: String] | JSON object (string:string) | `{ "churnRisk": "high" }` | For any additional attributes not covered above |

## Usage

```swift theme={null}
let attributes = UserAttributes(
  email: "user@example.com",
  subscriptionTier: "premium",
  monthsSubscribed: "6"
)

Encore.shared.setUserAttributes(attributes)
```
