tianji-client-sdk
Version:
111 lines • 2.61 kB
TypeScript
/**
* Pure Website Tracking SDK for Tianji
* Simple event tracking without DOM manipulation or auto-tracking
*/
import { IdentifyPayload } from '../types';
/**
* Website event payload interface
*/
export interface WebsiteEventPayload {
/**
* Website identifier (required)
*/
website: string;
/**
* Current hostname
*/
hostname?: string;
/**
* Screen resolution
*/
screen?: string;
/**
* Browser language
*/
language?: string;
/**
* Page title
*/
title?: string;
/**
* Current URL
*/
url?: string;
/**
* Referrer URL
*/
referrer?: string;
/**
* Event name (for custom events)
*/
name?: string;
/**
* Event data
*/
data?: Record<string, any>;
}
/**
* Website identify payload interface
*/
export interface WebsiteIdentifyPayload extends WebsiteEventPayload {
/**
* User identification data (required for identify)
*/
data: Record<string, any>;
}
/**
* Batch request item interface
*/
export interface BatchRequestItem {
type: 'event' | 'identify';
payload: WebsiteEventPayload | WebsiteIdentifyPayload;
}
/**
* Options for website tracking
*/
export interface WebsiteTrackingOptions {
/**
* Your Tianji server URL
* @example https://tianji.example.com
*/
serverUrl: string;
/**
* Website identifier
*/
websiteId: string;
/**
* Batch delay in milliseconds (optional, defaults to 200ms)
*/
batchDelay?: number;
/**
* Disable batch mode and send requests immediately (optional, defaults to false)
*/
disableBatch?: boolean;
}
/**
* Initialize website tracking
*/
export declare function initWebsiteTracking(_options: WebsiteTrackingOptions): void;
/**
* Send website page view event to Tianji server
*/
export declare function trackPageView(url?: string, title?: string): Promise<void>;
/**
* Send custom website event to Tianji server
*
* @param eventName - Name of the event
* @param eventData - Event data
*/
export declare function reportWebsiteEvent(eventName: string, eventData?: Record<string, any>): Promise<void>;
/**
* Identify user for website tracking
*
* @param userData - User identification data
*/
export declare function identifyWebsiteUser(userInfo: IdentifyPayload): Promise<void>;
/**
* Flush batch queue manually (send all pending requests immediately)
* Useful for ensuring events are sent before page unload
*/
export declare function flushBatchQueue(): Promise<void>;
//# sourceMappingURL=pure.d.ts.map