{"id":25733624,"url":"https://github.com/li-vien/dataacquisition","last_synced_at":"2026-01-28T08:41:49.950Z","repository":{"id":144064894,"uuid":"95202837","full_name":"Li-vien/dataAcquisition","owner":"Li-vien","description":"前端数据采集，前端异常数据采集，用户行为监控采集，用户前端异常监控，图形化分析插件dataAcquisition（附demo）","archived":false,"fork":false,"pushed_at":"2023-10-08T10:06:55.000Z","size":189,"stargazers_count":187,"open_issues_count":0,"forks_count":58,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-06T08:02:11.686Z","etag":null,"topics":["dataacquisition","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Li-vien.png","metadata":{"files":{"readme":"README-CN.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-06-23T09:00:09.000Z","updated_at":"2025-03-19T08:09:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"e979fb81-c576-4092-badd-f92cc5533465","html_url":"https://github.com/Li-vien/dataAcquisition","commit_stats":null,"previous_names":["li-vien/dataacquisition"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Li-vien/dataAcquisition","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Li-vien%2FdataAcquisition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Li-vien%2FdataAcquisition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Li-vien%2FdataAcquisition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Li-vien%2FdataAcquisition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Li-vien","download_url":"https://codeload.github.com/Li-vien/dataAcquisition/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Li-vien%2FdataAcquisition/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263868205,"owners_count":23522315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataacquisition","javascript"],"created_at":"2025-02-26T04:14:40.391Z","updated_at":"2026-01-28T08:41:49.943Z","avatar_url":"https://github.com/Li-vien.png","language":"JavaScript","readme":"## 前端数据采集上报插件 dataAcquisition.js （求小星星，求star）\n\n### 公告：\n大家在使用过程中有任何需求，或者有不满意的点都可以提交上来。\n此插件已开始支持Vuejs环境下使用，配置更丰富，功能更强大，使用更简单: [Vue-dataAc](https://github.com/adminV/Vue-dataAc)\n\n### 目的：\n1. 实现前端数据上报分析\n2. 实现用户画像建模，轨迹分析\n3. 实现主动埋点上报以及自动埋点\n4. 搭配node接口实现日志存储解析\n5. 实现前端页面加载速度上报\n6. 实现前端接口异常上报\n7. 实现前端代码异常上报\n8. 实现页面圈选采集  (未完成)\n\n### 使用方式：\n1. clone代码到本地\n2. 修改store.sendUrl为上报接口地址\n3. 修改store.selector输入元素选择器，用来指定输入事件监听范围\n4. 如需对输入采集进行过滤，可更改store.acRange来指定，password最好不要进行采集。此处只为示例。\n5. 点击元素默认向上冒泡采集两层，可修改store.acbLength来更改采集层数\n6. 将文件放置在逻辑代码加载之前（支持AMD）\n7. server目录下为基于Node.js开发的采集数据接收端\n\n### 主动埋点/自动埋点\n只需修改classTag配置即可实现两种采集方式。\nclassTag为空时 采集所有元素\nclassTag有值时，只会采集class中包含该值的元素\n\n### 手动数据上报\n调用 window.dataAc.postData() 即可\n\n### 日志：\n2017-04-03 - 实现基本页面访问数据上报\n\n2017-04-22 - 实现点击数据上报\n\n2017-05-28 - 全功能完成测试中\n\n2017-05-31 - 正式第一版部署到ult进行采集\n\n2017-06-09 - 爆出cookie过大导致400异常\n\n2017-06-14 - powerBI展示层完成\n\n2017-06-15 - 立项保存\n\n版本升级：1.0.1\n\n2017-06-18 - 增加点击元素采集限制，避免数据过大\n\n2017-06-20 - 增加输入框采集类型配置\n\n2017-06-21 - 增加接口异常上报，代理ajax error处理函数\n\n2017-06-22 - 增加代码异常上报。监听onerror事件\n\n2017-06-23 - 增加performance API统计页面加载时间信息\n\n版本升级：1.0.2\n\n2018-08-9  - 减少对jquery的依赖,除选择器外已全部替换\n\n2018-08-10 - 增加配置,增加demo展示\n\n2018-08-24 - 增加server端代码,使项目可在本地运行\n\n版本升级：1.0.3\n\n2019-11-11 - 取消对jquery的依赖，包括选择器、请求拦截器      \n2019-11-12 - 增加图片数据上报方式\n\n### 可配置参数：\n        sendUrl      : \"http://localhost:9090/logStash/push\",   //log采集地址\n        selector     : 'input',     //配置输入框的选择器来限定input.focus.blur事件监听范围;\n        acRange      : ['text','tel'],   //配置输入框type属性,控制采集范围\n        maxDays      : 5,           //cookie期限,默认:5天\n        userSha      : 'userSha',   //用户标识保存key\n        classTag     : 'isjs-ac',   //主动埋点时的class,设置为''时为全量采集,数据会很大\n        openInput    : 'true',      //是否开启输入采集\n        openCodeErr  : 'true',      //是否开启代码异常采集\n        openClick    : 'true',      //是否开启点击数据采集\n        openAjaxData : 'true',      //是否采集异常请求的params(注意隐私数据的保护)\n        openPerformance : 'true',   //是否开启页面性能采集\n        acblength    : 2,           //点击元素采集层数.层数越深数据越大\n\n\n\n\n### 参数介绍：\n#### sendUrl\n    与之搭配的后台接口,可以用node写一个接收端来写日志.\n    注意:该接口最好不要阻塞,以免影响页面响应.\n#### selector\n    selector选项用来控制输入框input.focus.blur事件的采集范围。\n    其实就是一个document.querySelectorAll的选择器,\n    值参考：https://www.runoob.com/cssref/css-selectors.html\n    \n    可以通过指定id实现主动埋点的功能.\n#### acRange\n    此条件用来控制输入框的采集范围,与 selector 选项功能一致,但优先级低于 selector 选项\n    注意,尽量不要采集type类型为password的元素内容,以免信息泄露\n#### classTag\n    用来实现主动埋点，会验证元素class是否包含指定标记\n    只需要对需要采集的元素:\u003cinput class=\"qyd_aci_0001\" /\u003e设置classTag为 qyd_aci\n#### userSha\n    用户uuid在浏览器中保存的key,有冲突时可以手动修改\n#### maxDays\n    cookie的保存期限,不建议设置过长时间,以免影响其他cookie存储\n#### acblength\n    此选项用来限制点击事件的冒泡层数.\n    我们通过 document.addEventListener(\"click\", function (e) {...}); 来监听点击事件.\n    选择事件冒泡的原理来采集,是因为有的html内容是js动态生成的,固定的选择器会遗漏掉.\n    目前的点击采集是自动埋点,所有元素的点击都会向上冒泡采集两层,采集的结果会有很多小元素,更具体的显示用户行为\n    当然,点击事件也支持主动埋点,只需要将329行注释掉的代码解开即可\n    注意,主动埋点与自动埋点只能保留一种.(当然你可以自己定制)\n\n### 数据格式：\n1. 行为数据\n\n\t\t{\n\t\t\t\"uuid\":\"F6A6C801B7197603\",                        //用户标识，5天有效\n\t\t\t\"acData\":[\t\t\t\t\t  //数据集\n                    {\n\t\t\t\t\t\"type\"  : \"ACINPUT/ACPAGE/ACCLIK\",   //上报数据类型：输入框/页面访问/点击事件\n\t\t\t\t\t\"path\"  : \"www.domain.com/w/w/w/\",   //事件发生的url\n\t\t\t\t\t\"eId\"   : \"qyd_acb_0_1\",\t\t  //事件发生的元素ID\n\t\t\t\t\t\"className\" : \"js_acb_2_0\",\t  //事件发生的元素class\n\t\t\t\t\t\"sTme\"  : \"13000000\",\t\t  //事件发生开始时间\n\t\t\t\t\t\"eTme\"  : \"130020122\",\t\t  //事件结束事件\n\t\t\t\t\t\"val\"   : \"123,3000:1234,4000:12345\", //事件发生后不同时间元素的值\n\t\t\t\t\t\"utk\"   : \"usertoken\"\t\t  //关联后台日志（未实现）\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t\n2. 接口异常数据\n\t\n\t\t{\n\t        \"type\"       : \"ACRERR\",                   //上报数据类型：接口异常\n\t        \"path\"       : \"www.domain.com/w/w/w/\",    //事件发生页面的url\n\t        \"sTme\"       : \"2017-06-21 13:31:31\",\t   //事件发生时间\n\t        \"requrl\"     : \"/mt/klalsjdjlenm\", //接口地址\n\t        \"readyState\" : \"2\",                //当前状态,0-未初始化，1-正在载入，2-已经载入，3-数据进行交互，4-完成。\n\t        \"status\"     : \"301\",              //请求状态码：400，500，404\n\t        \"statusText\" : \"Internal Server Error\", //404错误信息是not found,500是Internal Server Error。\n\t\t    \"textStatus\" : \"parsererror\", //timeout\"（超时）, \"error\"（错误）, \"abort\"(中止), \"parsererror\"（解析错误）\n\t    }\n    \n3. 代码异常数据\n\t\n\t\t{\n\t        \"type\"    : \"ACCERR\",     \t\t  //上报数据类型：代码异常\n\t        \"path\"    : \"www.domain.com/w/w/w/\",   //事件发生页面的url\n\t        \"sTme\"    : \"2017-06-21 13:31:31\",\t  //事件发生时间\n\t        \"msg\"     : \"script error\",       //异常摘要\n\t        \"line\"    : \"301\",  \t\t  //代码行数\n\t        \"col\"     : \"异常\",  \t\t //异常堆栈数据\n\t\t    \"err\"     : \"异常信息\",\n\t\t    \"ua\"      : \"ios/chrome 44.44\"    //浏览器版本\n\t    }\n    \n4. 时间数据\n\t\n\t\t{\n\t\t    \"type\"    : \"ACTIME\",     \t      //上报数据类型：代码异常\n\t\t    \"path\"    : \"www.domain.com/w/w/w/\",   //事件发生页面的url\n\t\t    \"DNS\"     : \"152\",       \t      //DNS查询时间\n\t\t    \"TCP\"     : \"525\",  \t      //TCP连接耗时\n\t\t    \"WT\"      : \"555\",  \t      //白屏时间\n\t\t    \"DR\"      : \"123\", \t\t      //dom ready时间，脚本加载完成时间\n\t\t    \"ONL\"     : \"152\",     \t      //执行onload事件耗时\n\t\t    \"ALLRT\"   : \"152\",                //所有请求耗时\n\t\t    \"PRDOM\"   : \"152\",                //dom解析耗时\n\t\t    \"FXHR\"    : \"152\"  \t              //第一个请求发起时间\n\t\t}\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-vien%2Fdataacquisition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fli-vien%2Fdataacquisition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-vien%2Fdataacquisition/lists"}