@tmsfe/tms-core 0.0.79 → 0.0.82
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/formatV1.ts
CHANGED
|
@@ -45,6 +45,8 @@ function getBaseData(deviceData: IDeviceData): DataItem[] {
|
|
|
45
45
|
arr[18] = location.cityName;
|
|
46
46
|
// 19: f19,当前小程序运行的宿主环境
|
|
47
47
|
arr[19] = host;
|
|
48
|
+
// 22: f22,小程序启动时的url和参数(与f36一致)
|
|
49
|
+
arr[22] = helper.getLaunchOptions();
|
|
48
50
|
// 28: f28,sinan、mycar等
|
|
49
51
|
arr[28] = client;
|
|
50
52
|
// 29: f29,小程序场景值
|
package/src/report/helper.ts
CHANGED
|
@@ -16,19 +16,25 @@ let initOptions: IInitOptions;
|
|
|
16
16
|
* 初始化
|
|
17
17
|
*/
|
|
18
18
|
function init(options: IInitOptions): void {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// 从上次缓存中读取,方便首次Report可以先带上
|
|
23
|
-
const loc = wx.getStorageSync('home.location_city') || wx.getStorageSync('home.city');
|
|
24
|
-
deviceData = {
|
|
25
|
-
networkType: '',
|
|
26
|
-
location: {
|
|
27
|
-
province: loc?.province as string,
|
|
28
|
-
cityName: loc?.cityName as string,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
19
|
+
if (initOptions) {
|
|
20
|
+
return;
|
|
31
21
|
}
|
|
22
|
+
|
|
23
|
+
initOptions = options;
|
|
24
|
+
|
|
25
|
+
// 从上次缓存中读取,方便首次Report可以先带上
|
|
26
|
+
const loc = wx.getStorageSync('home.location_city') || wx.getStorageSync('home.city');
|
|
27
|
+
deviceData = {
|
|
28
|
+
networkType: '',
|
|
29
|
+
location: {
|
|
30
|
+
province: loc?.province as string,
|
|
31
|
+
cityName: loc?.cityName as string,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
wx.onAppShow((options) => {
|
|
36
|
+
launchOptions = options;
|
|
37
|
+
});
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
@@ -128,7 +134,7 @@ function getPageInfo(): IPage {
|
|
|
128
134
|
let depth: number; // 页面深度
|
|
129
135
|
// 刚启动时首页未渲染
|
|
130
136
|
if (pages.length === 0) {
|
|
131
|
-
const launch =
|
|
137
|
+
const launch = getLaunchOptions();
|
|
132
138
|
route = launch.path;
|
|
133
139
|
options = launch.qurey;
|
|
134
140
|
depth = 1;
|
|
@@ -146,12 +152,12 @@ function getPageInfo(): IPage {
|
|
|
146
152
|
return { route, options, depth };
|
|
147
153
|
}
|
|
148
154
|
|
|
149
|
-
let launchOptions:
|
|
155
|
+
let launchOptions: any = null;
|
|
150
156
|
|
|
151
157
|
/**
|
|
152
158
|
* 获取小程序启动参数
|
|
153
159
|
*/
|
|
154
|
-
function getLaunchOptions():
|
|
160
|
+
function getLaunchOptions(): any {
|
|
155
161
|
if (launchOptions === null) {
|
|
156
162
|
launchOptions = syncApi.getLaunchOptionsSync();
|
|
157
163
|
}
|
|
@@ -162,7 +168,7 @@ function getLaunchOptions(): object {
|
|
|
162
168
|
* 获取小程序启动时的from参数
|
|
163
169
|
*/
|
|
164
170
|
function getLaunchFrom(): string {
|
|
165
|
-
const obj =
|
|
171
|
+
const obj = getLaunchOptions();
|
|
166
172
|
return obj.query?.from;
|
|
167
173
|
}
|
|
168
174
|
|
|
@@ -170,7 +176,7 @@ function getLaunchFrom(): string {
|
|
|
170
176
|
* 获取小程序启动场景值
|
|
171
177
|
*/
|
|
172
178
|
function getAppScene(): number {
|
|
173
|
-
const { scene = -1 } =
|
|
179
|
+
const { scene = -1 } = getLaunchOptions();
|
|
174
180
|
return scene;
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -244,6 +250,18 @@ function getCacheDeviceData(): IDeviceData {
|
|
|
244
250
|
return deviceData;
|
|
245
251
|
}
|
|
246
252
|
|
|
253
|
+
/**
|
|
254
|
+
* 设置字段到上报的SystemInfo中
|
|
255
|
+
* 用于携带自定义信息区分用户场景,比如新旧首页的区分
|
|
256
|
+
* @param fieldName
|
|
257
|
+
* @param value
|
|
258
|
+
*/
|
|
259
|
+
function setSystemField(fieldName: string, value: number | string): void {
|
|
260
|
+
const systemInfo = getSystemInfo();
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
systemInfo[fieldName] = value;
|
|
263
|
+
}
|
|
264
|
+
|
|
247
265
|
export default {
|
|
248
266
|
init,
|
|
249
267
|
getTms,
|
|
@@ -260,4 +278,5 @@ export default {
|
|
|
260
278
|
dataArrLen,
|
|
261
279
|
getDeviceData,
|
|
262
280
|
getCacheDeviceData,
|
|
281
|
+
setSystemField,
|
|
263
282
|
};
|
package/src/report/index.ts
CHANGED
|
@@ -55,23 +55,11 @@ function fastReport2(...data: any[]): void {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* 设置字段到上报的SystemInfo中
|
|
60
|
-
* 用于携带自定义信息区分用户场景,比如新旧首页的区分
|
|
61
|
-
* @param fieldName
|
|
62
|
-
* @param value
|
|
63
|
-
*/
|
|
64
|
-
function setSystemField(fieldName: string, value: number | string): void {
|
|
65
|
-
const systemInfo = helper.getSystemInfo();
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
systemInfo[fieldName] = value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
58
|
export default {
|
|
71
59
|
init,
|
|
72
60
|
report,
|
|
73
61
|
fastReport,
|
|
74
62
|
report2,
|
|
75
63
|
fastReport2,
|
|
76
|
-
setSystemField,
|
|
64
|
+
setSystemField: helper.setSystemField,
|
|
77
65
|
};
|
|
@@ -29,7 +29,7 @@ function proxyLifeMethod(componentName: string, componentOptions: any, methodNam
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// 劫持绑定事件
|
|
32
|
-
function proxyBindEvent(componentName: string, methods: any, methodName: string): void {
|
|
32
|
+
function proxyBindEvent(componentName: string, methods: any, methodName: string, bindType: string): void {
|
|
33
33
|
const original = methods[methodName];
|
|
34
34
|
if (!original) {
|
|
35
35
|
return;
|
|
@@ -41,8 +41,8 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string)
|
|
|
41
41
|
const extra = clone.getEventExtra(args[0]) ; // 把触发事件附加数据也带上
|
|
42
42
|
const data = clone.deepClone(this.data);
|
|
43
43
|
const eventName = `Component_${componentName}_${methodName}`;
|
|
44
|
-
helper.setLastBindEvent({ eventName, data, extra });
|
|
45
|
-
helper.reportData(eventName, data, extra);
|
|
44
|
+
helper.setLastBindEvent({ eventName, data, extra, bindType });
|
|
45
|
+
helper.reportData(eventName, data, extra, bindType);
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -56,8 +56,9 @@ function init(): void {
|
|
|
56
56
|
if (options.tmsAutoReport) {
|
|
57
57
|
// tmsReportEvents是由工具在编译时分析出的要上报的事件列表
|
|
58
58
|
const methods = options.methods || {};
|
|
59
|
-
for (const
|
|
60
|
-
|
|
59
|
+
for (const event of options.tmsReportEvents) {
|
|
60
|
+
const { name, type } = event;
|
|
61
|
+
proxyBindEvent(options.tmsComponentName, methods, name, type);
|
|
61
62
|
}
|
|
62
63
|
proxyLifeMethod(options.tmsComponentName, options, 'ready');
|
|
63
64
|
}
|
package/src/report/proxy/page.ts
CHANGED
|
@@ -85,7 +85,7 @@ function getPageLifeExtra(page: any, methodName: string, args: any[]): IPageLife
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// 劫持绑定事件
|
|
88
|
-
function proxyBindEvent(pageOptions: any, methodName: string): void {
|
|
88
|
+
function proxyBindEvent(pageOptions: any, methodName: string, bindType: string): void {
|
|
89
89
|
const original = pageOptions[methodName];
|
|
90
90
|
if (!original) {
|
|
91
91
|
return;
|
|
@@ -97,8 +97,8 @@ function proxyBindEvent(pageOptions: any, methodName: string): void {
|
|
|
97
97
|
return helper.executeFunc(this, original, args, () => {
|
|
98
98
|
const data = clone.deepClone(this.data);
|
|
99
99
|
const eventName = `Page_${methodName}`;
|
|
100
|
-
helper.setLastBindEvent({ eventName, data, extra });
|
|
101
|
-
helper.reportData(eventName, data, extra);
|
|
100
|
+
helper.setLastBindEvent({ eventName, data, extra, bindType });
|
|
101
|
+
helper.reportData(eventName, data, extra, bindType);
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
104
|
}
|
|
@@ -113,8 +113,9 @@ function proxyPage(): void {
|
|
|
113
113
|
proxyLifeMethod(options, methodName);
|
|
114
114
|
}
|
|
115
115
|
// tmsReportEvents是由工具在编译时分析出的要上报的事件列表
|
|
116
|
-
for (const
|
|
117
|
-
|
|
116
|
+
for (const event of options.tmsReportEvents) {
|
|
117
|
+
const { name, type } = event;
|
|
118
|
+
proxyBindEvent(options, name, type);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
originalPage(options);
|
|
@@ -163,7 +164,7 @@ function proxySubscribeMessage(): void {
|
|
|
163
164
|
// eslint-disable-next-line
|
|
164
165
|
options.fail = function(err: any) {
|
|
165
166
|
helper.reportData('wx_requestSubscribeMessage_fail', tmplIds, err.errMsg);
|
|
166
|
-
originalFail.
|
|
167
|
+
originalFail.call(this, err);
|
|
167
168
|
};
|
|
168
169
|
originalApi.call(this, options);
|
|
169
170
|
},
|