aegis-mp-rum-wrapper 0.1.4 → 0.1.6
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/dist/index.d.ts +1 -1
- package/dist/index.js +90 -86
- package/package.json +1 -1
- package/src/index.ts +115 -95
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,63 +11,63 @@ exports.reportEvent = reportEvent;
|
|
|
11
11
|
exports.getInstances = getInstances;
|
|
12
12
|
const aegis_mp_sdk_1 = __importDefault(require("aegis-mp-sdk"));
|
|
13
13
|
// RUM 上报 ID(默认使用国服服务)
|
|
14
|
-
exports.GPPRumID =
|
|
14
|
+
exports.GPPRumID = "8lDwXIovanY8d1awa6";
|
|
15
15
|
const logItemTemplate = {
|
|
16
16
|
report_type: 11,
|
|
17
|
-
event_id:
|
|
18
|
-
service_type:
|
|
19
|
-
openid:
|
|
20
|
-
role_id:
|
|
17
|
+
event_id: "",
|
|
18
|
+
service_type: "",
|
|
19
|
+
openid: "",
|
|
20
|
+
role_id: "",
|
|
21
21
|
area_id: 0,
|
|
22
22
|
zone_id: 0,
|
|
23
23
|
plat_id: 0,
|
|
24
24
|
channel_id: 0,
|
|
25
|
-
mod_name:
|
|
26
|
-
country:
|
|
27
|
-
language:
|
|
28
|
-
seq:
|
|
29
|
-
client_ip:
|
|
30
|
-
env:
|
|
31
|
-
log_time:
|
|
25
|
+
mod_name: "h5_frontend",
|
|
26
|
+
country: "",
|
|
27
|
+
language: "",
|
|
28
|
+
seq: "",
|
|
29
|
+
client_ip: "",
|
|
30
|
+
env: "prd",
|
|
31
|
+
log_time: "",
|
|
32
32
|
log_ts: 0,
|
|
33
|
-
extend1:
|
|
34
|
-
extend2:
|
|
35
|
-
extend3:
|
|
36
|
-
extend4:
|
|
33
|
+
extend1: "",
|
|
34
|
+
extend2: "",
|
|
35
|
+
extend3: "",
|
|
36
|
+
extend4: "",
|
|
37
37
|
in_game: 2,
|
|
38
|
-
open_panel:
|
|
38
|
+
open_panel: "2",
|
|
39
39
|
player_attr: 1,
|
|
40
|
-
inviter_open_id:
|
|
41
|
-
inviter_role_id:
|
|
40
|
+
inviter_open_id: "",
|
|
41
|
+
inviter_role_id: "",
|
|
42
42
|
inviter_zone_area_id: 0,
|
|
43
43
|
inviter_zone_id: 0,
|
|
44
44
|
inviter_plat_id: 0,
|
|
45
|
-
invitation_token:
|
|
45
|
+
invitation_token: "",
|
|
46
46
|
price: 0,
|
|
47
|
-
coin_type:
|
|
47
|
+
coin_type: "",
|
|
48
48
|
login_phase: 0,
|
|
49
49
|
share_channel: 0,
|
|
50
|
-
task_id:
|
|
51
|
-
account_type:
|
|
52
|
-
column_uid:
|
|
53
|
-
channel_uid:
|
|
54
|
-
plat:
|
|
55
|
-
content_id:
|
|
56
|
-
source:
|
|
50
|
+
task_id: "",
|
|
51
|
+
account_type: "",
|
|
52
|
+
column_uid: "",
|
|
53
|
+
channel_uid: "",
|
|
54
|
+
plat: "",
|
|
55
|
+
content_id: "",
|
|
56
|
+
source: "fe_rum",
|
|
57
57
|
};
|
|
58
58
|
// 内部状态
|
|
59
59
|
let defaultAegis;
|
|
60
60
|
let serviceAegis;
|
|
61
61
|
const internalState = {
|
|
62
62
|
id: exports.GPPRumID,
|
|
63
|
-
uin:
|
|
63
|
+
uin: "",
|
|
64
64
|
reportApiSpeed: false,
|
|
65
65
|
reportAssetSpeed: false,
|
|
66
66
|
pagePerformance: false,
|
|
67
67
|
webVitals: false,
|
|
68
68
|
delay: 100,
|
|
69
69
|
user: {},
|
|
70
|
-
rumID:
|
|
70
|
+
rumID: exports.GPPRumID,
|
|
71
71
|
ready: false,
|
|
72
72
|
};
|
|
73
73
|
// 构建一条上报日志 JSON 字符串(写入 ext1)
|
|
@@ -78,36 +78,40 @@ function buildReportStr(params, isPV) {
|
|
|
78
78
|
logItem.report_type = 1;
|
|
79
79
|
}
|
|
80
80
|
const user = internalState.user;
|
|
81
|
-
logItem.openid = ((_a = user.openid) !== null && _a !== void 0 ? _a :
|
|
82
|
-
logItem.role_id = user.roleID ? user.roleID +
|
|
81
|
+
logItem.openid = ((_a = user.openid) !== null && _a !== void 0 ? _a : "") + "";
|
|
82
|
+
logItem.role_id = user.roleID ? user.roleID + "" : "";
|
|
83
83
|
logItem.area_id = user.area ? parseInt(String(user.area), 10) : 0;
|
|
84
84
|
logItem.zone_id = user.zone ? parseInt(String(user.zone), 10) : 0;
|
|
85
85
|
logItem.plat_id = user.plat ? parseInt(String(user.plat), 10) : 0;
|
|
86
|
-
logItem.channel_id = user.channelID
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
logItem.
|
|
90
|
-
logItem.
|
|
91
|
-
|
|
92
|
-
logItem.
|
|
93
|
-
|
|
94
|
-
logItem.
|
|
95
|
-
logItem.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
logItem.
|
|
99
|
-
|
|
86
|
+
logItem.channel_id = user.channelID
|
|
87
|
+
? parseInt(String(user.channelID), 10)
|
|
88
|
+
: 0;
|
|
89
|
+
logItem.service_type = ((_b = user.serviceType) !== null && _b !== void 0 ? _b : "") + "";
|
|
90
|
+
logItem.event_id = ((_c = user.eventID) !== null && _c !== void 0 ? _c : "") + "";
|
|
91
|
+
logItem.country = user.country ? user.country + "" : "";
|
|
92
|
+
logItem.content_id = user.contentID ? user.contentID + "" : "";
|
|
93
|
+
const lang = (_e = (_d = user.language) !== null && _d !== void 0 ? _d : user.locale) !== null && _e !== void 0 ? _e : "";
|
|
94
|
+
logItem.language = lang ? lang + "" : "";
|
|
95
|
+
logItem.in_game = user.in_game
|
|
96
|
+
? parseInt(String(user.in_game), 10)
|
|
97
|
+
: logItem.in_game;
|
|
98
|
+
logItem.env = user.env ? user.env + "" : logItem.env;
|
|
99
|
+
logItem.account_type = user.accountType ? user.accountType + "" : "";
|
|
100
|
+
logItem.column_uid = user.columnUID ? user.columnUID + "" : "";
|
|
101
|
+
logItem.channel_uid = user.channelUID ? user.channelUID + "" : "";
|
|
102
|
+
logItem.plat = user.platName ? user.platName + "" : "";
|
|
103
|
+
if (typeof params === "string") {
|
|
100
104
|
logItem.extend1 = params;
|
|
101
105
|
}
|
|
102
|
-
else if (typeof params ===
|
|
106
|
+
else if (typeof params === "object" && params) {
|
|
103
107
|
logItem.extend1 = params.name;
|
|
104
|
-
if (typeof params.ext1 ===
|
|
108
|
+
if (typeof params.ext1 === "string") {
|
|
105
109
|
logItem.extend2 = params.ext1;
|
|
106
110
|
}
|
|
107
|
-
if (typeof params.ext2 ===
|
|
111
|
+
if (typeof params.ext2 === "string") {
|
|
108
112
|
logItem.extend3 = params.ext2;
|
|
109
113
|
}
|
|
110
|
-
if (typeof params.ext3 ===
|
|
114
|
+
if (typeof params.ext3 === "string") {
|
|
111
115
|
logItem.extend4 = params.ext3;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
@@ -116,8 +120,8 @@ function buildReportStr(params, isPV) {
|
|
|
116
120
|
}
|
|
117
121
|
// 初始化 Aegis 实例(isDefault=true 为默认实例,false 为服务实例)
|
|
118
122
|
function initAegis(isDefault) {
|
|
119
|
-
console.log(
|
|
120
|
-
let id = internalState.id;
|
|
123
|
+
console.log("initAegis205", isDefault, internalState);
|
|
124
|
+
let id = internalState.rumID || internalState.id;
|
|
121
125
|
let apiSpeed = internalState.reportApiSpeed;
|
|
122
126
|
let assetSpeed = internalState.reportAssetSpeed;
|
|
123
127
|
let pagePerformance = internalState.pagePerformance;
|
|
@@ -125,7 +129,7 @@ function initAegis(isDefault) {
|
|
|
125
129
|
let delay = internalState.delay;
|
|
126
130
|
let ext1;
|
|
127
131
|
if (!isDefault) {
|
|
128
|
-
id = internalState.rumID || internalState.id;
|
|
132
|
+
// id = internalState.rumID || internalState.id;
|
|
129
133
|
apiSpeed = true;
|
|
130
134
|
assetSpeed = true;
|
|
131
135
|
pagePerformance = true;
|
|
@@ -134,16 +138,16 @@ function initAegis(isDefault) {
|
|
|
134
138
|
}
|
|
135
139
|
if (internalState.ready) {
|
|
136
140
|
ext1 = buildReportStr({
|
|
137
|
-
name:
|
|
141
|
+
name: "@@init",
|
|
138
142
|
ext1: internalState.user.ext1,
|
|
139
143
|
ext2: internalState.user.ext2,
|
|
140
144
|
ext3: internalState.user.ext3,
|
|
141
145
|
}, true);
|
|
142
146
|
}
|
|
143
|
-
console.log(
|
|
147
|
+
console.log("AegisCtor235", aegis_mp_sdk_1.default);
|
|
144
148
|
// 小程序环境直接使用构造函数
|
|
145
|
-
if (typeof aegis_mp_sdk_1.default ===
|
|
146
|
-
console.log(
|
|
149
|
+
if (typeof aegis_mp_sdk_1.default === "function") {
|
|
150
|
+
console.log("return new AegisCtor");
|
|
147
151
|
return new aegis_mp_sdk_1.default({
|
|
148
152
|
id,
|
|
149
153
|
uin: internalState.uin,
|
|
@@ -154,36 +158,33 @@ function initAegis(isDefault) {
|
|
|
154
158
|
delay,
|
|
155
159
|
spa: true,
|
|
156
160
|
ext1,
|
|
161
|
+
// hostUrl: "https://aegis.qq.com",
|
|
157
162
|
beforeRequest(data) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return data;
|
|
163
|
+
if (data.logType === "speed" || data.logType === "log") {
|
|
164
|
+
return false;
|
|
161
165
|
}
|
|
162
|
-
|
|
163
|
-
return data;
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
+
return data;
|
|
166
167
|
},
|
|
167
168
|
});
|
|
168
169
|
}
|
|
169
|
-
console.error(
|
|
170
|
+
console.error("[Aegis Wrapper] 找不到 aegis-mp-sdk 构造函数,请确认依赖是否正确安装和引用265");
|
|
170
171
|
return undefined;
|
|
171
172
|
}
|
|
172
173
|
// 对外暴露的配置 API
|
|
173
174
|
function configureWrapper(config) {
|
|
174
175
|
if (config.id)
|
|
175
176
|
internalState.id = config.id;
|
|
176
|
-
if (typeof config.uin ===
|
|
177
|
+
if (typeof config.uin === "string")
|
|
177
178
|
internalState.uin = config.uin;
|
|
178
|
-
if (typeof config.reportApiSpeed ===
|
|
179
|
+
if (typeof config.reportApiSpeed === "boolean")
|
|
179
180
|
internalState.reportApiSpeed = config.reportApiSpeed;
|
|
180
|
-
if (typeof config.reportAssetSpeed ===
|
|
181
|
+
if (typeof config.reportAssetSpeed === "boolean")
|
|
181
182
|
internalState.reportAssetSpeed = config.reportAssetSpeed;
|
|
182
|
-
if (typeof config.pagePerformance ===
|
|
183
|
+
if (typeof config.pagePerformance === "boolean")
|
|
183
184
|
internalState.pagePerformance = config.pagePerformance;
|
|
184
|
-
if (typeof config.webVitals ===
|
|
185
|
+
if (typeof config.webVitals === "boolean")
|
|
185
186
|
internalState.webVitals = config.webVitals;
|
|
186
|
-
if (typeof config.delay ===
|
|
187
|
+
if (typeof config.delay === "number")
|
|
187
188
|
internalState.delay = config.delay;
|
|
188
189
|
}
|
|
189
190
|
function setUser(user) {
|
|
@@ -200,41 +201,43 @@ function setUser(user) {
|
|
|
200
201
|
internalState.user = nextUser;
|
|
201
202
|
const u = internalState.user;
|
|
202
203
|
if (u.openid && u.serviceType && u.eventID) {
|
|
203
|
-
console.log(
|
|
204
|
+
console.log("294", internalState, defaultAegis);
|
|
204
205
|
if (!internalState.ready) {
|
|
205
206
|
internalState.ready = true;
|
|
206
207
|
defaultAegis = initAegis(true);
|
|
207
|
-
console.log(
|
|
208
|
+
console.log("[Aegis Wrapper] default aegis 已就绪298");
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
else {
|
|
211
|
-
console.log(
|
|
212
|
+
console.log("[Aegis Wrapper] 初始化条件不足:需要 openid / serviceType / eventID", u);
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
215
|
function setRumID(rumID) {
|
|
215
216
|
internalState.rumID = rumID;
|
|
217
|
+
internalState.id = rumID;
|
|
216
218
|
serviceAegis = initAegis(false);
|
|
217
|
-
console.log(
|
|
219
|
+
console.log("[Aegis Wrapper] service aegis rumID 已设置");
|
|
218
220
|
}
|
|
219
221
|
// 事件上报入口:兼容字符串和对象参数
|
|
220
222
|
function reportEvent(params) {
|
|
221
223
|
// 先调用服务实例(如果存在)
|
|
222
|
-
if (serviceAegis && typeof serviceAegis.reportEvent ===
|
|
224
|
+
if (serviceAegis && typeof serviceAegis.reportEvent === "function") {
|
|
223
225
|
serviceAegis.reportEvent(params);
|
|
224
226
|
}
|
|
225
|
-
if (!defaultAegis ||
|
|
226
|
-
|
|
227
|
+
if (!defaultAegis ||
|
|
228
|
+
typeof defaultAegis.reportEvent !== "function") {
|
|
229
|
+
console.error("[Aegis Wrapper] default aegis 尚未准备就绪,请先调用 setUser 并补全必要字段");
|
|
227
230
|
return;
|
|
228
231
|
}
|
|
229
|
-
if (typeof params !==
|
|
230
|
-
console.error(
|
|
232
|
+
if (typeof params !== "string" && typeof params !== "object") {
|
|
233
|
+
console.error("[Aegis Wrapper] reportEvent 参数类型错误,应为 string 或 object");
|
|
231
234
|
return;
|
|
232
235
|
}
|
|
233
|
-
if (typeof params ===
|
|
234
|
-
console.error(
|
|
236
|
+
if (typeof params === "object" && params.name === undefined) {
|
|
237
|
+
console.error("[Aegis Wrapper] reportEvent 缺少 name 字段");
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
237
|
-
const payload = typeof params ===
|
|
240
|
+
const payload = typeof params === "string" ? { name: params } : Object.assign({}, params);
|
|
238
241
|
payload.ext1 = buildReportStr(payload, false);
|
|
239
242
|
defaultAegis.reportEvent(payload);
|
|
240
243
|
}
|
|
@@ -250,11 +253,11 @@ function getInstances() {
|
|
|
250
253
|
// 2)AegisW.reportEvent({...})
|
|
251
254
|
const handler = {
|
|
252
255
|
set(target, prop, value) {
|
|
253
|
-
console.log(
|
|
256
|
+
console.log("user change351", target, prop, value);
|
|
254
257
|
// console.log(`changed ${prop} from ${target[prop]} to ${value}`); // debug info
|
|
255
258
|
target[prop] = value;
|
|
256
259
|
if (prop === "user" && typeof value === "object") {
|
|
257
|
-
console.log(
|
|
260
|
+
console.log("user change368");
|
|
258
261
|
if (value.openid != undefined &&
|
|
259
262
|
value.openid != "" &&
|
|
260
263
|
value.serviceType != undefined &&
|
|
@@ -275,6 +278,7 @@ const handler = {
|
|
|
275
278
|
serviceAegis = initAegis(false);
|
|
276
279
|
console.log("[Aegis Wrapper]rum id is set378");
|
|
277
280
|
}
|
|
281
|
+
return true; // Proxy set trap 必须返回 true 表示设置成功
|
|
278
282
|
},
|
|
279
283
|
};
|
|
280
284
|
exports.AegisW = new Proxy(internalState, handler);
|
|
@@ -317,7 +321,7 @@ if ((document === null || document === void 0 ? void 0 : document.readyState) ==
|
|
|
317
321
|
document.addEventListener("DOMContentLoaded", init);
|
|
318
322
|
}
|
|
319
323
|
else {
|
|
320
|
-
console.log(
|
|
324
|
+
console.log("init()434");
|
|
321
325
|
// init report wrapper
|
|
322
326
|
init();
|
|
323
327
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import AegisCtor from
|
|
1
|
+
import AegisCtor from "aegis-mp-sdk";
|
|
2
2
|
|
|
3
3
|
// RUM 上报 ID(默认使用国服服务)
|
|
4
|
-
export const GPPRumID =
|
|
4
|
+
export const GPPRumID = "8lDwXIovanY8d1awa6";
|
|
5
5
|
|
|
6
6
|
// 封装的用户信息结构
|
|
7
7
|
export interface AegisUserInfo {
|
|
@@ -85,46 +85,46 @@ interface LogItem {
|
|
|
85
85
|
|
|
86
86
|
const logItemTemplate: LogItem = {
|
|
87
87
|
report_type: 11,
|
|
88
|
-
event_id:
|
|
89
|
-
service_type:
|
|
90
|
-
openid:
|
|
91
|
-
role_id:
|
|
88
|
+
event_id: "",
|
|
89
|
+
service_type: "",
|
|
90
|
+
openid: "",
|
|
91
|
+
role_id: "",
|
|
92
92
|
area_id: 0,
|
|
93
93
|
zone_id: 0,
|
|
94
94
|
plat_id: 0,
|
|
95
95
|
channel_id: 0,
|
|
96
|
-
mod_name:
|
|
97
|
-
country:
|
|
98
|
-
language:
|
|
99
|
-
seq:
|
|
100
|
-
client_ip:
|
|
101
|
-
env:
|
|
102
|
-
log_time:
|
|
96
|
+
mod_name: "h5_frontend",
|
|
97
|
+
country: "",
|
|
98
|
+
language: "",
|
|
99
|
+
seq: "",
|
|
100
|
+
client_ip: "",
|
|
101
|
+
env: "prd",
|
|
102
|
+
log_time: "",
|
|
103
103
|
log_ts: 0,
|
|
104
|
-
extend1:
|
|
105
|
-
extend2:
|
|
106
|
-
extend3:
|
|
107
|
-
extend4:
|
|
104
|
+
extend1: "",
|
|
105
|
+
extend2: "",
|
|
106
|
+
extend3: "",
|
|
107
|
+
extend4: "",
|
|
108
108
|
in_game: 2,
|
|
109
|
-
open_panel:
|
|
109
|
+
open_panel: "2",
|
|
110
110
|
player_attr: 1,
|
|
111
|
-
inviter_open_id:
|
|
112
|
-
inviter_role_id:
|
|
111
|
+
inviter_open_id: "",
|
|
112
|
+
inviter_role_id: "",
|
|
113
113
|
inviter_zone_area_id: 0,
|
|
114
114
|
inviter_zone_id: 0,
|
|
115
115
|
inviter_plat_id: 0,
|
|
116
|
-
invitation_token:
|
|
116
|
+
invitation_token: "",
|
|
117
117
|
price: 0,
|
|
118
|
-
coin_type:
|
|
118
|
+
coin_type: "",
|
|
119
119
|
login_phase: 0,
|
|
120
120
|
share_channel: 0,
|
|
121
|
-
task_id:
|
|
122
|
-
account_type:
|
|
123
|
-
column_uid:
|
|
124
|
-
channel_uid:
|
|
125
|
-
plat:
|
|
126
|
-
content_id:
|
|
127
|
-
source:
|
|
121
|
+
task_id: "",
|
|
122
|
+
account_type: "",
|
|
123
|
+
column_uid: "",
|
|
124
|
+
channel_uid: "",
|
|
125
|
+
plat: "",
|
|
126
|
+
content_id: "",
|
|
127
|
+
source: "fe_rum",
|
|
128
128
|
};
|
|
129
129
|
|
|
130
130
|
// 内部状态
|
|
@@ -133,14 +133,14 @@ let serviceAegis: any;
|
|
|
133
133
|
|
|
134
134
|
const internalState = {
|
|
135
135
|
id: GPPRumID,
|
|
136
|
-
uin:
|
|
136
|
+
uin: "",
|
|
137
137
|
reportApiSpeed: false,
|
|
138
138
|
reportAssetSpeed: false,
|
|
139
139
|
pagePerformance: false,
|
|
140
140
|
webVitals: false,
|
|
141
141
|
delay: 100,
|
|
142
142
|
user: {} as AegisUserInfo,
|
|
143
|
-
rumID:
|
|
143
|
+
rumID: GPPRumID,
|
|
144
144
|
ready: false,
|
|
145
145
|
};
|
|
146
146
|
|
|
@@ -162,36 +162,40 @@ function buildReportStr(params: string | ReportParams, isPV: boolean): string {
|
|
|
162
162
|
|
|
163
163
|
const user = internalState.user;
|
|
164
164
|
|
|
165
|
-
logItem.openid = (user.openid ??
|
|
166
|
-
logItem.role_id = user.roleID ? user.roleID +
|
|
165
|
+
logItem.openid = (user.openid ?? "") + "";
|
|
166
|
+
logItem.role_id = user.roleID ? user.roleID + "" : "";
|
|
167
167
|
logItem.area_id = user.area ? parseInt(String(user.area), 10) : 0;
|
|
168
168
|
logItem.zone_id = user.zone ? parseInt(String(user.zone), 10) : 0;
|
|
169
169
|
logItem.plat_id = user.plat ? parseInt(String(user.plat), 10) : 0;
|
|
170
|
-
logItem.channel_id = user.channelID
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
logItem.
|
|
174
|
-
logItem.
|
|
175
|
-
|
|
176
|
-
logItem.
|
|
177
|
-
|
|
178
|
-
logItem.
|
|
179
|
-
logItem.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
logItem.
|
|
183
|
-
|
|
184
|
-
|
|
170
|
+
logItem.channel_id = user.channelID
|
|
171
|
+
? parseInt(String(user.channelID), 10)
|
|
172
|
+
: 0;
|
|
173
|
+
logItem.service_type = (user.serviceType ?? "") + "";
|
|
174
|
+
logItem.event_id = (user.eventID ?? "") + "";
|
|
175
|
+
logItem.country = user.country ? user.country + "" : "";
|
|
176
|
+
logItem.content_id = user.contentID ? user.contentID + "" : "";
|
|
177
|
+
const lang = user.language ?? user.locale ?? "";
|
|
178
|
+
logItem.language = lang ? lang + "" : "";
|
|
179
|
+
logItem.in_game = user.in_game
|
|
180
|
+
? parseInt(String(user.in_game), 10)
|
|
181
|
+
: logItem.in_game;
|
|
182
|
+
logItem.env = user.env ? user.env + "" : logItem.env;
|
|
183
|
+
logItem.account_type = user.accountType ? user.accountType + "" : "";
|
|
184
|
+
logItem.column_uid = user.columnUID ? user.columnUID + "" : "";
|
|
185
|
+
logItem.channel_uid = user.channelUID ? user.channelUID + "" : "";
|
|
186
|
+
logItem.plat = user.platName ? user.platName + "" : "";
|
|
187
|
+
|
|
188
|
+
if (typeof params === "string") {
|
|
185
189
|
logItem.extend1 = params;
|
|
186
|
-
} else if (typeof params ===
|
|
190
|
+
} else if (typeof params === "object" && params) {
|
|
187
191
|
logItem.extend1 = params.name;
|
|
188
|
-
if (typeof params.ext1 ===
|
|
192
|
+
if (typeof params.ext1 === "string") {
|
|
189
193
|
logItem.extend2 = params.ext1;
|
|
190
194
|
}
|
|
191
|
-
if (typeof params.ext2 ===
|
|
195
|
+
if (typeof params.ext2 === "string") {
|
|
192
196
|
logItem.extend3 = params.ext2;
|
|
193
197
|
}
|
|
194
|
-
if (typeof params.ext3 ===
|
|
198
|
+
if (typeof params.ext3 === "string") {
|
|
195
199
|
logItem.extend4 = params.ext3;
|
|
196
200
|
}
|
|
197
201
|
}
|
|
@@ -202,8 +206,8 @@ function buildReportStr(params: string | ReportParams, isPV: boolean): string {
|
|
|
202
206
|
|
|
203
207
|
// 初始化 Aegis 实例(isDefault=true 为默认实例,false 为服务实例)
|
|
204
208
|
function initAegis(isDefault: boolean): any | undefined {
|
|
205
|
-
console.log(
|
|
206
|
-
let id = internalState.id;
|
|
209
|
+
console.log("initAegis205", isDefault, internalState);
|
|
210
|
+
let id = internalState.rumID || internalState.id;
|
|
207
211
|
let apiSpeed = internalState.reportApiSpeed;
|
|
208
212
|
let assetSpeed = internalState.reportAssetSpeed;
|
|
209
213
|
let pagePerformance = internalState.pagePerformance;
|
|
@@ -212,7 +216,7 @@ function initAegis(isDefault: boolean): any | undefined {
|
|
|
212
216
|
let ext1: string | undefined;
|
|
213
217
|
|
|
214
218
|
if (!isDefault) {
|
|
215
|
-
id = internalState.rumID || internalState.id;
|
|
219
|
+
// id = internalState.rumID || internalState.id;
|
|
216
220
|
apiSpeed = true;
|
|
217
221
|
assetSpeed = true;
|
|
218
222
|
pagePerformance = true;
|
|
@@ -223,19 +227,19 @@ function initAegis(isDefault: boolean): any | undefined {
|
|
|
223
227
|
if (internalState.ready) {
|
|
224
228
|
ext1 = buildReportStr(
|
|
225
229
|
{
|
|
226
|
-
name:
|
|
230
|
+
name: "@@init",
|
|
227
231
|
ext1: internalState.user.ext1,
|
|
228
232
|
ext2: internalState.user.ext2,
|
|
229
233
|
ext3: internalState.user.ext3,
|
|
230
234
|
},
|
|
231
|
-
true
|
|
235
|
+
true
|
|
232
236
|
);
|
|
233
237
|
}
|
|
234
|
-
console.log(
|
|
238
|
+
console.log("AegisCtor235", AegisCtor);
|
|
235
239
|
|
|
236
240
|
// 小程序环境直接使用构造函数
|
|
237
|
-
if (typeof AegisCtor ===
|
|
238
|
-
console.log(
|
|
241
|
+
if (typeof AegisCtor === "function") {
|
|
242
|
+
console.log("return new AegisCtor");
|
|
239
243
|
return new (AegisCtor as any)({
|
|
240
244
|
id,
|
|
241
245
|
uin: internalState.uin,
|
|
@@ -246,32 +250,35 @@ console.log('AegisCtor235',AegisCtor);
|
|
|
246
250
|
delay,
|
|
247
251
|
spa: true,
|
|
248
252
|
ext1,
|
|
253
|
+
// hostUrl: "https://aegis.qq.com",
|
|
249
254
|
beforeRequest(data: any) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return data;
|
|
255
|
+
if (data.logType === "speed" || data.logType === "log") {
|
|
256
|
+
return false;
|
|
253
257
|
}
|
|
254
|
-
|
|
255
|
-
return data;
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
+
return data;
|
|
258
259
|
},
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
262
|
|
|
262
|
-
console.error(
|
|
263
|
+
console.error(
|
|
264
|
+
"[Aegis Wrapper] 找不到 aegis-mp-sdk 构造函数,请确认依赖是否正确安装和引用265"
|
|
265
|
+
);
|
|
263
266
|
return undefined;
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
// 对外暴露的配置 API
|
|
267
270
|
export function configureWrapper(config: AegisMpWrapperConfig): void {
|
|
268
271
|
if (config.id) internalState.id = config.id;
|
|
269
|
-
if (typeof config.uin ===
|
|
270
|
-
if (typeof config.reportApiSpeed ===
|
|
271
|
-
|
|
272
|
-
if (typeof config.
|
|
273
|
-
|
|
274
|
-
if (typeof config.
|
|
272
|
+
if (typeof config.uin === "string") internalState.uin = config.uin;
|
|
273
|
+
if (typeof config.reportApiSpeed === "boolean")
|
|
274
|
+
internalState.reportApiSpeed = config.reportApiSpeed;
|
|
275
|
+
if (typeof config.reportAssetSpeed === "boolean")
|
|
276
|
+
internalState.reportAssetSpeed = config.reportAssetSpeed;
|
|
277
|
+
if (typeof config.pagePerformance === "boolean")
|
|
278
|
+
internalState.pagePerformance = config.pagePerformance;
|
|
279
|
+
if (typeof config.webVitals === "boolean")
|
|
280
|
+
internalState.webVitals = config.webVitals;
|
|
281
|
+
if (typeof config.delay === "number") internalState.delay = config.delay;
|
|
275
282
|
}
|
|
276
283
|
|
|
277
284
|
export function setUser(user: Partial<AegisUserInfo>): void {
|
|
@@ -295,46 +302,58 @@ export function setUser(user: Partial<AegisUserInfo>): void {
|
|
|
295
302
|
|
|
296
303
|
const u = internalState.user;
|
|
297
304
|
if (u.openid && u.serviceType && u.eventID) {
|
|
298
|
-
console.log(
|
|
299
|
-
|
|
305
|
+
console.log("294", internalState, defaultAegis);
|
|
306
|
+
if (!internalState.ready) {
|
|
300
307
|
internalState.ready = true;
|
|
301
308
|
defaultAegis = initAegis(true);
|
|
302
|
-
console.log(
|
|
309
|
+
console.log("[Aegis Wrapper] default aegis 已就绪298");
|
|
303
310
|
}
|
|
304
311
|
} else {
|
|
305
|
-
console.log(
|
|
312
|
+
console.log(
|
|
313
|
+
"[Aegis Wrapper] 初始化条件不足:需要 openid / serviceType / eventID",
|
|
314
|
+
u
|
|
315
|
+
);
|
|
306
316
|
}
|
|
307
317
|
}
|
|
308
318
|
|
|
309
319
|
export function setRumID(rumID: string): void {
|
|
310
320
|
internalState.rumID = rumID;
|
|
321
|
+
internalState.id = rumID;
|
|
311
322
|
serviceAegis = initAegis(false);
|
|
312
|
-
console.log(
|
|
323
|
+
console.log("[Aegis Wrapper] service aegis rumID 已设置");
|
|
313
324
|
}
|
|
314
325
|
|
|
315
326
|
// 事件上报入口:兼容字符串和对象参数
|
|
316
327
|
export function reportEvent(params: string | ReportParams): void {
|
|
317
328
|
// 先调用服务实例(如果存在)
|
|
318
|
-
if (serviceAegis && typeof (serviceAegis as any).reportEvent ===
|
|
329
|
+
if (serviceAegis && typeof (serviceAegis as any).reportEvent === "function") {
|
|
319
330
|
(serviceAegis as any).reportEvent(params as any);
|
|
320
331
|
}
|
|
321
332
|
|
|
322
|
-
if (
|
|
323
|
-
|
|
333
|
+
if (
|
|
334
|
+
!defaultAegis ||
|
|
335
|
+
typeof (defaultAegis as any).reportEvent !== "function"
|
|
336
|
+
) {
|
|
337
|
+
console.error(
|
|
338
|
+
"[Aegis Wrapper] default aegis 尚未准备就绪,请先调用 setUser 并补全必要字段"
|
|
339
|
+
);
|
|
324
340
|
return;
|
|
325
341
|
}
|
|
326
342
|
|
|
327
|
-
if (typeof params !==
|
|
328
|
-
console.error(
|
|
343
|
+
if (typeof params !== "string" && typeof params !== "object") {
|
|
344
|
+
console.error(
|
|
345
|
+
"[Aegis Wrapper] reportEvent 参数类型错误,应为 string 或 object"
|
|
346
|
+
);
|
|
329
347
|
return;
|
|
330
348
|
}
|
|
331
349
|
|
|
332
|
-
if (typeof params ===
|
|
333
|
-
console.error(
|
|
350
|
+
if (typeof params === "object" && (params as any).name === undefined) {
|
|
351
|
+
console.error("[Aegis Wrapper] reportEvent 缺少 name 字段");
|
|
334
352
|
return;
|
|
335
353
|
}
|
|
336
354
|
|
|
337
|
-
const payload: any =
|
|
355
|
+
const payload: any =
|
|
356
|
+
typeof params === "string" ? { name: params } : { ...params };
|
|
338
357
|
payload.ext1 = buildReportStr(payload, false);
|
|
339
358
|
(defaultAegis as any).reportEvent(payload);
|
|
340
359
|
}
|
|
@@ -350,15 +369,15 @@ export function getInstances() {
|
|
|
350
369
|
// 面向业务侧的简单封装对象,支持示例中的两种用法:
|
|
351
370
|
// 1)AegisW.user = {...}
|
|
352
371
|
// 2)AegisW.reportEvent({...})
|
|
353
|
-
const handler:any = {
|
|
354
|
-
set(target:any, prop:any, value:any) {
|
|
355
|
-
console.log(
|
|
356
|
-
|
|
372
|
+
const handler: any = {
|
|
373
|
+
set(target: any, prop: any, value: any) {
|
|
374
|
+
console.log("user change351", target, prop, value);
|
|
375
|
+
|
|
357
376
|
// console.log(`changed ${prop} from ${target[prop]} to ${value}`); // debug info
|
|
358
377
|
target[prop] = value;
|
|
359
378
|
if (prop === "user" && typeof value === "object") {
|
|
360
|
-
|
|
361
|
-
|
|
379
|
+
console.log("user change368");
|
|
380
|
+
|
|
362
381
|
if (
|
|
363
382
|
value.openid != undefined &&
|
|
364
383
|
value.openid != "" &&
|
|
@@ -381,9 +400,10 @@ const handler:any = {
|
|
|
381
400
|
serviceAegis = initAegis(false);
|
|
382
401
|
console.log("[Aegis Wrapper]rum id is set378");
|
|
383
402
|
}
|
|
403
|
+
return true; // Proxy set trap 必须返回 true 表示设置成功
|
|
384
404
|
},
|
|
385
405
|
};
|
|
386
|
-
export const AegisW:any = new Proxy(internalState, handler);
|
|
406
|
+
export const AegisW: any = new Proxy(internalState, handler);
|
|
387
407
|
// init
|
|
388
408
|
function init() {
|
|
389
409
|
console.log("initing...385");
|
|
@@ -428,7 +448,7 @@ if (document?.readyState === "loading") {
|
|
|
428
448
|
// add event listener for report wrapper
|
|
429
449
|
document.addEventListener("DOMContentLoaded", init);
|
|
430
450
|
} else {
|
|
431
|
-
console.log(
|
|
451
|
+
console.log("init()434");
|
|
432
452
|
// init report wrapper
|
|
433
453
|
init();
|
|
434
454
|
}
|