> ## 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 Android 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 clears app data, uninstalls, or calls `reset()`.

This anonymous ID is stored locally 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 cached data.

***

## Identified Users

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

```kotlin 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()`:

```kotlin 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 configuration data

***

## 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` class. All values are strings; use the `custom` map for app-specific fields:

```kotlin theme={null}
Encore.shared.setUserAttributes(
    UserAttributes(
        email = "user@example.com",
        subscriptionTier = "premium",
        monthsSubscribed = "6",
        custom = mapOf(
            "cancelReason" to "too_expensive"
        )
    )
)
```

You can also set user attributes when identifying:

```kotlin 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.

***

## Implementation Examples

### With Login

```kotlin theme={null}
class YourApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Encore.shared.configure(this, apiKey = "pk_your_api_key")
    }
}

// After successful login
class LoginActivity : AppCompatActivity() {
    private fun handleSuccessfulLogin(user: User) {
        Encore.shared.identify(
            userId = user.id,
            attributes = UserAttributes(
                email = user.email,
                subscriptionTier = user.subscriptionTier
            )
        )
        navigateToMain()
    }
}

// On logout
class SettingsActivity : AppCompatActivity() {
    private fun handleLogout() {
        Encore.shared.reset()
        authManager.logout()
        navigateToLogin()
    }
}
```

### Jetpack Compose with Login

```kotlin theme={null}
@Composable
fun SettingsScreen(authManager: AuthManager) {
    Button(onClick = {
        Encore.shared.reset()
        authManager.logout()
    }) {
        Text("Log Out")
    }
}
```

### Apps Without Login

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

```kotlin theme={null}
class YourApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Encore.shared.configure(this, apiKey = "pk_your_api_key")
    }
}

// You can still set attributes for anonymous users
Encore.shared.setUserAttributes(
    UserAttributes(custom = mapOf("cancelReason" to "too_expensive"))
)
```

***

## Next Steps

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