@tmsfe/tms-core 0.0.50 → 0.0.53
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/package.json
CHANGED
package/src/report/formatV2.ts
CHANGED
|
@@ -56,7 +56,9 @@ function getBaseData(deviceData: IDeviceData): { arr: DataItem[], nextIndex: num
|
|
|
56
56
|
arr[24] = JSON.stringify(page?.options);
|
|
57
57
|
// 25: f25,当前页面深度
|
|
58
58
|
arr[25] = pageDepth.toString();
|
|
59
|
-
// 26
|
|
59
|
+
// 26: f26,一次小程序生命周期中的埋点统一标记
|
|
60
|
+
arr[26] = helper.getLifeReportKey();
|
|
61
|
+
// 27 ~ 30: 预留字段给后续扩展使用
|
|
60
62
|
// 31 ~ 40: 提供给开发自定义
|
|
61
63
|
// --------------------------字段列表--------------------------
|
|
62
64
|
return { arr, nextIndex: 31 };
|
package/src/report/helper.ts
CHANGED
|
@@ -102,6 +102,18 @@ function getNowString(): string {
|
|
|
102
102
|
return `${year}${month}${day}${hours}${minutes}${seconds}${ms}`;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
let lifeReportKey = '';
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 一次小程序生命周期中的埋点统一标记
|
|
109
|
+
*/
|
|
110
|
+
function getLifeReportKey(): string {
|
|
111
|
+
if (lifeReportKey === '') {
|
|
112
|
+
lifeReportKey = getNowString();
|
|
113
|
+
}
|
|
114
|
+
return lifeReportKey;
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
/**
|
|
106
118
|
* 获取当前页面信息
|
|
107
119
|
*/
|
|
@@ -228,6 +240,7 @@ export default {
|
|
|
228
240
|
getSystemInfoString,
|
|
229
241
|
convert2String,
|
|
230
242
|
getNowString,
|
|
243
|
+
getLifeReportKey,
|
|
231
244
|
getPageInfo,
|
|
232
245
|
getLaunchOptionsString,
|
|
233
246
|
getLaunchFrom,
|
|
@@ -17,9 +17,9 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string)
|
|
|
17
17
|
}
|
|
18
18
|
// eslint-disable-next-line no-param-reassign
|
|
19
19
|
methods[methodName] = function (...args: any[]): any {
|
|
20
|
-
const extra = clone.getEventExtra(args[0]) ; // 把触发事件附加数据也带上
|
|
21
20
|
// 执行原函数之后再发埋点
|
|
22
21
|
return helper.executeFunc(this, original, args, () => {
|
|
22
|
+
const extra = clone.getEventExtra(args[0]) ; // 把触发事件附加数据也带上
|
|
23
23
|
const data = clone.deepClone(this.data);
|
|
24
24
|
const eventName = `Component_${componentName}`;
|
|
25
25
|
helper.setLastBindEvent({ eventName, methodName, data, extra });
|
|
@@ -17,6 +17,18 @@ function reportData(...args: any[]): any {
|
|
|
17
17
|
reporter.report2(...args);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
let systemInfo: any = null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取wx.getSystemInfoSync()
|
|
24
|
+
*/
|
|
25
|
+
function getSystemInfo(): any {
|
|
26
|
+
if (systemInfo === null) {
|
|
27
|
+
systemInfo = wx.getSystemInfoSync();
|
|
28
|
+
}
|
|
29
|
+
return systemInfo;
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
let lastBindEvent: IBindEvent;
|
|
21
33
|
|
|
22
34
|
/**
|
|
@@ -70,9 +82,10 @@ function executeFunc(context: any, func: Function, args: any[], callback: Functi
|
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
export default {
|
|
73
|
-
reportData,
|
|
74
85
|
emptyFunc,
|
|
86
|
+
reportData,
|
|
75
87
|
executeFunc,
|
|
88
|
+
getSystemInfo,
|
|
76
89
|
getLastBindEvent,
|
|
77
90
|
setLastBindEvent,
|
|
78
91
|
};
|
package/src/report/proxy/page.ts
CHANGED
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
import helper from './helper';
|
|
8
8
|
import clone from './clone';
|
|
9
9
|
|
|
10
|
+
// 工具为页面根节点插入的触摸事件
|
|
11
|
+
const pageTouchEvent = 'onReportPageTouch';
|
|
10
12
|
// 必须上报的生命周期函数
|
|
11
|
-
const mustLifeMethods = ['onLoad', 'onShow', 'onReady', 'onHide', 'onUnload'];
|
|
13
|
+
const mustLifeMethods = ['onLoad', 'onShow', 'onReady', 'onHide', 'onUnload', pageTouchEvent];
|
|
12
14
|
// 可能会有的生命周期函数
|
|
13
15
|
const maybeLifeMethods = [
|
|
14
16
|
'onPullDownRefresh', 'onReachBottom', 'onShareAppMessage',
|
|
15
|
-
'onShareTimeline', 'onAddToFavorites',
|
|
17
|
+
'onShareTimeline', 'onAddToFavorites',
|
|
16
18
|
];
|
|
17
19
|
const lifeMethods = mustLifeMethods.concat(maybeLifeMethods);
|
|
18
20
|
|
|
@@ -27,8 +29,8 @@ function proxyLifeMethod(pageOptions: any, methodName: string): void {
|
|
|
27
29
|
// eslint-disable-next-line no-param-reassign
|
|
28
30
|
pageOptions[methodName] = function (...args: any[]): any {
|
|
29
31
|
// 生命周期函数先发埋点,避免次过程用户退出而丢失埋点
|
|
30
|
-
const options = clone.deepClone(args[0], 0, 1);
|
|
31
|
-
const extra = getPageLifeExtra(this, methodName);
|
|
32
|
+
const options = methodName === pageTouchEvent ? '' : clone.deepClone(args[0], 0, 1);
|
|
33
|
+
const extra = getPageLifeExtra(this, methodName, args);
|
|
32
34
|
helper.reportData(`Page_${methodName}`, options, extra);
|
|
33
35
|
|
|
34
36
|
// 执行原函数
|
|
@@ -37,7 +39,7 @@ function proxyLifeMethod(pageOptions: any, methodName: string): void {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// 获取生命周期函数上报时的附加信息
|
|
40
|
-
function getPageLifeExtra(page: any, methodName: string): IPageLifeExtra {
|
|
42
|
+
function getPageLifeExtra(page: any, methodName: string, args: any[]): IPageLifeExtra | IPageTouchExtra {
|
|
41
43
|
/* eslint-disable */
|
|
42
44
|
// 页面生命周期内第几次曝光
|
|
43
45
|
let showCount: number;
|
|
@@ -49,6 +51,7 @@ function getPageLifeExtra(page: any, methodName: string): IPageLifeExtra {
|
|
|
49
51
|
showCount = page.tmsPageShowCount;
|
|
50
52
|
lessShowTime = page.tmsPageShowTime - page.tmsPageLoadTime;
|
|
51
53
|
} else if (methodName === 'onLoad') {
|
|
54
|
+
page.tmsTouchCount = 0;
|
|
52
55
|
page.tmsPageShowCount = 0;
|
|
53
56
|
page.tmsPageLoadTime = Date.now();
|
|
54
57
|
showCount = 1;
|
|
@@ -57,9 +60,24 @@ function getPageLifeExtra(page: any, methodName: string): IPageLifeExtra {
|
|
|
57
60
|
showCount = page.tmsPageShowCount;
|
|
58
61
|
lessShowTime = Date.now() - page.tmsPageShowTime;
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
|
|
64
|
+
let touchCount = page.tmsTouchCount;
|
|
65
|
+
|
|
66
|
+
// 如果是页面触摸事件
|
|
67
|
+
if (methodName === pageTouchEvent) {
|
|
68
|
+
page.tmsTouchCount += 1;
|
|
69
|
+
touchCount += 1;
|
|
70
|
+
const { clientX, clientY, pageX, pageY } = args[0].touches[0];
|
|
71
|
+
const { windowWidth, windowHeight } = helper.getSystemInfo();
|
|
72
|
+
return {
|
|
73
|
+
showCount, lessShowTime, touchCount,
|
|
74
|
+
windowWidth, windowHeight, clientX, clientY, pageX, pageY,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
61
78
|
const lastBindEvent = helper.getLastBindEvent();
|
|
62
|
-
return { showCount, lessShowTime, lastBindEvent };
|
|
79
|
+
return { showCount, lessShowTime, lastBindEvent, touchCount };
|
|
80
|
+
/* eslint-enable */
|
|
63
81
|
}
|
|
64
82
|
|
|
65
83
|
// 劫持绑定事件
|
|
@@ -42,4 +42,48 @@ interface IPageLifeExtra {
|
|
|
42
42
|
* 最后一个触发绑定事件埋点
|
|
43
43
|
*/
|
|
44
44
|
lastBindEvent: IBindEvent | null,
|
|
45
|
+
/**
|
|
46
|
+
* 页面触摸次数
|
|
47
|
+
*/
|
|
48
|
+
touchCount: number,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface IPageTouchExtra {
|
|
52
|
+
/**
|
|
53
|
+
* 页面生命周期内第几次曝光
|
|
54
|
+
*/
|
|
55
|
+
showCount: number,
|
|
56
|
+
/**
|
|
57
|
+
* 距离onShow的时长
|
|
58
|
+
*/
|
|
59
|
+
lessShowTime: number,
|
|
60
|
+
/**
|
|
61
|
+
* 页面触摸次数
|
|
62
|
+
*/
|
|
63
|
+
touchCount: number,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 可使用窗口宽度
|
|
67
|
+
*/
|
|
68
|
+
windowWidth: number,
|
|
69
|
+
/**
|
|
70
|
+
* 可使用窗口高度
|
|
71
|
+
*/
|
|
72
|
+
windowHeight: number,
|
|
73
|
+
/**
|
|
74
|
+
* 触摸目标在视口中的x坐标
|
|
75
|
+
*/
|
|
76
|
+
clientX: number,
|
|
77
|
+
/**
|
|
78
|
+
* 触摸目标在视口中的y坐标
|
|
79
|
+
*/
|
|
80
|
+
clientY: number,
|
|
81
|
+
/**
|
|
82
|
+
* 触摸目标在页面中的x坐标
|
|
83
|
+
*/
|
|
84
|
+
pageX: number,
|
|
85
|
+
/**
|
|
86
|
+
* 触摸目标在页面中的y坐标
|
|
87
|
+
*/
|
|
88
|
+
pageY: number,
|
|
45
89
|
}
|