{"id":20254644,"url":"https://github.com/guancecloud/datakit-miniprogram-uniapp","last_synced_at":"2025-04-11T00:03:55.017Z","repository":{"id":57102597,"uuid":"387766049","full_name":"GuanceCloud/datakit-miniprogram-uniapp","owner":"GuanceCloud","description":"Based uniapp framework, compatible with the DataFlux RUM data collection SDK of various platforms","archived":false,"fork":false,"pushed_at":"2022-03-29T07:42:26.000Z","size":649,"stargazers_count":31,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T00:03:49.605Z","etag":null,"topics":["datakit","javascript","miniprogram","uniapp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GuanceCloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-20T11:14:18.000Z","updated_at":"2024-08-10T05:37:39.000Z","dependencies_parsed_at":"2022-08-20T21:40:51.367Z","dependency_job_id":null,"html_url":"https://github.com/GuanceCloud/datakit-miniprogram-uniapp","commit_stats":null,"previous_names":["dataflux-cn/datakit-miniprogram-uniapp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuanceCloud%2Fdatakit-miniprogram-uniapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuanceCloud%2Fdatakit-miniprogram-uniapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuanceCloud%2Fdatakit-miniprogram-uniapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuanceCloud%2Fdatakit-miniprogram-uniapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuanceCloud","download_url":"https://codeload.github.com/GuanceCloud/datakit-miniprogram-uniapp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317705,"owners_count":21083528,"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":["datakit","javascript","miniprogram","uniapp"],"created_at":"2024-11-14T10:34:15.428Z","updated_at":"2025-04-11T00:03:54.978Z","avatar_url":"https://github.com/GuanceCloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 基于uniapp开发框架 兼容各平台小程序 DataFlux RUM 数据采集SDK\n通过引入sdk文件，监控小程序性能指标，错误log，以及资源请求情况数据，上报到DataFlux 平台datakit\n\n## 使用方法\n### 在uniapp项目入口文件`main.js`文件头部位置以如下方式引入代码\n### npm 引入(可参考uniapp官方[npm引入方式](https://uniapp.dcloud.net.cn/frame?id=npm%e6%94%af%e6%8c%81))\n```javascript\n//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE\nconst { datafluxRum } = require('@cloudcare/rum-uniapp')\n// 初始化 Rum\ndatafluxRum.init({\n\tdatakitOrigin: 'https://datakit.xxx.com/',// 必填，Datakit域名地址 需要在微信小程序管理后台加上域名白名单\n\tapplicationId: 'appid_xxxxxxx', // 必填，dataflux 平台生成的应用ID\n\tenv: 'testing', // 选填，小程序的环境\n\tversion: '1.0.0', // 选填，小程序版本\n\ttrackInteractions: true, // 用户行为数据\n})\n//#endif\n```\n### CDN 下载文件本地方式引入([下载地址](https://static.dataflux.cn/miniapp-sdk/v1/dataflux-rum-uniapp.js))\n\n```javascript\n//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE\nconst { datafluxRum } = require('@cloudcare/rum-uniapp')\n// 初始化 Rum\ndatafluxRum.init({\n\tdatakitOrigin: 'https://datakit.xxx.com/',// 必填，Datakit域名地址 需要在微信小程序管理后台加上域名白名单\n\tapplicationId: 'appid_xxxxxxx', // 必填，dataflux 平台生成的应用ID\n\tenv: 'testing', // 选填，小程序的环境\n\tversion: '1.0.0', // 选填，小程序版本\n\ttrackInteractions: true, // 用户行为数据\n})\n//#endif\n```\n\n## 配置\n\n### 初始化参数\n\n| 参数                                            | 类型    | 是否必须 | 默认值    | 描述                                                                                                                                                                                                                                    |\n| ----------------------------------------------- | ------- | -------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `applicationId`                                 | String  | 是       |           | 从 dataflux 创建的应用 ID                                                                                                                                                                                                               |\n| `datakitOrigin`                                 | String  | 是       |           | datakit 数据上报 Origin;`注意：需要在小程序管理后台加上request白名单`                                                                                                                                                                   |\n| `env`                                           | String  | 否       |           | 小程序 应用当前环境， 如 prod：线上环境；gray：灰度环境；pre：预发布环境 common：日常环境；local：本地环境；                                                                                                                            |\n| `version`                                       | String  | 否       |           | 小程序 应用的版本号                                                                                                                                                                                                                     |\n| `sampleRate`                                    | Number  | 否       | `100`     | 指标数据收集百分比: `100`表示全收集，`0`表示不收集                                                                                                                                                                                      |\n| `traceType` $\\color{#FF0000}{新增}$             | Enum    | 否       | `ddtrace` | 与 APM 采集工具连接的请求header类型，目前兼容的类型包括：`ddtrace`、`zipkin`、`skywalking_v3`、`jaeger`、`zipkin_single_header`、`w3c_traceparent`。*注： opentelemetry 支持 `zipkin_single_header`,`w3c_traceparent`,`zipkin`三种类型* |\n| `traceId128Bit` $\\color{#FF0000}{新增}$         | Boolean | 否       | `false`   | 是否以128位的方式生成 `traceID`，与`traceType` 对应，目前支持类型 `zipkin`、`jaeger`                                                                                                                                                    |\n| `allowedTracingOrigins` $\\color{#FF0000}{新增}$ | Array   | 否       | `[]`      | 允许注入 `trace` 采集器所需header头部的所有请求列表。可以是请求的origin，也可以是是正则，origin: `协议（包括：//），域名（或IP地址）[和端口号]` 例如：`[\"https://api.example.com\", /https:\\/\\/.*\\.my-api-domain\\.com/]`                 |\n| `trackInteractions`                             | Boolean | 否       | `false`   | 是否开启用户行为采集                                                                                                                                                                                                                    |\n\n## 注意事项\n\n1. `datakitOrigin` 所对应的datakit域名必须在小程序管理后台加上request白名单\n2. 目前各平台小程序在性能数据api暴露这块，并没有完善统一，所以导致一些性能数据并不能完善收集，比如`小程序启动`、`小程序包下载`、`脚本注入` 等一些数据除微信平台外，都有可能会存在缺失的情况。\n3. 目前各平台小程序请求资源API`uni.request`、`uni.downloadFile`返回数据中`profile`字段目前只有微信小程序ios系统不支持返回，所以会导致收集的资源信息中和timing相关的数据收集不全。目前暂无解决方案，[request](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html), [downloadFile](https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html) ;[API支持情况](https://developers.weixin.qq.com/community/develop/doc/000ecaa8b580c80601cac8e6f56000?highLine=%2520request%2520profile)\n3. `trackInteractions` 用户行为采集开启后，因为微信小程序的限制，无法采集到控件的内容和结构数据，所以在小程序 SDK 里面我们采取的是声明式编程，通过在 模版 里面设置 data-name 属性，可以给 交互元素 添加名称，方便后续统计是定位操作记录， 例如：\n```js\n \u003cbutton bindtap=\"bindSetData\" data-name=\"setData\"\u003esetData\u003c/button\u003e\n```\n\n    ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguancecloud%2Fdatakit-miniprogram-uniapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguancecloud%2Fdatakit-miniprogram-uniapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguancecloud%2Fdatakit-miniprogram-uniapp/lists"}