@unimed-web-tracing/core
Version:
基于 JS 跨平台插件,为前端项目提供【 埋点、行为、性能、异常、请求、资源、路由、曝光、录屏 】监控手段
343 lines (332 loc) • 10.4 kB
TypeScript
interface ObserverValue<T> {
value: T;
}
/**
* 触发的事件id - eventID
*/
declare enum SENDID {
PAGE = "page",// 页面
RESOURCE = "resource",// 资源
SERVER = "server",// 请求
CODE = "code",// code
REJECT = "reject",// reject
CONSOLEERROR = "console.error"
}
interface Pv {
core?: boolean;
}
interface Performance {
core?: boolean;
firstResource?: boolean;
server?: boolean;
}
interface Error {
core?: boolean;
server?: boolean;
}
interface Event {
core?: boolean;
}
interface IRequestType {
type?: "fetch" | "beacon" | "XMLHttpRequest";
headers?: AnyObj<string | number> | (() => AnyObj<string | number>);
}
interface IDsnOptions {
username: string;
password: string;
clientId: string;
qos?: number | string;
topic?: string;
}
type TUserUuid = string | (() => string);
/**
* sdk内部配置
*/
type InternalOptions = {
dsn: string;
encrypt?: boolean;
dsnOptions?: IDsnOptions;
requestId?: string;
serverName?: string;
invokeFormatSendDataCb?: (data: AnyObj) => any;
appName?: string;
appCode: string;
appVersion: string;
userUuid: () => string;
sdkUserUuid: string;
debug: boolean;
pv: Pv;
performance: Performance;
error: Error;
event: Event;
ext: AnyObj;
tracesSampleRate: number;
cacheMaxLength: number;
cacheWatingTime: number;
ignoreErrors: Array<string | RegExp>;
ignoreRequest: Array<string | RegExp>;
scopeError: boolean;
localization: boolean;
sendTypeByXmlBody?: boolean;
beforePushEventList: AnyFun[];
beforeSendData: AnyFun[];
afterSendData: AnyFun[];
localizationOverFlow: VoidFun;
recordScreen: boolean;
requestType?: IRequestType;
};
/**
* sdk初始化入参配置
*/
type InitOptions = {
dsn?: string;
dsnOptions?: IDsnOptions;
encrypt?: boolean;
requestId?: string;
serverName?: string;
appName?: string;
appCode?: string;
appVersion?: string;
userUuid?: TUserUuid;
debug?: boolean;
pv?: Pv | boolean;
performance?: Performance | boolean;
error?: Error | boolean;
event?: Event | boolean;
ext?: {
[key: string]: any;
};
tracesSampleRate?: number;
cacheMaxLength?: number;
cacheWatingTime?: number;
ignoreErrors?: Array<string | RegExp>;
ignoreRequest?: Array<string | RegExp>;
scopeError?: boolean;
localization?: boolean;
sendTypeByXmlBody?: boolean;
beforePushEventList?: (data: any) => any;
afterSendData?: (data: any) => void;
recordScreen?: boolean;
invokeFormatSendDataCb?: (data: AnyObj) => AnyObj;
requestType?: IRequestType;
};
type ElementOrList = Element | Element[];
interface TargetGather {
target: ElementOrList;
threshold: number;
params?: AnyObj;
}
type VoidFun = {
(...args: any[]): void;
};
type AnyFun = {
(...args: any[]): any;
};
type AnyObj<T = any> = {
[key: string]: T;
};
declare let options: ObserverValue<InternalOptions>;
interface ErrorStack {
errMessage: string;
errStack: string;
}
/**
* 分析错误信息
* @param e 错误源信息
* @returns 相对标准格式的错误信息
*/
declare function parseError(e: any): ErrorStack | {
errMessage: string;
errStack: string | undefined;
eventId: SENDID;
line: string;
col: string;
triggerPageUrl: string;
} | {
eventId: SENDID;
errMessage: any;
errStack?: undefined;
line?: undefined;
col?: undefined;
triggerPageUrl?: undefined;
} | {
errMessage?: undefined;
errStack?: undefined;
eventId?: undefined;
line?: undefined;
col?: undefined;
triggerPageUrl?: undefined;
};
/**
* 控制台输出错误信息
* @param args 错误信息
*/
declare function logError(...args: any[]): void;
/**
* 解压错误录屏数据
*/
declare function unzipRecordscreen(recordscreen: string): string;
/**
* 钩子:放入事件队列之前
* @param fun 回调函数
*/
declare function beforePushEventList(fun: AnyFun): void;
/**
* 钩子:发送之前
* @param fun 回调函数
*/
declare function beforeSendData(fun: AnyFun): void;
/**
* 钩子:发送之后
* @param fun 回调函数
*/
declare function afterSendData(fun: AnyFun): void;
/**
* 设置用户id
* @param id 用户id
*/
declare function setUserUuid(id: string): void;
/**
* 获取用户id(此id是手动设置的id)
*/
declare function getUserUuid(): string | void;
/**
* 获取sdk中的用户id
*/
declare function getSDKUserUuid(): string | void;
/**
* 获取在sdk中记录的所有基础的信息(包括硬件,地理位置等等)
*/
declare function getBaseInfo(): object | void;
/**
* 获取首屏数据
*/
declare function getFirstScreen(): object | void;
/**
* 主动触发error事件上报
* @param options 自定义配置信息
*/
declare function traceError(options?: {}, flush?: boolean): void;
/**
* 主动触发性能事件上报
* @param options 自定义配置信息
*/
declare function tracePerformance(options?: {}, flush?: boolean): void;
/**
* 主动触发事件上报
* @param options 自定义配置信息
*/
declare function traceCustomEvent(options?: {}, flush?: boolean): void;
/**
* 主动触发pv事件上报
* @param options 自定义配置信息
*/
declare function tracePageView(option?: {}, flush?: boolean): void;
/**
* 获取公网ip
*/
declare function getIPs(): Promise<string>;
/**
* 曝光 - 对目标元素进行监听
* @param params 附带的额外参数
*/
declare function intersectionObserver(gather: TargetGather): void;
/**
* 曝光 - 对目标元素进行取消监听
*/
declare function intersectionUnobserve(target: ElementOrList): void;
/**
* 曝光 - 取消所有监听
*/
declare function intersectionDisconnect(): void;
/**
* 手动发送本地数据
*/
declare function sendLocal(): void;
/**
* 设置本地化存储溢出后的回调
* @param overFlowFun 回调函数
*/
declare function setLocalizationOverFlow(overFlowFun: VoidFun): void;
/**
* 获取sdk内部的参数配置
* 这个参数配置并不是入参配置,sdk内部的参数是整理过后的
*/
declare function getOptions(): InternalOptions;
/**
* 立即发送
*/
declare function invokeSendData(): void;
declare const exportMethods_afterSendData: typeof afterSendData;
declare const exportMethods_beforePushEventList: typeof beforePushEventList;
declare const exportMethods_beforeSendData: typeof beforeSendData;
declare const exportMethods_getBaseInfo: typeof getBaseInfo;
declare const exportMethods_getFirstScreen: typeof getFirstScreen;
declare const exportMethods_getIPs: typeof getIPs;
declare const exportMethods_getOptions: typeof getOptions;
declare const exportMethods_getSDKUserUuid: typeof getSDKUserUuid;
declare const exportMethods_getUserUuid: typeof getUserUuid;
declare const exportMethods_intersectionDisconnect: typeof intersectionDisconnect;
declare const exportMethods_intersectionObserver: typeof intersectionObserver;
declare const exportMethods_intersectionUnobserve: typeof intersectionUnobserve;
declare const exportMethods_invokeSendData: typeof invokeSendData;
declare const exportMethods_sendLocal: typeof sendLocal;
declare const exportMethods_setLocalizationOverFlow: typeof setLocalizationOverFlow;
declare const exportMethods_setUserUuid: typeof setUserUuid;
declare const exportMethods_traceCustomEvent: typeof traceCustomEvent;
declare const exportMethods_traceError: typeof traceError;
declare const exportMethods_tracePageView: typeof tracePageView;
declare const exportMethods_tracePerformance: typeof tracePerformance;
declare const exportMethods_unzipRecordscreen: typeof unzipRecordscreen;
declare namespace exportMethods {
export {
exportMethods_afterSendData as afterSendData,
exportMethods_beforePushEventList as beforePushEventList,
exportMethods_beforeSendData as beforeSendData,
exportMethods_getBaseInfo as getBaseInfo,
exportMethods_getFirstScreen as getFirstScreen,
exportMethods_getIPs as getIPs,
exportMethods_getOptions as getOptions,
exportMethods_getSDKUserUuid as getSDKUserUuid,
exportMethods_getUserUuid as getUserUuid,
exportMethods_intersectionDisconnect as intersectionDisconnect,
exportMethods_intersectionObserver as intersectionObserver,
exportMethods_intersectionUnobserve as intersectionUnobserve,
exportMethods_invokeSendData as invokeSendData,
exportMethods_sendLocal as sendLocal,
exportMethods_setLocalizationOverFlow as setLocalizationOverFlow,
exportMethods_setUserUuid as setUserUuid,
exportMethods_traceCustomEvent as traceCustomEvent,
exportMethods_traceError as traceError,
exportMethods_tracePageView as tracePageView,
exportMethods_tracePerformance as tracePerformance,
exportMethods_unzipRecordscreen as unzipRecordscreen,
};
}
declare function init(options: InitOptions): void;
declare const _default: {
options: ObserverValue<InternalOptions>;
unzipRecordscreen(recordscreen: string): string;
beforePushEventList(fun: AnyFun): void;
beforeSendData(fun: AnyFun): void;
afterSendData(fun: AnyFun): void;
setUserUuid(id: string): void;
getUserUuid(): string | void;
getSDKUserUuid(): string | void;
getBaseInfo(): void | object;
getFirstScreen(): void | object;
traceError(options?: {}, flush?: boolean): void;
tracePerformance(options?: {}, flush?: boolean): void;
traceCustomEvent(options?: {}, flush?: boolean): void;
tracePageView(option?: {}, flush?: boolean): void;
getIPs(): Promise<string>;
intersectionObserver(gather: TargetGather): void;
intersectionUnobserve(target: ElementOrList): void;
intersectionDisconnect(): void;
sendLocal(): void;
setLocalizationOverFlow(overFlowFun: VoidFun): void;
getOptions(): InternalOptions;
invokeSendData(): void;
init: typeof init;
};
export { InitOptions, SENDID, afterSendData, beforePushEventList, beforeSendData, _default as default, exportMethods, getBaseInfo, getFirstScreen, getIPs, getOptions, getSDKUserUuid, getUserUuid, init, intersectionDisconnect, intersectionObserver, intersectionUnobserve, invokeSendData, logError, options, parseError, sendLocal, setLocalizationOverFlow, setUserUuid, traceCustomEvent, traceError, tracePageView, tracePerformance, unzipRecordscreen };