collect.ts
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 17:05:34
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-15 09:35:50
* @FilePath: \glsx-tracker-javascript\src\modules\collect.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import type { DefaultInfoDescriptor, EventType ,DeviceInfoDescriptor} from '../types/collect'
import utils from '../utils/helper'
class Collect {
/**
*
* 开始收集
* @param target 目标
* @param tagName 标签
* @param customProps 属性
* @param callback 回调函数
*/
start() {}
/**
* 采集用户信息数据
* @param info 接收的数据
*/
getUserData() {}
/**
* 采集设备信息数据
* @param info 接收的数据
*/
getDeviceData():DeviceInfoDescriptor {
return {
$plateform: navigator.platform,
$appName: navigator.appName,
$userAgent: navigator.userAgent,
$appVersion: navigator.appVersion
}
}
/**
* 采集默认信息数据
* @param info 接收的数据
*/
getDefaultData(): DefaultInfoDescriptor {
return {
$page_title: document.title,
$page_url: location.href,
$page_path: location.pathname
}
}
/**
* 收集点击事件数据
* 判断需要监听哪些dom元素
*/
getClickEvent<T extends object>(para: T) {
this.send(para, 'clickEvent')
}
/**
* 收集浏览事件数据
*/
getViewEvent<T extends object>(para: T) {
this.send(para, 'viewEvent')
}
/**
* 收集停留事件数据
*/
getStayEvent<T extends object>(para: T) {
this.send(para, 'stayEvent')
}
/**
* 发送埋点数据
*/
send<T>(para: T, type: EventType) {
para = Object.assign(this.getDefaultData(), para)
const reportInfo = {
properties: para,
event: type,
time: utils.dateFormat(Date.now())
}
console.log(reportInfo)
}
}
export default new Collect()