nw-log-distribution v2.32.6
nw-log-distribution
分流打点组件
重要更新日志
- 2024-04-02
2.32.2版本SDK增加了getClientHubbleDeviceId和getClientCustomUDID同步方法,用于获取设备ID。 - 2022-09-06
2.25.2版本SDK在attributes参数增加了一个method属性,值为get|post,指定打点请求通过GET还是POST方式发送,不传默认为POST方式。 - 2022-07-26
2.20.0版本SDK增加了客户端7.1.0以上版本自动读取UA中的hubble deviceId,附带在attributes中上报的功能。 - 2021-12-17
2.18.0版本SDK支持在打点时指定useAppTrack,用于在某些特定的打点选择是否通过app上传,用法见下面示例。 - 2021-10-21
2.16.0版本SDK支持在打点时指定activityId,用于在某些特定的打点上附加指定activityId,用法见下面示例。 - 2021-08-18
2.14.0版本SDK实例化增加一个参数activityId,用于上报打点的attributes中附加指定activityId,使得活动数据报表系统能够实现自动收集。 - 2020-08-05 本SDK改为全部向分流服务器打点,不再发送到哈勃,所以不再需要传入pointConfig
安装
$ yarn add nw-log-distributionexample
import {ENV,APP_KEY,HubLog as Log} from 'nw-log-distribution';
const log = new Log({
userId: '',
key: APP_KEY.PC | APP_KEY.H5, // 根据当前开发的环境选择正确的appkey
hbInitOptions: {
truncateLength: 255,
persistence: "localStorage",
cross_subdomain_cookie: true
},
k: 'lofter',
v: '6.15.0',
env: ENV.ST,
activityId: 'ac-log' // 非必须,SDK 初始化传入activityId,后续所有打点都会带上activityId
})
log.capture('h5-4-1', {
category: 'h5-4',
activityId: 'ac-log', // 非必须,只有本次打点带上activityId,同时会覆盖SDK初始化的activityId
useAppTrack: false // 非必须,针对某一打点设置是否通过app上传,不传默认为false,既默认使用js ajax上传,true则通过app上传
})
// 获取hubble sdk deviceId
const deviceId = log.getClientHubbleDeviceId();
// 获取customUDID,客户端协议header中会附带的设备id
const customUDID = log.getClientCustomUDID();开发
- 如果没有修改
DATracker.sync._yuedu1.6.12.4.js上报SDK,直接执行第4步; - 如果有修改
DATracker.sync._yuedu1.6.12.4.js上报SDK,则先执行npm run upload,将上报SDK的代码压缩并上传; - 压缩上传后的地址会自动写入剪切板,将该地址复制到
/src/index.js的_initHB方法中; - 执行
npm run build,打包es及iife两种格式的Log SDK; - Git提交清晰完整的commit msg,然后在根目录执行
npm run publish。
ST平台验证注意事项
userAgent
本地开发验证打点时,k需要指定为lofter,同时浏览器的userAgent需要设置为符合对应的平台特征,否则在对应的平台会找不到打点记录,因为st平台会根据打点请求的userAgent来判断打点请求所对应的平台是Web、H5还是其他。
版本号
本地开发验证打点时,v注意指定准确的统计点所属版本号,如果不指定统计点版本号,st平台会认为统计点属于最新版的版本号,可能会出现版本不匹配的问题。
API
Classes
Functions
Typedefs
HubLog
HubLog
Kind: global class
new HubLog(props)
| Param | Type | Description |
|---|---|---|
| props | Object | |
| props.userId | string | 用户id |
| props.key | string | hubble产品id |
| props.hbInitOptions | object | hubble init方法需要的options参数,如不传默认值{truncateLength: 255,persistence: "localStorage",cross_subdomain_cookie: true} |
| props.k | string | ST平台产品key |
| props.env | string | 数据上报平台 |
| props.activityId | string | 活动ID |
hubLog.logToHub(eventId, attributes, options)
打点到哈勃 eg: logToHub('event-Idxxxx', { attr1: 'attr1value', attr2: "Laptop Computer", attr3: "MacBook Pro", attr4: 123.45 });
Kind: instance method of HubLog
| Param | Type | Description |
|---|---|---|
| eventId | string | |
| attributes | object | |
| options | LogOptions | 打点额外参数 |
hubLog.logToSt(eventId, attributes, options)
打点到打点验证平台 eg:logToSt('event-Idxxxx', { attr1: 'attr1 value', attr2: "Laptop Computer", attr3: "MacBook Pro", attr4: 123.45 });
Kind: instance method of HubLog
| Param | Type | Description |
|---|---|---|
| eventId | string 打点事件id | |
| attributes | object 上报属性对象 | |
| options | LogOptions | 打点额外参数 |
hubLog.login(userId)
标识真实用户,建议用户登录完成时调用
Kind: instance method of HubLog
| Param |
|---|
| userId |
hubLog.logout()
切到匿名用户
Kind: instance method of HubLog
hubLog.capture(eventId, attributes, options)
根据对象初始化配置env属性打点到不同平台 eg:capture('event-Idxxxx', { attr1: 'attr1 value', attr2: "Laptop Computer", attr3: "MacBook Pro", attr4: 123.45 });
Kind: instance method of HubLog
| Param | Type | Description |
|---|---|---|
| eventId | string 打点事件id | |
| attributes | object 上报属性对象 | |
| options | LogOptions | 打点额外参数 |
hubLog.getDeviceId() ⇒
通过哈勃sdk获取设备ID,如果在端外或者获取失败,会生成随机的uuid返回
Kind: instance method of HubLog
Returns: Promise
hubLog.getClientHubbleDeviceId() ⇒
客户端7.1.0版本后在UA中增加了客户端hubble SDK生成的deviceId(非客户端自行生成的customUDID) 此方法通过正则从UA自动拿取该deviceId,同步调用即可 如果非客户端或者正则匹配失败,会自行生成一个本地的deviceId并储存在localstorage
Kind: instance method of HubLog
Returns: string
hubLog.getClientCustomUDID() ⇒
客户端7.1.0版本后在UA中增加了客户端customUDID 此方法通过正则从UA自动拿取该customUDID,同步调用即可 如果非客户端或者正则匹配失败,会自行生成一个本地的deviceId并储存在localstorage
Kind: instance method of HubLog
Returns: string
ENV : enum
Enum env values.
Kind: global enum
Read only: true
Properties
| Name | Type | Default |
|---|---|---|
| ST | string | "ST" |
| HB | string | "HB" |
APP_KEY : enum
Enum env values.
Kind: global enum
Read only: true
Properties
| Name | Type | Default |
|---|---|---|
| PC | string | "MA-BFD7-963BF6846668" |
| H5 | string | "MA-B4E8-3BEB9540671E" |
createMaxWaitingCallback(options)
createMaxWaitingCallback
Kind: global function
| Param | Type |
|---|---|
| options | LogOptions |
LogOptions : Object
打点的额外参数
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| LogOptions.callback | function | 上报完成后的回调 | |
| LogOptions.maxWaitingTime | number | 200 | 回调最多等待时间,单位毫秒,默认200ms |
| LogOptions.reqHb | boolean | 使用设置是否调用 哈勃 |
12 months ago
12 months ago
11 months ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago