@tmsfe/tms-core 0.0.50 → 0.0.51
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
|
@@ -17,13 +17,16 @@ 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, () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
// 如果是滚动事件,太频繁就不发了
|
|
23
|
+
if (args[0]?.type !== 'scroll') {
|
|
24
|
+
const extra = clone.getEventExtra(args[0]) ; // 把触发事件附加数据也带上
|
|
25
|
+
const data = clone.deepClone(this.data);
|
|
26
|
+
const eventName = `Component_${componentName}`;
|
|
27
|
+
helper.setLastBindEvent({ eventName, methodName, data, extra });
|
|
28
|
+
helper.reportData(eventName, methodName, data, extra);
|
|
29
|
+
}
|
|
27
30
|
});
|
|
28
31
|
};
|
|
29
32
|
}
|
|
@@ -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
|
}
|