# jz-policy-stat-helper

> 用户操作日志记录辅助工具(内部使用)

Latest version **0.1.0** (published 2020-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install jz-policy-stat-helper
pnpm add jz-policy-stat-helper
yarn add jz-policy-stat-helper
bun add jz-policy-stat-helper
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-09-21 |
| First published | 2020-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | Champkeh |
| Maintainers | champkeh |

## Links

- npm: https://www.npmjs.com/package/jz-policy-stat-helper
- npm.io page: https://npm.io/package/jz-policy-stat-helper

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.20.0
- [sn-js-utils](https://npm.io/package/sn-js-utils.md) ^0.1.5-rc.10

## Recent versions

- 0.1.0 (latest) — 2020-09-21
- 0.0.15 — 2020-09-08
- 0.0.14 — 2020-09-08
- 0.0.13 — 2020-09-02
- 0.0.12 — 2020-09-02
- 0.0.11 — 2020-09-02
- 0.0.10 — 2020-09-02
- 0.0.9 — 2020-09-02
- 0.0.8 — 2020-08-27
- 0.0.8-beta — 2020-08-27
- 0.0.8-alpha — 2020-08-27
- 0.0.7 — 2020-08-27
- 0.0.6 — 2020-08-27
- 0.0.5 — 2020-08-27
- 0.0.4 — 2020-08-27
- … 3 more at https://npm.io/package/jz-policy-stat-helper/versions

## README

# jz-policy-stat-helper

## 使用说明

### 记录与上报是在同一个页面
```js
import PolicyStat from "jz-policy-stat-helper";

// 第一步: 实例化，实例化时可预先填入已知的配置
const ps = new PolicyStat({project: '0001', version: '0.2.1'})

// 第二步: 配置要上报的数据
// 配置用户id、订单号、操作类型
ps.config({uid: 'xxx', orderNo: 'xxx', event: '下单'})

// 添加操作日志(内部会根据name参数进行去重)
ps.append({name: '勾选阅读须知', value: ''})
ps.append({name: '取消勾选阅读须知', value: ''})

// 第三步: 调用report上报
ps.report()
```

### 记录与上报不在同一个页面
```js
// 页面1
import PolicyStat from "jz-policy-stat-helper";

// 第一步: 实例化，实例化时可预先填入已知的配置
const ps = new PolicyStat({project: '0001', version: '0.2.1'})

// 第二步: 配置要上报的数据
// 配置用户id、订单号、操作类型
ps.config({uid: 'xxx'})

// 添加操作日志(内部会根据name参数进行去重)
ps.append({name: '勾选阅读须知', value: ''})
ps.append({name: '取消勾选阅读须知', value: ''})

// 第三步: 离开页面之前调用save命令保存本页面的操作
ps.save('storage_key_prefix', window.localStorage.setItem.bind(window.localStorage))
```

```js
// 页面2
import PolicyStat from "jz-policy-stat-helper";

// 第四步: 在下一个页面从缓存中读取
let ps = new PolicyStat()
ps = ps.restore('storage_key_prefix', window.localStorage.getItem.bind(window.localStorage))

// 可继续添加配置与操作记录
ps.config({orderNo: 'xxx', event: '下单'})
ps.append({name: '阅读保险条款', value: ''})

// 第五步: 调用report
ps.report()
```

## API

### 构造函数与config
这两处都可以填入配置信息，当前内部共有5个配置项:
1. project 项目标识
2. uid 用户id
3. orderNo 订单号
4. version 项目版本
5. event 操作类型

在调用`report`之前需要保证所有这5个配置都已填入。

### append
用来记录用户的操作日志

### save
如果涉及跨页面的话，可以使用`save`接口把当前页面已经记录的操作和配置保存到缓存

### restore
如果涉及跨页面的话，可以使用`restore`接口恢复前一个页面保存的配置

### report
调用该接口会自动把当前所记录的操作提交给服务器，并且会**清空**所有通过`append`记录的日志  
注意：通过`config`填入的配置**不会被删除**

---
_Source: https://npm.io/package/jz-policy-stat-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
