# @fubei/mina-sls

> 小程序端日志上报工具

Latest version **0.0.18** (published 2025-04-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @fubei/mina-sls
pnpm add @fubei/mina-sls
yarn add @fubei/mina-sls
bun add @fubei/mina-sls
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.18 |
| Published | 2025-04-15 |
| First published | 2022-10-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 85.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 郭晓婷 |
| Maintainers | fubei |
| Keywords | tracker |

## Links

- npm: https://www.npmjs.com/package/@fubei/mina-sls
- npm.io page: https://npm.io/package/@fubei/mina-sls

## Recent versions

- 0.0.18 (latest) — 2025-04-15
- 0.0.17 — 2025-04-08
- 0.0.16 — 2022-11-26
- 0.0.15 — 2022-11-26
- 0.0.14 — 2022-11-26
- 0.0.13 — 2022-11-26
- 0.0.12 — 2022-11-24
- 0.0.10 — 2022-10-26
- 0.0.9 — 2022-10-26
- 0.0.8 — 2022-10-26
- 0.0.7 — 2022-10-26
- 0.0.6 — 2022-10-26
- 0.0.5 — 2022-10-26
- 0.0.4 — 2022-10-26
- 0.0.3 — 2022-10-26
- … 2 more at https://npm.io/package/@fubei/mina-sls/versions

## README

# FsSlsTracker 阿里云日志统计工具

## 使用

### 安装

```bash
npm install @fubei/mina-sls --save
```

### demo

```javascript
import FsSlsTracker from '@fubei/mina-sls'
// 固定阿里云日志参数
const OPTS = {
  host: '', // 所在地域的服务入口。例如cn-hangzhou.log.aliyuncs.com
  project: '', // Project名称。
  logstore: '', // Logstore名称。
  time: 10, // 发送日志的时间间隔，默认是10秒。
  count: 10 // 发送日志的数量大小，默认是10条。
}
// 日志统计公共参数
let param = {
  userName: '',
  userId: '',
  userAgent: ''
}
const slsTracker= new FsSlsTracker(OPTS, param)
// 测试事件点击
slsTracker.trackerClick('npm包测试', 'test_log')
// 测试打开新页面
slsTracker.trackerOpenPage('npm包测试打开新页面', 'test_open_page')
// 测试event
slsTracker.trackerEvent('npm包测试evet', 'test_event')
// 追踪记录原始日志，用于统计请求参数，请求返回等日志信息
slsTracker.trackerLog({accessToken: '1111'})

/**
 * @function 获取自定义上报对象
 */
 function getCustomReport () {
  let param = {
    userAgent: '测试数据',
    storeId: localStorage.getItem('storeId')
  }
  return param
}
setTimeout(() => {
  localStorage.setItem('storeId', '123456')
}, 5000);
// 也可以动态传方法，更新公共参数
// const xlsxLog = new FsSlsTracker(OPTS, {
//   data() { // 非必填
//     return {
//       AppId: `fs-web-project`,
//       ...getCustomReport()
//     }
//   }
// })
```

## 配置项

- 阿里云日志基础字段
  - host， 所在地域的服务入口。例如cn-hangzhou.log.aliyuncs.com
  - project，Project名称
  - logstore	Logstore名称。
  - time	发送日志的时间间隔，默认是10秒。
  - count 发送日志的数量大小，默认是10条。
- 公共参数，传到阿里云的公共参数，例如userName，userId等，

- 四个统计事件参数

|  参数名称  | 类型 | 是否必填  |  描述  |  默认值 |
|  ---- | ---- | ----  | ----  | ---- |
| category  | string| 必填 | 类别， 页面名称标识或功能标识（统一中文命名）  | |
| seed  | string | 必填 |  埋点Id，埋点的英文ID，由需求提交者定义，例如 运营广告位-点击 promotion_ops_click | |
| ext4  | string | 选填 |  其他json字符串字段  |  |

## 方法

---
_Source: https://npm.io/package/@fubei/mina-sls · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
