UNPKG

@tinytapanalytics/sdk

Version:

Behavioral psychology platform that detects visitor frustration, predicts abandonment, and helps you save at-risk conversions in real-time

76 lines 2.25 kB
/** * Network Manager for handling HTTP requests with retry logic and error handling */ import { TinyTapAnalyticsConfig, NetworkRequest, NetworkResponse } from '../types/index'; import { ErrorHandler } from './ErrorHandler'; export declare class NetworkManager { private config; private errorHandler; constructor(config: TinyTapAnalyticsConfig, errorHandler: ErrorHandler); /** * Send a network request with retry logic */ request<T = any>(request: NetworkRequest): Promise<NetworkResponse<T>>; /** * Send events in batch */ sendBatch(events: any[]): Promise<void>; /** * Send a single event */ sendEvent(event: any): Promise<void>; /** * Check if the SDK can connect to the API */ ping(): Promise<boolean>; /** * Make the actual HTTP request */ private makeRequest; /** * Parse response body */ private parseResponse; /** * Parse response headers */ private parseHeaders; /** * Sleep for specified milliseconds */ private sleep; /** * Check if the current network connection supports sending data */ canSendData(): boolean; /** * Use sendBeacon for critical events when page is unloading */ sendBeacon(event: any): boolean; /** * Send event using image beacon (CORS-free method) * This works across all domains without CORS restrictions */ sendImageBeacon(event: any): Promise<boolean>; /** * Send event with automatic fallback strategy * 1. Try XHR/fetch (best for rich data) * 2. Fall back to sendBeacon (reliable, no CORS) * 3. Fall back to image beacon (works everywhere) */ sendWithFallback(event: any): Promise<boolean>; /** * Compress event data for URL transmission (used by image beacon) * Removes large fields and keeps only essential data */ private compressEventForBeacon; /** * Compress metadata to fit in URL */ private compressMetadata; /** * Make request with CORS credentials if configured */ requestWithCredentials<T>(request: NetworkRequest): Promise<NetworkResponse<T>>; } //# sourceMappingURL=NetworkManager.d.ts.map