一个完整的 Web 性能报告插件。
- 一 :所有类型通用的上报SDK 即:web-report-default.js
- 二 :针对于使用Jquery ajax的上报SDK 即:web-report-jquery.js
- 三 :针对于使用Axios ajax的上报SDK 即:web-report-axios.js
- 四 :针对于使用Fetch ajax的上报SDK 即:web-report-fetch.js
- 五 :针对于业务代码手动触发的上报SDK 即:web-report-none.js
通用版本适合所有上报情况
至于四种sdk的选择可酌情选择。通常来说专库专用会更好,因此使用jquery的推荐第二种,使用fetch的推荐第三种,使用Axios的推荐第三种,其他情况使用通用版本
web-report-sdk 只做页面性,错误信息,资源信息,ajax信息等上报,让你不用关心浏览器上报部分,是一个比较完整和健全的数据上报插件。
在此基础上你可以开发任何自己需要的性能上报系统。
- url 上报页面地址
- preUrl 来访上一页面URL
- performance 页面性能数据详情,字段含义详情请参考后面内容
- errorList 页面错误信息详情,包含js,img,ajax,fetch等所有错误信息,字段含义详情请参考后面内容
- resoruceList 页面性能数据详情,当前页面所有资源性能详情信息,字段含义详情请参考后面内容
- markUv 统计uv标识
- markUser 从用户进入网站开始标识,直到用户离开销毁,可以用来做用户漏斗分析
- time 当前上报时间
- screenwidth 屏幕宽度
- screenheight 屏幕高度
- isFristIn 是否是某次会话的第一次进入
- type 上报类型 1:页面级性能上报 2:页面ajax性能上报 3:页面内错误信息上报
- 1、下载 dist/web-report-default.min.js 到本地
- 2、使用script标签引入到html的头部(备注:放到所有js资源之前)
- 3、使用performance函数进行数据的监听上报
performance test
npm install web-report --save
import {
Performance,
axiosReport,
defaultReport,
fetchReport,
jqueryReport,
noneReport
} from 'web-report'
npm install web-report --save
//New performance.js file
//The contents are as follows
import { Performance } from 'web-report'
Performance({
domain:'http://some.com/api'
})
//Change webpack configuration
entry: {
//add performance entry
'performance':path.resolve(__dirname, '../src/performance.js'),
},
//change htmlWebpackPlugin config like this
//Attention to dependence
new htmlWebpackPlugin({
...
chunks: ['vendors','performance','main'],
chunksSortMode: 'manual',
}),
router.afterEach((to, from, next) => {
if(from.name){
try{ window.ReportData(); }catch(e){}
}else{
addEventListener("load",function(){
try{ window.ReportData(); }catch(e){}
},false);
}
})
https://github.com/wangweianger/zanePerfor
https://www.npmjs.com/package/web-report
- 同时传入 domain和传入的function ,function优先级更高,也就是说function会执行
- domain :上报api接口
- outtime :上报延迟时间,保证异步数据的加载 (默认:300ms)
- isPage :是否上报页面性能数据 (默认:true)
- isResource :是否上报页面资源性能数据 (默认:true)
- isError :是否上报页面错误信息数据 (默认:true)
- isAjax :是否上报ajax信息 (默认:true)
- add :附带参数 (值为json object 例如:{APPID:'123456789'})
- filterUrl :不需要上报的ajax请求 (例如开发模式下的livereload链接)
- fn :自定义上报函数,上报方式可以用ajax可以用fetch (非必填:默认使用fetch,如果使用ajax则必须参数 report:'report-data',如果是fetch则必须参数:type:'report-data')
…
一:addError :此方法向插件中自定义上报错误信息,vue,react,try{}catch 的报错信息均可采用此方法上报 案例:
let message = 'js add error'
let col = 20
let line = 20
let resourceUrl = 'http://www.xxx.com/01.js'
Performance.addError({
msg:message,
col:col,
line:line,
resourceUrl:resourceUrl
})
二:addData :上报时自定义的数据 案例:
Performance.addData((data)=>{
data.name = 'wangwei'
data.some = {
name:'wangwie',
age:20
}
})
If you use the Vue framework, you can do it like this.
…
If you use the React framework, you can do it like this.
…
git clone https://github.com/wangweianger/web-report-sdk.git
npm install
//Development
npm run dev
//product
npm run build
//test page
http://localhost:8080/test/
| parameter name | describe | explain |
|---|---|---|
| url | 上报页面地址 | |
| markUv | 统计uv标识 | |
| markUser | 用户标识 | 可用来做UV统计,和用户行为漏斗分析 |
| isFristIn | 是否是每次会话的第一次渲染 | 可以用来做首屏渲染性能统计分类 |
| type | 上报类型 | 1:页面级性能上报 2:页面ajax性能上报 3:页面内错误信息上报 |
| screenwidth | 屏幕宽度 | |
| screenheight | 屏幕高度 | |
| preUrl | 上一页面 | |
| errorList | 错误资源列表信息 | |
| ->t | 资源时间 | |
| ->n | 资源类型 | resource,js,ajax,fetch,other |
| ->msg | 错误信息 | |
| ->method | 资源请求方式 | GET,POST |
| ->data->resourceUrl | 请求资源路径 | |
| ->data->col | js错误行 | |
| ->data->line | js错误列 | |
| ->data->status | ajax错误状态 | |
| ->data->text | ajax错误信息 | |
| performance | 页面资源性能数据(单位均为毫秒) | |
| ->dnst | DNS解析时间 | |
| ->tcpt | TCP建立时间 | |
| ->wit | 白屏时间 | |
| ->domt | dom渲染完成时间 | |
| ->lodt | 页面onload时间 | |
| ->radt | 页面准备时间 | |
| ->rdit | 页面重定向时间 | |
| ->uodt | unload时间 | |
| ->reqt | request请求耗时 | |
| ->andt | 页面解析dom耗时 | |
| resoruceList | 页面资源性能数据 | |
| ->decodedBodySize | 资源返回数据大小 | |
| ->duration | 资源耗时 | |
| ->method | 请求方式 | GET,POST |
| ->name | 请求资源路径 | |
| ->nextHopProtocol | http协议版本 | |
| ->type | 请求资源类型 | script,img,fetchrequest,xmlhttprequest,other |
…
暂无开放 Issues,或尚未同步最近议题。