# client-analytics-sdk

> shein performence analytics report

Latest version **1.0.2** (published 2021-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install client-analytics-sdk
pnpm add client-analytics-sdk
yarn add client-analytics-sdk
bun add client-analytics-sdk
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-12-07 |
| First published | 2021-10-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 96.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lichengxiang |
| Keywords | analytics |

## Links

- npm: https://www.npmjs.com/package/client-analytics-sdk
- Repository: https://gitlab.sheincorp.cn/sheinWeb/client-analytics-sdk
- npm.io page: https://npm.io/package/client-analytics-sdk

## Dependencies (6)

- [core-js](https://npm.io/package/core-js.md) ^3.18.3
- [web-vitals](https://npm.io/package/web-vitals.md) ^2.1.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.15.4
- [@shein/apm-ua-parser](https://npm.io/package/@shein/apm-ua-parser.md) 0.0.3
- [@babel/runtime-corejs2](https://npm.io/package/@babel/runtime-corejs2.md) ^7.15.4
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.15.4

## Recent versions

- 1.0.2 (latest) — 2021-12-07
- 1.0.1 — 2021-11-25
- 1.0.4 — 2021-11-25
- 1.0.3 — 2021-10-25

## README

# CLIENT ANALYTICS SDK

ClientAnalytics 性能上报系统SDK

## 异步引入
将以下代码放入 html 的 head 里面，需要放在稍微靠前点的位置。 您在使用 ClientAnalytics.track() 时，只要保证写在引用的代码的下面就可以，不需要等 window.onload 后再执行
```javascript
<script>
  ;(function(para) {
    var w = window, p = para.sdk_url, d = document, n = para.name || 'ClientAnalytics', x = null, y = null, s = 'script';
    w['sheinClientAnalytic202110'] = n;
    w[n] = w[n] || function(a) {return function() {(w[n]._q = w[n]._q || []).push([a, arguments])}};
    var ifs = ['init', 'registerPage', 'track'];
    for (var i = 0; i < ifs.length; i++) {
      w[n][ifs[i]] = w[n].call(null, ifs[i]);
    }
    if (!w[n]._t) {
      x = d.createElement(s), y = d.getElementsByTagName(s)[0];
      x.async = 1;
      x.src = p;
      // w[n].para = para;
      y.parentNode.insertBefore(x, y);
    }
  })({
    sdk_url: '下载新版本的 clientAnalytics.min.js',
    name: 'ClientAnalytics', // 你希望使用的包的名字，默认 ClientAnalytics
  });

  ClientAnalytics.init({ reportUrl: 'https://xxxx/report', random: 1 })
  ClientAnalytics.track()
</script>
```

## ES模块引入
从 npm 获取 sdk, `npm install client-analytics-sdk`

```javascript
import ClientAnalytics from 'client-analytics-sdk'
ClientAnalytics.init({
  reportUrl: '数据接收地址',
  random: 1
  isSinglePage: true, // 单页面配置
});
//开启采集
ClientAnalytics.track()
```

## API
### init
SDK 的初始化方法，传入基本配置信息，**`必须`**要执行该方法，且`reportUrl`为必须传字段

- 入参参数

> reportUrl

**必须**. type: `String`

上报的地址，必须填入

> random

**必须**. type: `Number`

抽样采集的比例，值为 0～1 之间的一个数字

> sendType

**非必须**.  type: `String`

采集结果上报的形式，可选值：`ajax, image, beacon`，默认：ajax

> isSinglePage

**非必须**.  type: `Boolean`

告知SDK当前统计的应用是否是但页面应用程序

> log

**非必须**.  type: `Boolean`

是否将上报的信息打印在控制台，供调试

### registerPage
对于所有事件都需要添加的属性，可在初始化 SDK 后，调用 registerPage() 将属性注册为公共属性

```javascript
// 添加公共属性
ClientAnalytics.registerPage({
  deviceType: 'pc',   // 平台
  siteId: 'us',     // 站点
  language: 'en',   // 语言
  pageName: 'index',   // 页面名称
  brand: 'shein',      // 品牌
})
```

如果当你需要添加的公共字段是个动态参数，可以通过一个函数来动态返回值，定义的方法将会在上报的时候执行并赋值

```javascript
// 添加公共属性
ClientAnalytics.registerPage({
  isEmptyList: function() {
    return product.list.length > 0 ? 'non-empty' : 'empty'
  }
})
```

### track
关键方法。开启SDK统计上报的开关方法，如果不执行该方法，则不会进行任何收集操作。

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