/** * User Manager - Handles user identity and properties * * Uses shared StorageManager for consistent storage operations. * * Manages: * - anonymous_id: Generated ID for anonymous users * - distinct_id: User-provided ID after identification * - device_id: Persistent device identifier * - user_properties: Custom properties set via identify/setUserProperties * - user_state: "anonymous" or "identified" */ import { UserIdentity, IdentityUpdate, PersistenceMethod } from "./types"; export declare class UserManager { private storage; private userIdentity; private _isFirstVisit; constructor(storageMethod?: PersistenceMethod, cross_subdomain?: boolean); /** * Hydrate identity from persistent storage. * * Called by VTilt._boot() once the browser environment is guaranteed ready * (DOMContentLoaded). This is the only code path that reads from * localStorage / cookies. If storage is empty (first visit), the generated * IDs are persisted so they survive the next page load. */ hydrateFromStorage(): void; /** * Generate an ephemeral in-memory identity with no storage access. * Used by the constructor so the SDK is safe to instantiate in SSR. */ private generateEphemeralIdentity; /** * Get current user identity */ getUserIdentity(): UserIdentity; /** * Get current distinct ID (identified user ID) */ getDistinctId(): string | null; /** * Get current anonymous ID */ getAnonymousId(): string; /** * Get current user properties */ getUserProperties(): Record; /** * Get the effective ID for event tracking */ getEffectiveId(): string; /** * Get current device ID */ getDeviceId(): string; /** * Get current user state */ getUserState(): "anonymous" | "identified"; /** * Returns true if this is the user's first visit (no prior anonymous_id * in storage when the SDK booted). Resets after first call. * Matches GA4's _fv=1 semantics. */ consumeFirstVisit(): boolean; /** * Apply batched identity changes with a single save. * Replaces individual setters to avoid multiple storage writes per operation. */ applyUpdate(update: IdentityUpdate): void; /** * Reset identity to anonymous state. Generates new IDs and clears user data. */ reset(resetDeviceId?: boolean): void; /** * Set initial person info */ set_initial_person_info(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[]): void; /** * Load user identity from storage. * * For traditional SSR websites where each page navigation reloads JavaScript, * identity MUST be persisted immediately when generated to ensure the same * anonymous_id is used across all page loads. * * Flow: * 1. Load from storage (reads cookies first for critical properties in SSR mode) * 2. Generate new IDs if not found * 3. Immediately persist to storage (saved to both localStorage and cookies) * * With `localStorage+cookie` persistence (default): * - Critical properties are stored in cookies for SSR compatibility * - Full data is stored in localStorage for fast SPA-style access * - Cookies ensure identity persists across full page reloads */ private loadUserIdentity; /** * Save user identity to storage */ private saveUserIdentity; /** * Get user properties from storage */ private getStoredUserProperties; /** * Set user properties in storage */ private setStoredUserProperties; /** * Register super properties once — a key is written only if it is not * already present. Mirrors PostHog's `persistence.register_once`: the value * is written to the **in-memory** identity (so it ships on the very next * event in this same page load, not only after a reload re-hydrates from * storage) and then persisted. */ private register_once; private generateAnonymousId; private generateDeviceId; /** * Update storage method at runtime. */ updateStorageMethod(method: PersistenceMethod, cross_subdomain?: boolean): void; }