UNPKG

@sdc-monitor/demo

Version:

<div align="center"> <a href="#" target="_blank"> <img src="https://i.loli.net/2021/07/28/EvPwd4NjVH3tBfO.jpg" alt="mito-logo" height="90"> </a> <p>A Lightweight SDK For Monitor Web</p>

53 lines (48 loc) 2.05 kB
import Store from '../core/store' import { WxPerformanceDataType, WxPerformanceItemType } from '../constant' import { WxPerformanceItem, WxPerformanceAnyObj } from '../types/index' function pushLife(store: Store, itemType: WxPerformanceItemType) { store.push(WxPerformanceDataType.WX_LIFE_STYLE, { itemType, timestamp: Date.now() }) } function pushAction(store: Store, data: WxPerformanceItem) { store.push(WxPerformanceDataType.WX_USER_ACTION, { ...data, timestamp: Date.now() }) } function pushNetwork(store: Store, data: WxPerformanceItem) { store.push(WxPerformanceDataType.WX_NETWORK, { ...data, timestamp: Date.now() }) } const Events = { [WxPerformanceItemType.AppOnLaunch]: function (args: any[]) { const _this = this as Store const now = Date.now() _this.setLaunchTime(now) _this.push(WxPerformanceDataType.WX_LIFE_STYLE, { itemType: WxPerformanceItemType.AppOnLaunch, timestamp: now }) }, [WxPerformanceItemType.AppOnShow]: function () { pushLife(this, WxPerformanceItemType.AppOnShow) }, [WxPerformanceItemType.PageOnLoad]: function () { pushLife(this, WxPerformanceItemType.PageOnLoad) }, [WxPerformanceItemType.PageOnReady]: function () { pushLife(this, WxPerformanceItemType.PageOnReady) }, [WxPerformanceItemType.PageOnUnload]: function () { pushLife(this, WxPerformanceItemType.PageOnUnload) }, [WxPerformanceItemType.UserTap]: function (event: WxPerformanceAnyObj) { pushAction(this, { ...event, itemType: WxPerformanceItemType.UserTap }) }, [WxPerformanceItemType.UserTouchMove]: function (event: WxPerformanceAnyObj) { pushAction(this, { ...event, itemType: WxPerformanceItemType.UserTouchMove }) }, [WxPerformanceItemType.WxRequest]: function (data: WxPerformanceItem) { pushNetwork(this, data) }, [WxPerformanceItemType.WxDownloadFile]: function (data: WxPerformanceItem) { pushNetwork(this, data) }, [WxPerformanceItemType.WxUploadFile]: function (data: WxPerformanceItem) { pushNetwork(this, data) } } export default Events