New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hz-tracker

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hz-tracker

海致通用埋点工具

latest
npmnpm
Version
1.2.1
Version published
Maintainers
5
Created
Source

背景

海致通用埋点组件,支持dom点击埋点、pv/uv上报、曝光时长、批量上报、无网络延时上报

项目说明

|.
├── src
    ├── index.js  // 埋点组件主入口
    ├── utils.js    // 埋点组件工具函数

埋点组件使用

简单使用

import hzTracker from 'hz-tracker'
const $tracker = new hzTracker({
  maxLogNum: 1, // 存储日志的最大数量,达到最大数量才会上报
  requestUrl: 'localhost:3000/test' // 埋点请求后端接口
})
onClickBtn() {
  $tracker.sendTracker('click', 'test_click_btn_tracker')
}

参数说明

  • 初始化配置项
参数名说明类型默认值
appid应用标识,用来区分埋点数据中的应用string'default'
maxLogNum批量上报的最大数量number5
enableTrackerKey是否开启约定拥有属性值为'tracker-key'的dom的点击事件自动上报booleanfalse
enableHeatMapTracker是否开启热力图自动上报booleanfalse
enableLoadTracker是否开启页面加载自动上报,适合多页面应用的pv/uv上报booleanfalse
enableHistoryTracker是否开启页面history变化pv/uv上报,适合单页面应用的history路由booleanfalse
enableHashTracker是否开启页面hash变化pv/uv上报,适合单页面应用的hash路由booleanfalse
enableExposureTimeTracker是否开启页面曝光时长上报booleanfalse
requestUrl埋点请求后端接口stringhttp://localhost:3000
requestMethod埋点请求方式,上报方案:POST为navigator.sendBeacon,GET为image。采用xmlHttpRequest兼容'POST','GET''POST'
extra用户自定义上传字段对象object{}
replaceFields自定义上报接口的字段名 {eventId:'eventId', uuid:'uuid', userId:'userId' }object{}
stayTime单位ms, 停留有效时长,用于优化曝光时长。只有时长大于stayTime才算做一次有效的曝光时长number2000
  • tracker.method()
参数名说明类型默认值
sendTracker手动触发上报函数,参数为分别为(事件类型,事件id,额外参数)function
setExtra设置埋点上报额外数据,用于更新配置中的extrafunction
setUserId设置用户id,可用于UV上报function
setOptions用于更新配置项(options)function

上报接口格式

  • POST
[{
    "appid": "default",
    "eventType": "click",
    "uuid": "26399770-8fd4-11ec-a1b0-97f4769244f2",
    "eventId": "front_home",
    "title": "atlas",
    "url": "http://localhost:8080/#/home/graph/analysis",
    "eventTime": 1645672242611,
    "browserType": "Chrome",
    "browserVersion": "98.0.4758.102",
    "browserEngine": "Blink",
    "osType": "OS X",
    "osVersion": "10.14.6",
    "language": "zh-CN"
},{
    "appid": "default",
    "eventType": "click",
    "uuid": "26399770-8fd4-11ec-a1b0-97f4769244f2",
    "eventId": "graph_analysis",
    "title": "atlas",
    "url": "http://localhost:8080/#/home/graph/analysis",
    "eventTime": 1645672242611,
    "browserType": "Chrome",
    "browserVersion": "98.0.4758.102",
    "browserEngine": "Blink",
    "osType": "OS X",
    "osVersion": "10.14.6",
    "language": "zh-CN"
}]
  • GET
let data = [{
    "appid": "default",
    "eventType": "click",
    "uuid": "26399770-8fd4-11ec-a1b0-97f4769244f2",
    "eventId": "front_home",
    "title": "atlas",
    "url": "http://localhost:8080/#/home/graph/analysis",
    "eventTime": 1645672242611,
    "browserType": "Chrome",
    "browserVersion": "98.0.4758.102",
    "browserEngine": "Blink",
    "osType": "OS X",
    "osVersion": "10.14.6",
    "language": "zh-CN"
},{
    "appid": "default",
    "eventType": "click",
    "uuid": "26399770-8fd4-11ec-a1b0-97f4769244f2",
    "eventId": "graph_analysis",
    "title": "atlas",
    "url": "http://localhost:8080/#/home/graph/analysis",
    "eventTime": 1645672242611,
    "browserType": "Chrome",
    "browserVersion": "98.0.4758.102",
    "browserEngine": "Blink",
    "osType": "OS X",
    "osVersion": "10.14.6",
    "language": "zh-CN"
}]
let reportData = encodeURIComponent(JSON.stringify(data));
axios(`localhost:3000/test?logs=${reportData}`)

Keywords

haizhi

FAQs

Package last updated on 29 Aug 2022

Did you know?

Socket

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.

Install

Related posts