推荐一个上报事件插件 “reportEvent”

GitHub地址:https://github.com/shiweihua960613/reportEvent

reportEvent

一个支持常规PCH5,单网页应用ReactVueAngurla 的上报事件小插件,使用简单,代码轻量。

参数自动序列化,自带一个唯一uuid frontUvId 存储在本地 eventFrontUvId 中,每次上报事件都会携带这个参数

直接调用

适用于路由切换、接口请求完毕、onload、接口或方法回调等场景。callback为非必填

window.reportEvent.reportEventFunc(object,callback);

window.reportEvent.reportEventFunc({code:1,id:2},(res)=>{
console.log('调用完成=>',res)
});

自动绑定click事件,完成上报

支持数组传参和对象的方式传递参数,上报方法会检测类型,如果是数组,会循环数组,并多次上报里边的对象;对象直接上报,传递的参数需要JSON.stringify(对象或者数组)

目前自动绑定只做了click,如果各位有兴趣拓展,可以直接在GitHub提交pull requests

PC or H5

对象:
<div data-reporteventfunc="click" data-reporteventdata='{"code":"1","id":"2"}'></div>
数组:
<div data-reporteventfunc="click" data-reporteventdata='[{"code":"1","id":"2"},{"code":"1","id":"2"}]'></div>

React

对象:
<div data-reporteventfunc={'click'} data-reporteventdata={JSON.stringify({code:1,id:2})}></div>
数组:
<div data-reporteventfunc={'click'} data-reporteventdata={JSON.stringify([{code:1,id:2},{code:1,id:2}])}></div>

Vue

对象:
<div data-reporteventfunc="click" :data-reporteventdata="JSON.stringify({code:1,id:2})"></div>
数组:
<div data-reporteventfunc="click" :data-reporteventdata="JSON.stringify([{code:1,id:2},{code:1,id:2}])"></div>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。