Skip to main content
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:
// 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():
// 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 EncoreAttributes struct. All values are strings; use the custom dictionary for app-specific fields:
Encore.shared.setUserAttributes(
    EncoreAttributes(
        email: "user@example.com",
        subscriptionTier: "premium",
        monthsSubscribed: "6",
        custom: [
            "cancelReason": "too_expensive"
        ]
    )
)
You can also set user attributes when identifying:
Encore.shared.identify(
    userId: "user_12345",
    attributes: EncoreAttributes(
        email: "user@example.com",
        subscriptionTier: "premium",
        monthsSubscribed: "6"
    )
)
Important: setUserAttributes() merges with existing attributes - it does not replace them.
See the SDK Reference for details: identify(), setUserAttributes(), and the full EncoreAttributes field list and formats.

Implementation Examples

SwiftUI with Login

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: EncoreAttributes(
                                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

class LoginViewController: UIViewController {
    func handleSuccessfulLogin(user: User) {
        Encore.shared.identify(
            userId: user.id,
            attributes: EncoreAttributes(
                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:
@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(
        EncoreAttributes(
            custom: ["cancelReason": "too_expensive"]
        )
    )
    Encore.placement().show()
}

Next Steps