# imeik-report

> ``` npm run build ```

Latest version **1.0.0** (published 2026-10-21) · 0 weekly downloads

## Install

```sh
npm install imeik-report
pnpm add imeik-report
yarn add imeik-report
bun add imeik-report
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-10-21 |
| First published | 2023-10-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | imeik-npm |

## Links

- npm: https://www.npmjs.com/package/imeik-report
- npm.io page: https://npm.io/package/imeik-report

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^1.5.1
- [core-js](https://npm.io/package/core-js.md) ^3.6.5

## Recent versions

- 1.0.0 (latest) — 2026-10-21
- 0.2.12 — 2026-01-08
- 0.2.11 — 2025-11-13
- 0.2.10 — 2025-11-12
- 0.2.9 — 2025-11-12
- 0.2.8 — 2025-11-11
- 0.2.7 — 2025-09-12
- 0.2.6 — 2025-09-09
- 0.2.5 — 2025-08-21
- 0.2.4 — 2025-05-20
- 0.2.3 — 2025-05-19
- 0.2.2 — 2025-05-16
- 0.2.1 — 2025-05-12
- 0.2.0 — 2025-05-12
- 0.1.6 — 2025-04-22
- … 25 more at https://npm.io/package/imeik-report/versions

## README

# imeik-report（通用埋点上报前端项目）
## 主要功能：实现登录埋点上报和页面访问埋点上报
## 打包方式：
```
npm run build
```

## 版本更新
```
0.0.3 实现登录埋点上报和页面访问埋点上报
0.0.4 上报参数：pageUrl、pageName、uuid
0.0.5 README.md
0.0.6 运行环境：isTest
0.0.7 baseUrl
0.0.8 修改platSource
0.0.9 pc/h5上报去掉router引入
0.0.10 platSource增加14
0.0.11 小程序上报参数：pageContent
0.0.12 重复上报多次bug
0.0.13 修复mixin重复上报
0.0.14 回退到0.0.12版本
0.0.15 小程序上报参数：openId、unionId
0.0.16 上报参数改为驼峰命名
0.0.17 openId
0.0.18 增加渠道code统计
0.0.19 增加按钮点击通用上报
0.0.20 小程序上报userId兼容
0.1.0 页面上报路由pageUrl增加query参数
0.1.1
0.1.2 解决进入页面上报多次问题
0.1.3 onLaunch执行完毕后再执行onShow上报
0.1.6 小程序登录上报增加渠道channel参数
0.2.0 安卓机型企微打开小程序空白屏问题修复
0.2.2 小程序自定义上报
0.2.3 小程序上报参数pageSession
0.2.4 小程序上报参数pageContent为string类型
0.2.5 PC上报增加扩展字段extra_data
0.2.6 小程序自定义上报增加pageSession
0.2.7 小程序自定义上报去掉pageSession
0.2.8 pc增加自定义上报
0.2.9 channel是否在上报一次后清空由isClearChannel参数判断
0.2.10 小程序channel是否在上报一次后清空由isClearChannel参数判断
0.2.11 pc增加appId、openId、unionId
0.2.12 小程序未登录用户页面上报增加支持传openId
1.0.0 兼容 Vue 3 与非 Vue 项目（去除 Vuex 依赖；新增框架无关 init / reportPageView；install / ReportParams 仅做参数初始化，Vue 项目需手动 mixin 获得 PV 自动上报，非 Vue 项目用 init + reportPageView 手动上报）；新增 initNonVue（非 Vue 项目专用初始化，内置自动 PV 默认开启），init 新增 autoPageView 开关；token / account / userId 缺失时自动生成 UUID 兜底；vue.config.js 增加 OSS CDN 上传（--cdn 开关）
```

## install
```
npm install imeik-report
```

## pc/h5项目接入方法
SDK 同时兼容 Vue 2 与 Vue 3。`Vue.use`（Vue 2）或 `app.use`（Vue 3）仅做参数初始化，**不会自动注入 PV 上报 mixin**（与老版本行为一致，便于老项目零改动升级）。如需页面 PV 自动上报，请手动注入：`Vue.mixin(ImeikReport.reportMixin)`（Vue 3 用 `app.mixin(ImeikReport.reportMixin)`）。

main.js（Vue 2）
```
// 上报
import ImeikReport from 'imeik-report/dist/ImeikReport/ImeikReport.umd'
Vue.use(ImeikReport, {
  isTest: '1', //  运行环境 1: test, 0: 生产
  token: sessionStorage.getItem(store.state.cookieKey) // 业务中获取token方法
})
// 定义全局对象
Vue.prototype.$ImeikReport = ImeikReport
```

main.js（Vue 3）
```
import ImeikReport from 'imeik-report/dist/ImeikReport/ImeikReport.umd'
const app = createApp(App)
app.use(ImeikReport, {
  isTest: '1',
  token: ... // 业务中获取 token 方法
})
app.config.globalProperties.$ImeikReport = ImeikReport
app.mount('#app')
```

> 兼容旧写法：`Vue.use(ImeikReport.ReportParams, {...})` 仅做参数初始化，需自行 `Vue.mixin(ImeikReport.reportMixin)`（Vue 3 用 `app.mixin`）。
> 若宿主不是 Vue Router 应用，PV 不会自动上报，可改用下方非 Vue 项目的 reportPageView 手动上报。

获取用户信息页面
```
// 初始化上报需要的参数
this.initReportParams(res.data)
initReportParams(info) {
  const visitId = Math.random().toString(16).substring(2) + new Date().getTime()
  const uuid = this.createUUID()
  localStorage.setItem('plat_source', '') // (前端自己定义，同步后端)
  localStorage.setItem('visitId', visitId)
  localStorage.setItem('uuid', uuid)
  localStorage.setItem('userId', info.accountId || '')
  localStorage.setItem('phone', info.telephone || '')
},
createUUID () {
  let result = []
  let hexDigits = '0123456789abcdef'
  for (let i = 0; i < 36; i++) {
    result[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  }
  // bits 12-15 of the time_hi_and_version field to 0010
  result[14] = '4'
  // bits 6-7 of the clock_seq_hi_and_reserved to 01
  result[19] = hexDigits.substr((result[19] & 0x3) | 0x8, 1)
  result[8] = result[13] = result[18] = result[23] = '-'
  return result.join('')
}
```
登录页面-登录成功方法后
```
// 本地存储account(登录账号)和 platSource(产品线)用于登录上报
localStorage.setItem('account', this.loginForm.username)
localStorage.setItem('platSource', '') // (前端自己定义，同步后端)
// 登录上报
this.$ImeikReport.reportLogin()
```

## 非 Vue / 通用项目接入方法
SDK 的核心上报能力（登录 / 点击 / 自定义 / 页面 PV）均为框架无关实现，原生 JS、React、Angular、jQuery 等任何项目都能接入。axios 已随 SDK 内置，无需额外引入，也无需 Vue / Vuex。

1) 引入
```
npm install imeik-report
// 或 script 标签引入 dist/ImeikReport/ImeikReport.umd.min.js（全局 ImeikReport，axios 已内置，无需额外引入）
```
2) 初始化（框架无关，不依赖 Vue）
```
import ImeikReport from 'imeik-report/dist/ImeikReport/ImeikReport.umd'
// 非 Vue 项目推荐用 initNonVue：内置自动 PV 默认开启，pv 自动覆盖首屏 / hashchange / pushState / popstate
ImeikReport.initNonVue({ isTest: '1', platSource: '30' })
// 也可用 init({ autoPageView: true }) 手动开启内置自动 PV（默认 false）
```
3) 业务上报
```
ImeikReport.reportClick({ element_name: '提交按钮' })
ImeikReport.reportCustom({ eventType: 3, event_code: 'pay', event_name: '支付完成' })
ImeikReport.reportLogin()

// 页面 PV 曝光：initNonVue 已内置自动上报，一般无需手动调用；
// 如需自定义 pageName 或覆盖 replaceState 等未被内置监听的跳转，可手动调用（注意别与内置重复造成双报）
ImeikReport.reportPageView({ pageUrl: location.pathname, pageName: '首页' })
// 离开页面时（如需统计停留时长）传 type: 'hide'
ImeikReport.reportPageView({ type: 'hide', pageUrl: location.pathname, pageName: '首页' })
```
> 说明：Vue 项目需手动 `Vue.mixin(ImeikReport.reportMixin)`（Vue 3 用 `app.mixin`）实现 PV 自动上报，**请勿使用 `initNonVue`**（会与 mixin 双报）；非 Vue 项目用 `initNonVue`（或 `init({ autoPageView: true })`）由 SDK 内置自动上报 PV，两者底层走同一套上报逻辑。

## 小程序项目接入方法
main.js
```
// 上报
import ImeikReport from 'imeik-report/dist/ImeikWechatReport/ImeikWechatReport.umd'
Vue.use(ImeikReport.ReportParams, {
  isTest: '1', //  运行环境 1: test, 0: 生产
  token: uni.getStorageSync('userToken')
})
Vue.mixin(ImeikReport.reportWechatMixin)
// 定义全局对象
Vue.prototype.$ImeikReport = ImeikReport
```
App.vue
```
全局变量
globalData: {
  visitId: '',
  phone: '',
  platSource: '' // 产品线/产品端(前端自己定义，同步后端)
}
// 初始化上报需要的参数
initReportParams() {
  this.globalData.visitId = Math.random().toString(16).substring(2) + new Date().getTime()
  this.globalData.uuid = this.createUUID()
  this.globalData.phone = this.globalData.userInfo.account
}
createUUID () {
  let result = []
  let hexDigits = '0123456789abcdef'
  for (let i = 0; i < 36; i++) {
    result[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  }
  // bits 12-15 of the time_hi_and_version field to 0010
  result[14] = '4'
  // bits 6-7 of the clock_seq_hi_and_reserved to 01
  result[19] = hexDigits.substr((result[19] & 0x3) | 0x8, 1)
  result[8] = result[13] = result[18] = result[23] = '-'
  return result.join('')
}
```
登录成功获取用户信息后
```
// 登录上报
this.$ImeikReport.reportWechatLogin()
```

## 本地调试方法
在通用埋点项目运行npm link
在业务项目中运行npm link npm包名(imeik-report)
在业务项目中修改引入方式 import ImeikReport from '../node_modules/imeik-report/dist/ImeikReport/ImeikReport.umd.js'
此时，通用埋点的改动可同步在业务系统中显示

## platSource
1-全轩运营平台/全轩管理后台
2-官网H5
3-官网PC
4-爱美客服务小程序
5-商学院PC
7-电子签系统PC
8-BI经营驾驶舱小程序
9-iclub小程序
10-iclub PC
11-C创
12-BI大屏PC
13-BI数据驾驶舱小程序
14-BI管理后台
15-物资管理系统PC端
16-物资管理系统H5端
17-科研平台管理系统PC端
18-科研项目pc端
19-科研项目小程序
20-社区小程序
21-爱美客资源管理系统PC端
22-爱美客伙伴小程序
23-会议管理系统
24-会议管理系统移动端
25-内容中心
27-标签中心
28-规则中心
29-申请中心PC端
30-申请中心H5端
31-内容广场

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