@tmsfe/tms-core 0.0.54 → 0.0.55
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 +1 -1
- package/src/report/formatV2.ts +12 -9
- package/src/report/helper.ts +13 -8
- package/src/report/types.ts +1 -0
package/package.json
CHANGED
package/src/report/formatV2.ts
CHANGED
|
@@ -8,8 +8,7 @@ import helper from './helper';
|
|
|
8
8
|
/**
|
|
9
9
|
* 获取埋点的基础字段
|
|
10
10
|
*/
|
|
11
|
-
function getBaseData(deviceData: IDeviceData): { arr: DataItem[], nextIndex: number } {
|
|
12
|
-
const { page, pageDepth } = helper.getPageInfo();
|
|
11
|
+
function getBaseData(page: IPage, deviceData: IDeviceData): { arr: DataItem[], nextIndex: number } {
|
|
13
12
|
const { networkType, location } = deviceData;
|
|
14
13
|
const { appVersion, client } = helper.getInitOptions();
|
|
15
14
|
const arr = new Array<DataItem>(helper.dataArrLen);
|
|
@@ -51,11 +50,11 @@ function getBaseData(deviceData: IDeviceData): { arr: DataItem[], nextIndex: num
|
|
|
51
50
|
// 22: f22,小程序启动时的url和参数
|
|
52
51
|
arr[22] = helper.getLaunchOptions();
|
|
53
52
|
// 23: f23,当前页面的url
|
|
54
|
-
arr[23] = page
|
|
53
|
+
arr[23] = page.route;
|
|
55
54
|
// 24: f24,当前页面的query
|
|
56
|
-
arr[24] = page
|
|
55
|
+
arr[24] = page.options;
|
|
57
56
|
// 25: f25,当前页面深度
|
|
58
|
-
arr[25] =
|
|
57
|
+
arr[25] = page.depth;
|
|
59
58
|
// 26: f26,一次小程序生命周期中的埋点统一标记
|
|
60
59
|
arr[26] = helper.getLifeReportKey();
|
|
61
60
|
// 27 ~ 30: 预留字段给后续扩展使用
|
|
@@ -67,8 +66,8 @@ function getBaseData(deviceData: IDeviceData): { arr: DataItem[], nextIndex: num
|
|
|
67
66
|
/**
|
|
68
67
|
* 拼接埋点数组
|
|
69
68
|
*/
|
|
70
|
-
function jointData(data: any[], deviceData: IDeviceData): DataItem[] {
|
|
71
|
-
const { arr, nextIndex } = getBaseData(deviceData);
|
|
69
|
+
function jointData(page: IPage, data: any[], deviceData: IDeviceData): DataItem[] {
|
|
70
|
+
const { arr, nextIndex } = getBaseData(page, deviceData);
|
|
72
71
|
let index = nextIndex;
|
|
73
72
|
for (const item of data) {
|
|
74
73
|
if (index >= arr.length) {
|
|
@@ -85,9 +84,11 @@ function jointData(data: any[], deviceData: IDeviceData): DataItem[] {
|
|
|
85
84
|
* 格式化上报埋点数据
|
|
86
85
|
*/
|
|
87
86
|
function formatData(data: any[]): Promise<DataItem[]> {
|
|
87
|
+
// getDeviceData可能会太慢导致页面已跳转完,所以先获取page比较准确
|
|
88
|
+
const page = helper.getPageInfo();
|
|
88
89
|
return new Promise<DataItem[]>((resolve) => {
|
|
89
90
|
helper.getDeviceData().then((deviceData: IDeviceData) => {
|
|
90
|
-
const arr = jointData(data, deviceData);
|
|
91
|
+
const arr = jointData(page, data, deviceData);
|
|
91
92
|
resolve(arr);
|
|
92
93
|
});
|
|
93
94
|
});
|
|
@@ -97,7 +98,9 @@ function formatData(data: any[]): Promise<DataItem[]> {
|
|
|
97
98
|
* 格式化快速上报埋点数据,不依赖用户位置
|
|
98
99
|
*/
|
|
99
100
|
function formatFastData(data: any[]): DataItem[] {
|
|
100
|
-
|
|
101
|
+
const page = helper.getPageInfo();
|
|
102
|
+
const deviceData = helper.getCacheDeviceData();
|
|
103
|
+
return jointData(page, data, deviceData);
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
export default {
|
package/src/report/helper.ts
CHANGED
|
@@ -116,20 +116,25 @@ function getLifeReportKey(): string {
|
|
|
116
116
|
/**
|
|
117
117
|
* 获取当前页面信息
|
|
118
118
|
*/
|
|
119
|
-
function getPageInfo():
|
|
119
|
+
function getPageInfo(): IPage {
|
|
120
120
|
const pages = getCurrentPages();
|
|
121
|
-
let
|
|
122
|
-
let
|
|
123
|
-
//
|
|
121
|
+
let route: string;
|
|
122
|
+
let options: object;
|
|
123
|
+
let depth: number; // 页面深度
|
|
124
|
+
// 刚启动时首页未渲染
|
|
124
125
|
if (pages.length === 0) {
|
|
125
126
|
const launch = syncApi.getLaunchOptionsSync() as any;
|
|
126
|
-
|
|
127
|
+
route = launch.path;
|
|
128
|
+
options = launch.qurey;
|
|
129
|
+
depth = 1;
|
|
127
130
|
} else {
|
|
128
|
-
pageDepth = pages.length;
|
|
129
131
|
// 如果最后一个为空,则当前是在插件页,继续找上一个页面
|
|
130
|
-
page = pages.reverse().find((t:
|
|
132
|
+
const page = pages.reverse().find((t: any) => t);
|
|
133
|
+
route = page?.route;
|
|
134
|
+
options = page?.options;
|
|
135
|
+
depth = pages.length;
|
|
131
136
|
}
|
|
132
|
-
return {
|
|
137
|
+
return { route, options, depth };
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
let launchOptions: object | null = null;
|