> ## 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.

# User Management

> Identifying users, setting attributes, and managing identity in your iOS app.

## Overview

Encore requires user identification to track entitlements and prevent abuse across devices. You can also set user attributes to enable targeted offers and personalization.

***

## Anonymous Users

Encore **automatically generates** a random user ID that persists until the user deletes/reinstalls your app or calls `reset()`.

This anonymous ID is stored securely and allows entitlement tracking to work immediately without requiring explicit user identification. The auto-generated ID is a standard UUID (e.g., `550e8400-e29b-41d4-a716-446655440000`).

You can call `Encore.shared.reset()` to reset this ID and clear any entitlement data.

***

## Identified Users

If you use your own user management system, call `identify(userId:)` when you have a user's identity:

```swift theme={null}
// After retrieving a user's ID from login or account creation
Encore.shared.identify(userId: user.id)
```

This enables the SDK to:

* Associate promotional access with your user account
* Sync entitlements across devices when the user logs in
* Track conversion attribution accurately

***

## Resetting User Identity

When a user logs out, call `reset()`:

```swift theme={null}
// When the user signs out
Encore.shared.reset()
```

This will:

* Reset the user ID to a new auto-generated anonymous ID
* Clear cached entitlement data
* Clear all user attributes

***

## Setting User Attributes

User attributes enable:

* **Personalized offers** based on user data (subscription tier, usage, etc.)
* **Audience targeting** with specific offers in the Encore dashboard
* **Conversion context tracking** for analytics

### Usage

Set attributes using the `UserAttributes` struct. All values are strings; use the `custom` dictionary for app-specific fields:

```swift theme={null}
Encore.shared.setUserAttributes(
    UserAttributes(
        email: "user@example.com",
        subscriptionTier: "premium",
        monthsSubscribed: "6",
        custom: [
            "cancelReason": "too_expensive"
        ]
    )
)
```

You can also set user attributes when identifying:

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

**Important:** `setUserAttributes()` **merges** with existing attributes - it does not replace them.

<Tip>
  See the SDK Reference for details: [identify()](../sdk-reference/identify), [setUserAttributes()](../sdk-reference/set-user-attributes), and the full [UserAttributes](../sdk-reference/user-attributes) field list and formats.
</Tip>

***

## Implementation Examples

### SwiftUI with Login

```swift theme={null}
import SwiftUI
import Encore

@main
struct YourApp: App {
    @StateObject private var authManager = AuthManager()

    init() {
        Encore.shared.configure(apiKey: "pk_your_api_key")
    }

    var body: some Scene {
        WindowGroup {
            MainAppView()
                .onAppear {
                    if authManager.isAuthenticated {
                        Encore.shared.identify(
                            userId: authManager.userId,
                            attributes: UserAttributes(
                                email: authManager.email,
                                subscriptionTier: authManager.tier
                            )
                        )
                    }
                }
        }
    }
}

struct SettingsView: View {
    @EnvironmentObject var authManager: AuthManager
    
    var body: some View {
        Button("Log Out") {
            Encore.shared.reset()
            authManager.logout()
        }
    }
}
```

### UIKit with Login

```swift theme={null}
class LoginViewController: UIViewController {
    func handleSuccessfulLogin(user: User) {
        Encore.shared.identify(
            userId: user.id,
            attributes: UserAttributes(
                email: user.email,
                subscriptionTier: user.subscriptionTier
            )
        )
        navigateToMainApp()
    }
}

class SettingsViewController: UIViewController {
    func handleLogout() {
        Encore.shared.reset()
        authManager.logout()
        navigateToLogin()
    }
}
```

### Apps Without Login

If your app doesn't require users to log in, you don't need to do anything special:

```swift theme={null}
@main
struct YourApp: App {
    init() {
        Encore.shared.configure(apiKey: "pk_your_api_key")
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

// You can still set attributes for anonymous users
Button("Cancel Subscription") {
    Encore.shared.setUserAttributes(
        UserAttributes(
            custom: ["cancelReason": "too_expensive"]
        )
    )
    Encore.placement().show()
}
```

***

## Next Steps

* [Present Offers](./present-offers) - Show promotional offers and handle purchase results
* [Add Subscription Product](./add-subscription-product) - Create an App Store subscription product and connect it to Encore
