/** * Session management for Formo Analytics * * Handles tracking of detected wallets and identified wallet-address pairs * using cookies to maintain state across page loads within a session. */ import type { IFormoEventProperties } from "../types/events"; /** * Cookie keys for session tracking * NOTE: These values must match the original constants in constants/base.ts * to maintain backward compatibility with existing user sessions */ export declare const SESSION_WALLET_DETECTED_KEY = "wallet-detected"; export declare const SESSION_WALLET_IDENTIFIED_KEY = "wallet-identified"; /** * Interface for session management operations */ export interface IFormoAnalyticsSession { /** * Check if a wallet has been detected in this session * @param rdns The reverse domain name (RDNS) of the wallet provider */ isWalletDetected(rdns: string): boolean; /** * Mark a wallet as detected in this session * @param rdns The reverse domain name (RDNS) of the wallet provider */ markWalletDetected(rdns: string): void; /** * Check if a wallet-address pair has been identified in this session * @param address The wallet address * @param rdns The reverse domain name (RDNS) of the wallet provider * @param userId Optional external user ID (e.g. a Privy DID). When provided, * it is folded into the dedup key so attaching a new user ID to an * already-identified wallet re-emits instead of being silently deduped. * @param properties Optional identify properties. Fingerprinted into the * dedup key so an identify whose properties have *changed* (e.g. a Privy * user linked a new social account) re-emits, while an unchanged repeat * still dedupes. */ isWalletIdentified(address: string, rdns: string, userId?: string, properties?: IFormoEventProperties): boolean; /** * Mark a wallet-address pair as identified in this session * @param address The wallet address * @param rdns The reverse domain name (RDNS) of the wallet provider * @param userId Optional external user ID (e.g. a Privy DID). See * {@link isWalletIdentified} for how it affects the dedup key. * @param properties Optional identify properties. See * {@link isWalletIdentified}. */ markWalletIdentified(address: string, rdns: string, userId?: string, properties?: IFormoEventProperties): void; } export declare class FormoAnalyticsSession implements IFormoAnalyticsSession { /** * Generate a unique key for wallet identification tracking. * * Combines address, RDNS, and (optionally) the external user ID and a * fingerprint of the identify's properties, so the key identifies a specific * wallet-user-profile combination rather than just an address. * * Folding the user ID in means the same wallet identified first anonymously * and later with a user ID (e.g. after a Privy login attaches a DID) produces * two distinct keys, so the second identify is not deduped. * * Folding the properties hash in means a *changed* profile re-emits. This * matters for account linking: a Privy user who links a Google account keeps * the same wallets and the same DID, so without the hash every already-seen * wallet would dedupe and the new `google` property would never reach Formo * until the session expired. An identify repeated with identical properties * still dedupes, so this does not turn a re-render into an event. * * Key shapes, by component count - each is unambiguous, so they cannot * collide with one another: * * | Components | Shape | When | * | --- | --- | --- | * | 1 | `address` | no rdns, no userId, no properties | * | 2 | `address:rdns` | rdns only | * | 3 | `address:rdns:userId` | userId, no properties | * | 4 | `address:rdns:userId:hash` | properties present | * * Shapes 1 and 2 are unchanged from before user IDs and property hashes * existed, so keys already stored in browsers still match (backward * compatible). An identify that carries properties moves to shape 4, so the * first identify after an upgrade re-emits once per wallet - a one-off, and * the correct outcome, since those properties were never recorded under the * new key. * * @param address The wallet address * @param rdns The reverse domain name of the wallet provider * @param userId Optional external user ID (e.g. a Privy DID) * @param properties Optional identify properties, fingerprinted into the key * @returns A unique identification key */ private generateIdentificationKey; /** * Build the dedup key plus the **identity prefix** it belongs to. * * The identity prefix is the key with the properties hash stripped - * `address:rdns:userId` - i.e. *which wallet-user this is*, independent of * *what profile it last had*. `markWalletIdentified` uses it to drop that * identity's previous state before storing the new one, which matters twice: * * - **Reversion.** Keeping every state seen would make dedup mean "have I * ever seen this exact profile", so a profile that goes A → B → A (link * then unlink an account) would find the old A key and emit nothing. Dedup * should mean "is this the same as this wallet's *last* identify", so only * the current state is retained. * - **Growth.** Otherwise each profile change adds a key per wallet, and an * 8-wallet user linking a few accounts would push the cookie into eviction. * Superseding keeps it at one entry per wallet-user. * * The prefix is only defined for keys that have a userId and/or a properties * hash (3+ components). The legacy 1- and 2-component shapes are the whole * identity already, so there is nothing to supersede. */ private buildIdentificationKey; /** * Check if a wallet provider has been detected in this session * * @param rdns The reverse domain name of the wallet provider * @returns true if the wallet has been detected */ isWalletDetected(rdns: string): boolean; /** * Mark a wallet provider as detected in this session * Prevents duplicate detection events from being emitted * * @param rdns The reverse domain name of the wallet provider */ markWalletDetected(rdns: string): void; /** * Check if a specific wallet-address combination has been identified * * @param address The wallet address * @param rdns The reverse domain name of the wallet provider * @returns true if this wallet-address pair has been identified */ isWalletIdentified(address: string, rdns: string, userId?: string, properties?: IFormoEventProperties): boolean; /** * Mark a wallet-address combination as identified in this session * Prevents duplicate identification events from being emitted * * @param address The wallet address * @param rdns The reverse domain name of the wallet provider */ markWalletIdentified(address: string, rdns: string, userId?: string, properties?: IFormoEventProperties): void; } //# sourceMappingURL=index.d.ts.map