- 埋点 收集用户行为数据 前端插入代码或脚本 的方式 的捕获行为 以下三种方式都是用户行为 的业务数据
- 手动埋点
- 自动埋点
- 可视化埋点
- 监控
性能监控 错误监控 用户体验监控
在面试中 通常会问 首屏加载 页面耗时 资源请求 回流与重绘
- 性能监控通常变现为首屏的加载 页面交互等
- 用户体验监控 系统Bug 性能优化等
页面加载时间的监控
通过监听浏览器的load加载
用performance.now() 获取加载时间
Api 的调用耗时 请求发送前 请求收到后 只是监控浏览器的耗时
function apiPreformance(){
const start =performance.now()
fetch('https://api.imooc-web.lgdsunday.club//api/data-lazy/01').then((res)=> res.json())
then((data)=> {
const duration =performance.noy()-starttrackEvent('api _call',{
duration,
endpoint:
'https://api.imooc-web.lgdsunday.club//api/data-lazy/01
apiPreformance()
错误监控 是项目中错误是非常常见的问题
接口请求错误 同意的提示语 在js中 也可以直接 window.onerrow的方法去统一处理
- 自定义埋点上报(手动 ) 如 监控 dom 移入与 移除的时间 监控
<style>
#sectionId {
width: 200px;
height:200px;
background-color:mantiquewhite;
</style>
</head>
<body>
<div id="sectionId">自定义埋点上报</div>
<script>
function trackEvent(eventType,details){console.log(`Event:${eventType}`,details)}
</script>
总的来说 埋点 与监控 就是监听事件 很好理解