EasyTrack
EasyTrack is a Typescript library for dealing with js error, xhr error and performance tracking.
Installation
yarn add easy-track
or
npm install easy-track
Usage
Config and Init
Create your Report log by sendBeacon function
import EasyTrack from 'easy-track'
const easyTrack = new EasyTrack({
acceptEventType: ['onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'],
track: ['jsError', 'performance', 'xhr'],
sendInterval: 1000 * 30,
sendQueueSize: 30,
sendUrl: 'http://localhost:8080/api/log/beacon/',
sendType: SEND_TYPE.BEACON,
singleMode: false,
getCurrentPage: () => window.location.href,
getInitialEventContent: () => {
return {
appInfo: {
// appID,
// version,
// appName,
},
systemInfo: {
ua: navigator.userAgent,
is_cookie: window.navigator.cookieEnabled ? 1 : 0,
cookie: document.cookie || '',
screen_height: window.screen.availHeight,
screen_width: window.screen.availWidth,
},
userInfo: {
// userId,
// openId,
},
}
},
})
easyTrack.init()
export default easyTrack
OR report log by your custom sendFn
import EasyTrack from 'easy-track'
const easyTrack = new EasyTrack({
acceptEventType: ['onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'],
track: ['jsError', 'performance', 'xhr'],
sendInterval: 1000 * 30,
sendQueueSize: 30,
sendFn: e => {
doReportSend(e)
console.log('EasyLogReport', e)
},
singleMode: false,
getCurrentPage: () => window.location.href,
getInitialEventContent: () => {
return {
appInfo: {
// appID,
// version,
// appName,
},
systemInfo: {
ua: navigator.userAgent,
is_cookie: window.navigator.cookieEnabled ? 1 : 0,
cookie: document.cookie || '',
screen_height: window.screen.availHeight,
screen_width: window.screen.availWidth,
},
userInfo: {
// userId,
// openId,
},
}
},
})
easyTrack.init(() => {
console.log('EasyLogReport init!')
})
export default easyTrack
Config Props
Property | Description | Type | Default |
---|---|---|---|
acceptEventType | log event types that are allowed to be reported | string[] | ['onLaunch', 'onLoad', 'onUnload', 'onShow', 'request', 'onError', 'click'] |
track | event types that need to be tracked | string[] | ['jsError', 'performance', 'xhr'] |
sendInterval | send function trigger interval(millisecond) | number | 1000 * 30 |
sendQueueSize | the maximum number of logs in queue | number | 50 |
singleMode | If it`s singleMode, report log immediately | boolean | false |
sendUrl | report url | number | - |
sendType | reporting mode | SEND_TYPE.IMG / SEND_TYPE.BEACON | - |
sendFn | custom sendFn, If sendFn is set, sendUrl and sendType would be remove | (content: ReportContent) => void | - |
getCurrentPage | get current page route | () => string | - |
getInitialEventContent | get the default log content | () => InitialReportContent | - |
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.