
Security News
White House Authorizes Private Companies to Conduct Offensive Cyber Operations
A new federal program will let vetted U.S. cybersecurity firms help investigate and disrupt foreign cybercrime groups under government direction.
nw-log-distribution
Advanced tools
分流打点组件
2.32.15版本SDK新增ENV.GAME环境和APP_KEY.GAME,用于游戏场景的打点上报。2.32.2版本SDK增加了getClientHubbleDeviceId和getClientCustomUDID同步方法,用于获取设备ID。2.25.2版本SDK在attributes参数增加了一个method属性,值为get|post,指定打点请求通过GET还是POST方式发送,不传默认为POST方式。2.20.0版本SDK增加了客户端7.1.0以上版本自动读取UA中的hubble deviceId,附带在attributes中上报的功能。2.18.0版本SDK支持在打点时指定useAppTrack,用于在某些特定的打点选择是否通过app上传,用法见下面示例。2.16.0版本SDK支持在打点时指定activityId,用于在某些特定的打点上附加指定activityId,用法见下面示例。2.14.0版本SDK实例化增加一个参数activityId,用于上报打点的attributes中附加指定activityId,使得活动数据报表系统能够实现自动收集。$ yarn add nw-log-distribution
import {ENV,APP_KEY,HubLog as Log} from 'nw-log-distribution';
const log = new Log({
userId: '',
key: APP_KEY.PC | APP_KEY.H5 | APP_KEY.GAME, // 根据当前开发的环境选择正确的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;npm run publish。本地开发验证打点时,k需要指定为lofter,同时浏览器的userAgent需要设置为符合对应的平台特征,否则在对应的平台会找不到打点记录,因为st平台会根据打点请求的userAgent来判断打点请求所对应的平台是Web、H5还是其他。
本地开发验证打点时,v注意指定准确的统计点所属版本号,如果不指定统计点版本号,st平台会认为统计点属于最新版的版本号,可能会出现版本不匹配的问题。
HubLog
createMaxWaitingCallback
Object打点的额外参数
HubLog
Kind: global class
| 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 |
打点到哈勃 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 | 打点额外参数 |
打点到打点验证平台 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 | 打点额外参数 |
标识真实用户,建议用户登录完成时调用
Kind: instance method of HubLog
| Param |
|---|
| userId |
切到匿名用户
Kind: instance method of HubLog
根据对象初始化配置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 | 打点额外参数 |
通过哈勃sdk获取设备ID,如果在端外或者获取失败,会生成随机的uuid返回
Kind: instance method of HubLog
Returns: Promise
客户端7.1.0版本后在UA中增加了客户端hubble SDK生成的deviceId(非客户端自行生成的customUDID) 此方法通过正则从UA自动拿取该deviceId,同步调用即可 如果非客户端或者正则匹配失败,会自行生成一个本地的deviceId并储存在localstorage
Kind: instance method of HubLog
Returns: string
客户端7.1.0版本后在UA中增加了客户端customUDID 此方法通过正则从UA自动拿取该customUDID,同步调用即可 如果非客户端或者正则匹配失败,会自行生成一个本地的deviceId并储存在localstorage
Kind: instance method of HubLog
Returns: string
enumEnum env values.
Kind: global enum
Read only: true
Properties
| Name | Type | Default |
|---|---|---|
| ST | string | "ST" |
| HB | string | "HB" |
| GAME | string | "GAME" |
enumEnum env values.
Kind: global enum
Read only: true
Properties
| Name | Type | Default |
|---|---|---|
| PC | string | "MA-BFD7-963BF6846668" |
| H5 | string | "MA-B4E8-3BEB9540671E" |
| GAME | string | "MA-BF04-E6819DFA8632" |
createMaxWaitingCallback
Kind: global function
| Param | Type |
|---|---|
| options | LogOptions |
Object打点的额外参数
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [LogOptions.callback] | function | 上报完成后的回调 | |
| [LogOptions.maxWaitingTime] | number | 200 | 回调最多等待时间,单位毫秒,默认200ms |
| [LogOptions.reqHb] | boolean | 使用设置是否调用 哈勃 |
FAQs
We found that nw-log-distribution demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A new federal program will let vetted U.S. cybersecurity firms help investigate and disrupt foreign cybercrime groups under government direction.

Research
/Security News
The campaign amassed more than 75,000 installs by targeting Russian-speaking users seeking access to blocked services.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.