2.32.2 • Published 1 month ago

nw-log-distribution v2.32.2

Weekly downloads
180
License
-
Repository
-
Last release
1 month ago

nw-log-distribution

分流打点组件

重要更新日志

  • 2024-04-02 2.32.2版本SDK增加了getClientHubbleDeviceIdgetClientCustomUDID同步方法,用于获取设备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-distribution

example

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();

开发

  1. 如果没有修改DATracker.sync._yuedu1.6.12.4.js上报SDK,直接执行第4步;
  2. 如果有修改DATracker.sync._yuedu1.6.12.4.js上报SDK,则先执行npm run upload,将上报SDK的代码压缩并上传;
  3. 压缩上传后的地址会自动写入剪切板,将该地址复制到/src/index.js_initHB方法中;
  4. 执行npm run build,打包esiife两种格式的Log SDK;
  5. Git提交清晰完整的commit msg,然后在根目录执行npm run publish

ST平台验证注意事项

userAgent

本地开发验证打点时,k需要指定为lofter,同时浏览器的userAgent需要设置为符合对应的平台特征,否则在对应的平台会找不到打点记录,因为st平台会根据打点请求的userAgent来判断打点请求所对应的平台是WebH5还是其他。

版本号

本地开发验证打点时,v注意指定准确的统计点所属版本号,如果不指定统计点版本号,st平台会认为统计点属于最新版的版本号,可能会出现版本不匹配的问题。

API

Classes

Functions

Typedefs

HubLog

HubLog

Kind: global class

new HubLog(props)

ParamTypeDescription
propsObject
props.userIdstring用户id
props.keystringhubble产品id
props.hbInitOptionsobjecthubble init方法需要的options参数,如不传默认值{truncateLength: 255,persistence: "localStorage",cross_subdomain_cookie: true}
props.kstringST平台产品key
props.envstring数据上报平台
props.activityIdstring活动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

ParamTypeDescription
eventIdstring
attributesobject
optionsLogOptions打点额外参数

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

ParamTypeDescription
eventIdstring 打点事件id
attributesobject 上报属性对象
optionsLogOptions打点额外参数

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

ParamTypeDescription
eventIdstring 打点事件id
attributesobject 上报属性对象
optionsLogOptions打点额外参数

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

NameTypeDefault
STstring"ST"
HBstring"HB"

APP_KEY : enum

Enum env values.

Kind: global enum
Read only: true
Properties

NameTypeDefault
PCstring"MA-BFD7-963BF6846668"
H5string"MA-B4E8-3BEB9540671E"

createMaxWaitingCallback(options)

createMaxWaitingCallback

Kind: global function

ParamType
optionsLogOptions

LogOptions : Object

打点的额外参数

Kind: global typedef
Properties

NameTypeDefaultDescription
LogOptions.callbackfunction上报完成后的回调
LogOptions.maxWaitingTimenumber200回调最多等待时间,单位毫秒,默认200ms
LogOptions.reqHbboolean使用设置是否调用 哈勃
2.32.0

1 month ago

2.32.2

1 month ago

2.31.1

3 months ago

2.31.0

7 months ago

2.30.1

8 months ago

2.30.0

9 months ago

2.29.4

1 year ago

2.29.3

1 year ago

2.29.5

1 year ago

2.29.2

1 year ago

2.29.0

1 year ago

2.27.0

2 years ago

2.28.0

2 years ago

2.26.2

2 years ago

2.26.1

2 years ago

2.25.0

2 years ago

2.23.2

2 years ago

2.21.4

2 years ago

2.21.3

2 years ago

2.25.1

2 years ago

2.22.0

2 years ago

2.24.1

2 years ago

2.26.0

2 years ago

2.23.0

2 years ago

2.20.0

2 years ago

2.20.1

2 years ago

2.21.0

2 years ago

2.21.2

2 years ago

2.21.1

2 years ago

2.19.1

2 years ago

2.19.0

2 years ago

2.18.5

2 years ago

2.18.3

2 years ago

2.18.4

2 years ago

2.18.1

2 years ago

2.18.2

2 years ago

2.18.0

2 years ago

2.17.2

2 years ago

2.17.1

3 years ago

2.17.0

3 years ago

2.16.1

3 years ago

2.16.0

3 years ago

2.15.1

3 years ago

2.15.0

3 years ago

2.11.0

3 years ago

2.13.0

3 years ago

2.10.1

3 years ago

2.12.0

3 years ago

2.10.0

3 years ago

2.14.0

3 years ago

2.9.0

3 years ago

2.8.0

3 years ago

2.7.12

3 years ago

2.7.11

3 years ago

2.7.10

3 years ago

2.7.8

3 years ago

2.7.7

3 years ago

2.7.6

3 years ago

2.7.4

3 years ago

2.7.5

3 years ago

2.7.3

3 years ago

2.7.0

3 years ago

2.7.2

3 years ago

2.7.1

3 years ago

2.4.1

3 years ago

2.4.3

3 years ago

2.4.2

3 years ago

2.4.0

3 years ago

2.6.0

3 years ago

2.3.0

4 years ago

2.2.3

4 years ago

1.46.1

4 years ago

1.45.6

4 years ago

1.45.5

4 years ago

1.45.4

4 years ago

1.45.3

4 years ago

1.45.2

4 years ago

1.42.2

4 years ago

1.42.0

4 years ago

1.41.0

4 years ago

1.42.1

4 years ago

1.40.0

4 years ago

1.39.0

4 years ago

1.35.0

4 years ago

1.34.0

4 years ago

1.33.0

4 years ago

1.28.0

4 years ago

1.26.11

5 years ago

1.26.10

5 years ago

1.26.9

5 years ago

1.26.8

5 years ago

1.26.7

5 years ago

1.26.6

5 years ago