UNPKG

userplex

Version:

Simple analytics SDK for Userplex - Track events, identify users, and log conversations

79 lines (77 loc) 2.15 kB
/** * Userplex - Simple Analytics SDK * * Just install and use. No complex setup required. * * @example * ```ts * import Userplex from 'userplex'; * * const userplex = new Userplex('upx_your_api_key'); * * // Track events * await userplex.track('user123', 'button_clicked', { button: 'signup' }); * * // Identify users * await userplex.identify('user123', { email: 'user@example.com' }); * * // Log conversations * await userplex.logConversation({ * messages: [ * { role: 'user', content: 'Hello' }, * { role: 'assistant', content: 'Hi there!' } * ] * }); * ``` */ interface ConversationMessage { role: 'user' | 'assistant' | 'system'; content: string; } interface UserplexOptions { /** Your Userplex instance URL (default: https://userplex.vercel.app) */ baseUrl?: string; /** Request timeout in ms (default: 10000) */ timeout?: number; /** Enable debug logging (default: false) */ debug?: boolean; } declare class UserplexError extends Error { statusCode?: number | undefined; response?: any | undefined; constructor(message: string, statusCode?: number | undefined, response?: any | undefined); } declare class Userplex { private apiKey; private baseUrl; private timeout; private debug; constructor(apiKey: string, options?: UserplexOptions); /** * Track an event */ track(userId: string, event: string, properties?: Record<string, any>): Promise<any>; /** * Identify a user */ identify(externalId: string, properties?: Record<string, any>): Promise<any>; /** * Log a conversation */ logConversation(options: { messages: ConversationMessage[]; userId?: string; conversationId?: string; conversationName?: string; }): Promise<any>; /** * Batch track multiple events */ trackBatch(events: Array<{ userId: string; event: string; properties?: Record<string, any>; }>): Promise<any[]>; private request; } export { type ConversationMessage, Userplex, UserplexError, type UserplexOptions, Userplex as default };