@tmsfe/tms-core 0.0.49 → 0.0.52

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.49",
3
+ "version": "0.0.52",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -77,7 +77,7 @@ function deepClone(obj: any, depth = 0, maxDepth = 5): any {
77
77
  * 获取触发绑定事件的携带数据
78
78
  * @param event
79
79
  */
80
- function getEventExtend(event: any): any {
80
+ function getEventExtra(event: any): any {
81
81
  if (!event) {
82
82
  return '';
83
83
  }
@@ -100,5 +100,5 @@ function getEventExtend(event: any): any {
100
100
 
101
101
  export default {
102
102
  deepClone,
103
- getEventExtend,
103
+ getEventExtra,
104
104
  };
@@ -17,13 +17,13 @@ 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 extend = clone.getEventExtend(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
- helper.setLastBindEvent({ eventName, methodName, data, extend });
26
- helper.reportData(eventName, methodName, data, extend);
25
+ helper.setLastBindEvent({ eventName, methodName, data, extra });
26
+ helper.reportData(eventName, methodName, data, extra);
27
27
  });
28
28
  };
29
29
  }
@@ -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
  };
@@ -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', 'onPageScroll',
17
+ 'onShareTimeline', 'onAddToFavorites',
16
18
  ];
17
19
  const lifeMethods = mustLifeMethods.concat(maybeLifeMethods);
18
20
 
@@ -27,9 +29,9 @@ 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 extend = getPageLifeExtend(this, methodName);
32
- helper.reportData(`Page_${methodName}`, options, extend);
32
+ const options = methodName === pageTouchEvent ? '' : clone.deepClone(args[0], 0, 1);
33
+ const extra = getPageLifeExtra(this, methodName, args);
34
+ helper.reportData(`Page_${methodName}`, options, extra);
33
35
 
34
36
  // 执行原函数
35
37
  return helper.executeFunc(this, original, args, helper.emptyFunc);
@@ -37,9 +39,8 @@ function proxyLifeMethod(pageOptions: any, methodName: string): void {
37
39
  }
38
40
 
39
41
  // 获取生命周期函数上报时的附加信息
40
- function getPageLifeExtend(page: any, methodName: string): IPageLifeExtend {
42
+ function getPageLifeExtra(page: any, methodName: string, args: any[]): IPageLifeExtra | IPageTouchExtra {
41
43
  /* eslint-disable */
42
- page.tmsPageShowCount = page.tmsPageShowCount || 0;
43
44
  // 页面生命周期内第几次曝光
44
45
  let showCount: number;
45
46
  // 距离onShow的时长,如果是onShow函数则为距离onLoad的时长
@@ -50,16 +51,33 @@ function getPageLifeExtend(page: any, methodName: string): IPageLifeExtend {
50
51
  showCount = page.tmsPageShowCount;
51
52
  lessShowTime = page.tmsPageShowTime - page.tmsPageLoadTime;
52
53
  } else if (methodName === 'onLoad') {
54
+ page.tmsTouchCount = 0;
55
+ page.tmsPageShowCount = 0;
56
+ page.tmsPageLoadTime = Date.now();
53
57
  showCount = 1;
54
58
  lessShowTime = 0;
55
- page.tmsPageLoadTime = Date.now();
56
59
  } else {
57
60
  showCount = page.tmsPageShowCount;
58
61
  lessShowTime = Date.now() - page.tmsPageShowTime;
59
62
  }
60
- /* eslint-enable */
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
  // 劫持绑定事件
@@ -70,13 +88,13 @@ function proxyBindEvent(pageOptions: any, methodName: string): void {
70
88
  }
71
89
  // eslint-disable-next-line no-param-reassign
72
90
  pageOptions[methodName] = function (...args: any[]): any {
73
- const extend = clone.getEventExtend(args[0]) ; // 把触发事件附加数据也带上
91
+ const extra = clone.getEventExtra(args[0]) ; // 把触发事件附加数据也带上
74
92
  // 执行原函数之后再发埋点
75
93
  return helper.executeFunc(this, original, args, () => {
76
94
  const data = clone.deepClone(this.data);
77
95
  const eventName = `Page_${methodName}`;
78
- helper.setLastBindEvent({ eventName, methodName, data, extend });
79
- helper.reportData(eventName, data, extend);
96
+ helper.setLastBindEvent({ eventName, methodName, data, extra });
97
+ helper.reportData(eventName, data, extra);
80
98
  });
81
99
  };
82
100
  }
@@ -23,13 +23,13 @@ interface IBindEvent {
23
23
  /**
24
24
  * 触发事件的携带参数
25
25
  */
26
- extend: object,
26
+ extra: object,
27
27
  }
28
28
 
29
29
  /**
30
30
  * 页面生命周期函数的埋点附加数据
31
31
  */
32
- interface IPageLifeExtend {
32
+ interface IPageLifeExtra {
33
33
  /**
34
34
  * 页面生命周期内第几次曝光
35
35
  */
@@ -37,9 +37,53 @@ interface IPageLifeExtend {
37
37
  /**
38
38
  * 距离onShow的时长,如果是onShow函数则为距离onLoad的时长
39
39
  */
40
- lessShowTime?: number,
40
+ lessShowTime: number,
41
41
  /**
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
  }