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