You need to enable JavaScript to run this app.
导航

生命周期

最近更新时间2022.09.02 17:44:34

首次发布时间2022.03.16 11:20:41

通过on挂载监听,通过off卸载监听。

init

监听实例被初始化。

client('on', 'init', () => {
    ...
 })

start

监听实例开启上报。

client('on', 'start', () => {
    ...
 })

beforeConfig

监听实例配置变更之前,可拿到新的配置。

client('on', 'beforeConfig', (config: Partial<Config>) => {
    ...
})

config

监听实例配置变更后的瞬间。

client('on', 'config', () => {
    ...
 })

provide

监听实例被挂载属性的瞬间,可拿到属性名。

client('on', 'provide', (name: string) => {
    ...
 })

report

监听事件被监控插件发送的瞬间, 可用于为事件补充上下文, 返回Falsy类型则不上报。

client('on', 'report', (ev: ReportEvent): ReportEvent | Falsy => {
    ...
 })

export type Falsy = false | null | undefined

beforeBuild

监听事件被包装上下文之前的瞬间, 能够拿到即将被包装的数据, 返回Falsy类型则不上报。

client('on', 'beforeBuild', (ev: ReportEvent): ReportEvent | Falsy => {
    ...
 })

export type Falsy = false | null | undefined

build

监听事件被包装上下文之后的瞬间,能够拿到即将上报的数据, 返回Falsy类型则不上报。

client('on', 'build', (ev: SendEvent): SendEvent | Falsy => {
    ...
 })

export type Falsy = false | null | undefined

beforeSend

监听事件被发送之前的瞬间, 返回Falsy类型则不上报。

client('on', 'beforeSend', (ev: SendEvent): SendEvent | Falsy => {
    ...
 })

export type Falsy = false | null | undefined

send

注册事件发送之后的回调。

client('on', 'send', (e: Callback<SendEvent>) => {
    ...
 })
  
interface Callback<T> {
  (arg: T): void
}

beforeDestroy

注册实例销毁之前的回调。

client('on', 'beforeDestroy', () => {
    ...
 })

SendEvent && ReportEvent 类型声明

// 具体各类型上报格式见上报格式。
export type SendEvent =
  | CustomReport
  | HttpReport
  | JsErrorReport
  | PageviewReport
  | PerformanceReport
  | PerformanceLongTaskReport
  | PerformanceTimingReport
  | ResourceErrorReport
  | ResourceReport
  | SriReport
  | BlankReport

export type WebReport = Omit<SendEvent,'common'> 

export type ReportEvent<T extends WebReport> = T & {
  // 具体common格式见上报格式
  extra?: Partial<Common>
  // 允许额外上报一些 context 覆盖组装上下文,主要在预收集与预加载场景
  overrides?: Partial<Common>
}