auto-point 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AP/auto_point.js +1 -3
- package/README.md +31 -1
- package/package.json +1 -1
package/AP/auto_point.js
CHANGED
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
let point_item = this.#create_point_data_common_params()
|
|
124
124
|
point_item.point_type = "event"
|
|
125
125
|
point_item.point_sing = this.#POINT_SING
|
|
126
|
-
point_item.elment = element.target.
|
|
126
|
+
point_item.elment = element.target.localName
|
|
127
127
|
point_item.event_type = element.type
|
|
128
128
|
point_item.point_attr = element.target.getAttribute(this.#POINT_SING)
|
|
129
129
|
point_item.point_value = element.target.getAttribute(this.#POINT_SING)
|
|
@@ -199,8 +199,6 @@
|
|
|
199
199
|
navigator.sendBeacon(this.#SERVER, JSON.stringify(this.#POINT_LIST));
|
|
200
200
|
// 发送后清空埋点列表数据
|
|
201
201
|
this.#POINT_LIST = new Array()
|
|
202
|
-
} else {
|
|
203
|
-
console.log("无新埋点数据")
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
|
package/README.md
CHANGED
|
@@ -12,4 +12,34 @@ npm i -S auto-point
|
|
|
12
12
|
|
|
13
13
|
**Step 3**: 执行init()方法并传入配置参数,进行初始化。注意,AP应当在页面加载前进行初始化,否则将无法记录AP初始化前的浏览器动作。初始化完成后AP已经可以根据配置进行自动埋点动作收集和发送工作了。
|
|
14
14
|
|
|
15
|
-
**Step 4**: 初始化完成后可以根据需求,自行添加一些其他埋点信息,可以使用AP.add_point()方法添加一些自定义埋点数据,推荐使用object类型的数据,这些数据会与自动记录的埋点数据一起交给中间件处理之后发送给服务端。
|
|
15
|
+
**Step 4**: 初始化完成后可以根据需求,自行添加一些其他埋点信息,可以使用AP.add_point()方法添加一些自定义埋点数据,推荐使用object类型的数据,这些数据会与自动记录的埋点数据一起交给中间件处理之后发送给服务端。
|
|
16
|
+
|
|
17
|
+
**示例**
|
|
18
|
+
```javascript
|
|
19
|
+
// 假设AP已经初始化完成
|
|
20
|
+
// 添加一个自定义埋点
|
|
21
|
+
import AP from "auto-point";
|
|
22
|
+
const ap = new AP().init({
|
|
23
|
+
server: 'https://your-server.com/api/track', // 替换为真实的服务端地址
|
|
24
|
+
send_time: 5000, // 发送间隔:5秒
|
|
25
|
+
events: ['click'], // 监听的事件类型
|
|
26
|
+
point_sing: 'data-track-id' // 埋点标记属性名 如果元素上带有该属性名,AP会自动记录该属性值,否则不会记录
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 挂载中间件(在发送数据前执行)
|
|
30
|
+
ap.middleware(function() {
|
|
31
|
+
// 示例:添加用户信息到埋点数据
|
|
32
|
+
console.log('执行中间件:准备发送埋点数据', this.point_list);
|
|
33
|
+
// 注意:中间件函数中的 this 指向 AP 实例
|
|
34
|
+
// 可以在这里修改 this.#POINT_LIST 中的数据
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// 添加自定义埋点数据
|
|
38
|
+
ap.add_point({
|
|
39
|
+
type: 'custom',
|
|
40
|
+
data: {
|
|
41
|
+
name: 'custom_point',
|
|
42
|
+
value: 'custom_value'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
```
|
package/package.json
CHANGED