@loopkit/react
Version:
React TypeScript wrapper for @loopkit/javascript with built-in auto-tracking and comprehensive TypeScript support
68 lines (67 loc) • 2.87 kB
TypeScript
/**
* LoopKit React SDK Types
*
* This file extends the core @loopkit/javascript types with React-specific functionality.
*/
import type { ReactNode } from 'react';
export type { LoopKitConfig, LogLevel, RetryBackoff, TrackEvent, IdentifyEvent, GroupEvent, ClickEventProperties, BatchEventInput, TrackOptions, ILoopKit, IStorageManager, ISessionManager, IQueueManager, INetworkManager, Config, Event, Options, } from '@loopkit/javascript';
import type { LoopKitConfig, TrackOptions, BatchEventInput } from '@loopkit/javascript';
export interface UserProperties {
email?: string;
name?: string;
firstName?: string;
lastName?: string;
plan?: string;
signup_date?: string;
[key: string]: any;
}
export interface GroupProperties {
name?: string;
plan?: string;
employee_count?: number;
[key: string]: any;
}
export interface LoopKitContextValue {
isInitialized: boolean;
isLoading: boolean;
error: Error | null;
config: LoopKitConfig | null;
track: (eventName: string, properties?: Record<string, any>, options?: TrackOptions) => Promise<void>;
trackBatch: (events: BatchEventInput[]) => Promise<void>;
identify: (userId: string, properties?: UserProperties) => Promise<void>;
group: (groupId: string, properties?: GroupProperties, groupType?: string) => Promise<void>;
flush: () => Promise<void>;
getQueueSize: () => number;
configure: (options: Partial<LoopKitConfig>) => void;
}
export interface LoopKitProviderProps {
apiKey: string;
config?: Partial<LoopKitConfig>;
children: ReactNode;
onError?: (error: Error) => void;
onInitialized?: () => void;
}
export interface UseLoopKitOptions {
userId?: string;
userProperties?: UserProperties;
autoIdentify?: boolean;
}
export interface UseLoopKitReturn extends Omit<LoopKitContextValue, 'configure'> {
trackPageView: (pageName?: string, properties?: Record<string, any>) => Promise<void>;
trackClick: (elementName: string, properties?: Record<string, any>) => Promise<void>;
trackFormSubmit: (formName: string, properties?: Record<string, any>) => Promise<void>;
setUserId: (userId: string, properties?: UserProperties) => Promise<void>;
setUserProperties: (properties: UserProperties) => Promise<void>;
setGroup: (groupId: string, properties?: GroupProperties, groupType?: string) => Promise<void>;
}
export declare class LoopKitError extends Error {
code?: string | undefined;
originalError?: Error | undefined;
constructor(message: string, code?: string | undefined, originalError?: Error | undefined);
}
export declare class LoopKitInitializationError extends LoopKitError {
constructor(message: string, originalError?: Error);
}
export declare class LoopKitTrackingError extends LoopKitError {
constructor(message: string, originalError?: Error);
}