drgame-cc 1.0.62 → 1.0.63
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/drres/focus/focus_1/gesture.atlas +34 -34
- package/drres/focus/focus_2/gesture.atlas +41 -41
- package/drres/focus/focus_3/gesture.atlas +34 -34
- package/drres/focus/focus_4/gesture.atlas +20 -20
- package/drres/prefab/HelperWin.prefab +508 -508
- package/drscript/PlatformAdapter.ts +2 -2
- package/drscript/ad-sdk/README.md +78 -12
- package/drscript/ad-sdk/ad-sdk.ts +416 -0
- package/drscript/ad-sdk/{adapters/xiaomi-adapter.js.meta → ad-sdk.ts.meta} +2 -2
- package/drscript/ad-sdk/event-emitter.ts +66 -0
- package/drscript/ad-sdk/event-emitter.ts.meta +10 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.ts +219 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.ts.meta +10 -0
- package/drscript/ad-sdk/package.json +18 -17
- package/drscript/ad-sdk/reporters/reporter.ts +515 -0
- package/drscript/ad-sdk/reporters/reporter.ts.meta +10 -0
- package/drscript/ad-sdk/reporters/superset-lewo.ts +464 -0
- package/drscript/ad-sdk/reporters/superset-lewo.ts.meta +10 -0
- package/drscript/ad-sdk/types/enums.ts +103 -0
- package/drscript/ad-sdk/types/enums.ts.meta +10 -0
- package/drscript/ad-sdk/types/{index.d.ts → index.ts} +1 -1
- package/drscript/ad-sdk/types/index.ts.meta +10 -0
- package/drscript/ad-sdk/types/{interfaces.d.ts → interfaces.ts} +61 -10
- package/drscript/ad-sdk/types/interfaces.ts.meta +10 -0
- package/drscript/ad-sdk/user-gamedata/user-gamedata.ts +219 -0
- package/drscript/ad-sdk/user-gamedata/user-gamedata.ts.meta +10 -0
- package/drscript/ad-sdk/user-gamedata.meta +13 -0
- package/package.json +1 -1
- package/drscript/ad-sdk/ad-sdk.d.ts +0 -59
- package/drscript/ad-sdk/ad-sdk.js +0 -338
- package/drscript/ad-sdk/adapters/xiaomi-adapter.d.ts +0 -29
- package/drscript/ad-sdk/adapters/xiaomi-adapter.d.ts.meta +0 -6
- package/drscript/ad-sdk/adapters/xiaomi-adapter.js +0 -452
- package/drscript/ad-sdk/event-emitter.d.ts +0 -12
- package/drscript/ad-sdk/event-emitter.js +0 -65
- package/drscript/ad-sdk/leaderboard/leaderboard.d.ts +0 -23
- package/drscript/ad-sdk/leaderboard/leaderboard.js +0 -193
- package/drscript/ad-sdk/reporters/reporter.d.ts +0 -85
- package/drscript/ad-sdk/reporters/reporter.js +0 -500
- package/drscript/ad-sdk/reporters/superset-lewo.js +0 -574
- package/drscript/ad-sdk/types/enums.d.ts +0 -66
- package/drscript/ad-sdk/types/enums.js +0 -113
- package/drscript/ad-sdk/types/index.js +0 -15
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据上报模块 - 统一封装层
|
|
3
|
+
*
|
|
4
|
+
* 内部使用 supersetLewo 上报脚本,对外提供简洁的调用接口:
|
|
5
|
+
* Reporter.init(config) — 初始化
|
|
6
|
+
* Reporter.report(data, immediate) — 单次上报(默认加入队列批量发送)
|
|
7
|
+
* Reporter.reportBatch(list) — 批量上报
|
|
8
|
+
* Reporter.flushQueue() — 立即刷新队列
|
|
9
|
+
* Reporter.reportAppStart() — 启动事件
|
|
10
|
+
* Reporter.reportSwitchBackground() — 切后台事件
|
|
11
|
+
* Reporter.reportSwitchBack() — 切回事件
|
|
12
|
+
* Reporter.reportAppExit() — 退出事件(自动计算游戏时长)
|
|
13
|
+
* Reporter.updateUserInfo(info) — 登录后更新用户信息
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import supersetLewo from './superset-lewo';
|
|
17
|
+
import {
|
|
18
|
+
IReporterConfig,
|
|
19
|
+
IReportItem,
|
|
20
|
+
} from '../types/interfaces';
|
|
21
|
+
|
|
22
|
+
// ────────────────────────────────────────
|
|
23
|
+
// 上报动作类型
|
|
24
|
+
// ────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
export const ActionType = {
|
|
27
|
+
/** 曝光 */
|
|
28
|
+
Exposure: '曝光',
|
|
29
|
+
/** 点击 */
|
|
30
|
+
Click: '点击',
|
|
31
|
+
/** 开始播放 */
|
|
32
|
+
StartPlay: '开始播放',
|
|
33
|
+
/** 结束播放(需上报时长 action_value) */
|
|
34
|
+
EndPlay: '结束播放',
|
|
35
|
+
/** 分享 */
|
|
36
|
+
Share: '分享',
|
|
37
|
+
/** 订购(需上报成功订购金额) */
|
|
38
|
+
Order: '订购',
|
|
39
|
+
/** 启动 */
|
|
40
|
+
Start: '启动',
|
|
41
|
+
/** 退出 */
|
|
42
|
+
Exit: '退出',
|
|
43
|
+
/** 切后台 */
|
|
44
|
+
SwitchBackground: '切后台',
|
|
45
|
+
/** 切回 */
|
|
46
|
+
SwitchBack: '切回',
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
export interface IBatchConfig {
|
|
50
|
+
/** 每批最大条数 */
|
|
51
|
+
perNum: number;
|
|
52
|
+
/** 发送间隔(秒) */
|
|
53
|
+
spaceSec: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ────────────────────────────────────────
|
|
57
|
+
// 内部队列管理(无需修改 supersetLewo)
|
|
58
|
+
// ────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/** 配置接口地址 */
|
|
61
|
+
const CONFIG_URL = 'https://sup.daoran.tv/bi-api/api/config/get';
|
|
62
|
+
|
|
63
|
+
/** 事件队列 */
|
|
64
|
+
const _eventQueue: IReportItem[] = [];
|
|
65
|
+
/** 定时器句柄 */
|
|
66
|
+
let _batchTimer: any = null;
|
|
67
|
+
/** 每批最大条数 */
|
|
68
|
+
let _perNum = 10;
|
|
69
|
+
/** 发送间隔(秒) */
|
|
70
|
+
let _spaceSec = 30;
|
|
71
|
+
/** 队列模式是否已启用 */
|
|
72
|
+
let _queueEnabled = false;
|
|
73
|
+
|
|
74
|
+
/** 会话启动时间戳(毫秒),用于计算游戏时长 */
|
|
75
|
+
let _sessionStartTime = 0;
|
|
76
|
+
|
|
77
|
+
/** 额外用户信息(登录后填充,合并到上报 user 对象) */
|
|
78
|
+
const _extraUserInfo: Record<string, string> = {};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 修补 supersetLewo.getUserInfo,使登录后的额外字段能合并到 user 对象
|
|
82
|
+
* 避免修改 superset-lewo 源文件
|
|
83
|
+
*/
|
|
84
|
+
(function _patchGetUserInfo() {
|
|
85
|
+
const originalGetUserInfo = supersetLewo.getUserInfo;
|
|
86
|
+
supersetLewo.getUserInfo = function () {
|
|
87
|
+
const info = originalGetUserInfo();
|
|
88
|
+
// 合并额外字段(如 user_id、user_type 等)
|
|
89
|
+
for (const key in _extraUserInfo) {
|
|
90
|
+
if (_extraUserInfo.hasOwnProperty(key)) {
|
|
91
|
+
info[key] = _extraUserInfo[key];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return info;
|
|
95
|
+
};
|
|
96
|
+
})();
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 刷新队列 —— 将队列中所有事件打包发送
|
|
100
|
+
*/
|
|
101
|
+
function _flushQueue() {
|
|
102
|
+
if (_eventQueue.length === 0) return;
|
|
103
|
+
const batch = _eventQueue.splice(0, _perNum);
|
|
104
|
+
supersetLewo.batchReporting(batch);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 添加单条事件到队列
|
|
109
|
+
*/
|
|
110
|
+
function _addToQueue(eventItem: IReportItem) {
|
|
111
|
+
_eventQueue.push(eventItem);
|
|
112
|
+
if (_eventQueue.length >= _perNum) {
|
|
113
|
+
_flushQueue();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 批量添加事件到队列
|
|
119
|
+
*/
|
|
120
|
+
function _addBatchToQueue(eventList: IReportItem[]) {
|
|
121
|
+
if (!Array.isArray(eventList) || eventList.length === 0) return;
|
|
122
|
+
for (let i = 0; i < eventList.length; i++) {
|
|
123
|
+
_eventQueue.push(eventList[i]);
|
|
124
|
+
}
|
|
125
|
+
if (_eventQueue.length >= _perNum) {
|
|
126
|
+
_flushQueue();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 启用队列定时刷新
|
|
132
|
+
*/
|
|
133
|
+
function _startQueueTimer() {
|
|
134
|
+
if (_queueEnabled) return;
|
|
135
|
+
_queueEnabled = true;
|
|
136
|
+
_batchTimer = setInterval(_flushQueue, _spaceSec * 1000);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 停止队列定时刷新
|
|
141
|
+
*/
|
|
142
|
+
function _stopQueueTimer() {
|
|
143
|
+
_queueEnabled = false;
|
|
144
|
+
if (_batchTimer) {
|
|
145
|
+
clearInterval(_batchTimer);
|
|
146
|
+
_batchTimer = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ────────────────────────────────────────
|
|
151
|
+
// Reporter 实现
|
|
152
|
+
// ────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
export interface ReporterLike {
|
|
155
|
+
_initialized: boolean;
|
|
156
|
+
_commonInfo: Record<string, any>;
|
|
157
|
+
init(config: IReporterConfig): void;
|
|
158
|
+
fetchReportConfig(callback?: (config: IBatchConfig) => void): void;
|
|
159
|
+
report(data: IReportItem, immediate?: boolean): void;
|
|
160
|
+
reportBatch(dataList: IReportItem[], commonInfo?: IReportItem, immediate?: boolean): void;
|
|
161
|
+
flushQueue(): void;
|
|
162
|
+
createDeviceId(): string;
|
|
163
|
+
resetDeviceId(): void;
|
|
164
|
+
setCommonInfo(info: Record<string, any>): void;
|
|
165
|
+
getCommonInfo(): Record<string, any>;
|
|
166
|
+
updateUserInfo(userInfo: Record<string, string>): void;
|
|
167
|
+
reportAppStart(): void;
|
|
168
|
+
reportSwitchBackground(): void;
|
|
169
|
+
reportSwitchBack(): void;
|
|
170
|
+
reportAppExit(): void;
|
|
171
|
+
readonly instance: any;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const Rep: ReporterLike = {
|
|
175
|
+
/** 是否已初始化 */
|
|
176
|
+
_initialized: false,
|
|
177
|
+
|
|
178
|
+
/** 公共字段缓存(初始化时设置,每次上报自动合并) */
|
|
179
|
+
_commonInfo: {},
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 从后端获取批量上报配置
|
|
183
|
+
*/
|
|
184
|
+
fetchReportConfig: function (callback?: (config: IBatchConfig) => void) {
|
|
185
|
+
supersetLewo.ajax({
|
|
186
|
+
url: CONFIG_URL,
|
|
187
|
+
type: 'get',
|
|
188
|
+
dataType: 'json',
|
|
189
|
+
data: {},
|
|
190
|
+
success: function (_xhr, rsp) {
|
|
191
|
+
if (rsp && rsp.code === 200 && rsp.data) {
|
|
192
|
+
const cfg = rsp.data;
|
|
193
|
+
_perNum = cfg.perNum || 10;
|
|
194
|
+
_spaceSec = cfg.spaceSec || 30;
|
|
195
|
+
if (typeof callback === 'function') {
|
|
196
|
+
callback({ perNum: _perNum, spaceSec: _spaceSec });
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if (typeof callback === 'function') {
|
|
200
|
+
callback({ perNum: 10, spaceSec: 30 });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
error: function (_xhr, rsp) {
|
|
205
|
+
console.warn('[Reporter] fetchReportConfig failed, use defaults', rsp);
|
|
206
|
+
if (typeof callback === 'function') {
|
|
207
|
+
callback({ perNum: 10, spaceSec: 30 });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 初始化上报模块
|
|
215
|
+
*/
|
|
216
|
+
init: function (config: IReporterConfig) {
|
|
217
|
+
config = config || {};
|
|
218
|
+
|
|
219
|
+
// 设置上报地址(未传则使用 supersetLewo 默认值)
|
|
220
|
+
if (config.report_url) {
|
|
221
|
+
supersetLewo.config.reportUrl = config.report_url;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 设置请求头
|
|
225
|
+
if (config.headers && config.headers.length > 0) {
|
|
226
|
+
supersetLewo.config.defaultHeaders = config.headers as any;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 设置默认行为类型
|
|
230
|
+
if (config.default_action_type) {
|
|
231
|
+
(supersetLewo.config as any).defaultActionType = config.default_action_type;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 缓存公共字段
|
|
235
|
+
this._commonInfo = {
|
|
236
|
+
app_item: config.app_item || '',
|
|
237
|
+
content_type: config.content_type || '游戏',
|
|
238
|
+
content_id: config.content_id || '',
|
|
239
|
+
content_title: config.content_title || '',
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// 自动填充 device_id
|
|
243
|
+
if (!this._commonInfo.device_id) {
|
|
244
|
+
this._commonInfo.device_id = supersetLewo.createDeviceId();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
supersetLewo.initUserInfo({
|
|
248
|
+
os_type: config.os_type || "", // 操作系统类型 android/ios
|
|
249
|
+
os_version: config.os_version || "", // 操作系统版本号
|
|
250
|
+
app_version: config.app_version || "1.0.0", // APP版本号
|
|
251
|
+
app_item: config.app_item || "", // 渠道编码(项目编码)
|
|
252
|
+
app_name: config.app_name || config.content_title || "", // APP名称
|
|
253
|
+
app_project: config.app_project || config.content_id || "", // 产品编码
|
|
254
|
+
province: config.province || "", // 省份编码
|
|
255
|
+
city: config.city || "", // 城市编码
|
|
256
|
+
uid: config.uid || "", // 注册登录用户全局UID;游客/未登录填空字符串
|
|
257
|
+
user_id: config.user_id || "", // 会员ID(memberId),无则填空字符串,不用uid填充
|
|
258
|
+
device_id: this._commonInfo.device_id, // 设备唯一ID
|
|
259
|
+
device_brand: config.device_brand || "", // 设备品牌,小写
|
|
260
|
+
device_model: config.device_model || "", // 设备型号
|
|
261
|
+
network_type: config.network_type || "", // 网络类型:wifi/cellular
|
|
262
|
+
carrier: config.carrier || "", // 运营商
|
|
263
|
+
promotion_flag: config.promotion_flag || "0", // 推广标识(ubp接口获取,1推广/0自然)
|
|
264
|
+
user_type: config.user_type || "0" // 用户身份类型(0游客/1注册用户/2付费用户)
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
this._initialized = true;
|
|
268
|
+
|
|
269
|
+
// 记录启动时间
|
|
270
|
+
_sessionStartTime = Date.now();
|
|
271
|
+
|
|
272
|
+
// 异步拉取批量配置,拉取成功后启动队列
|
|
273
|
+
this.fetchReportConfig(function (batchCfg) {
|
|
274
|
+
_startQueueTimer();
|
|
275
|
+
console.log('[Reporter] Batch config:', batchCfg, '- Queue mode enabled');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
console.log('[Reporter] Initialized, reportUrl:', supersetLewo.config.reportUrl);
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 单次上报
|
|
283
|
+
*/
|
|
284
|
+
report: function (data: IReportItem, immediate?: boolean) {
|
|
285
|
+
if (!this._initialized) {
|
|
286
|
+
console.warn('[Reporter] Not initialized. Call Reporter.init() first.');
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 合并公共字段 + 传入数据
|
|
291
|
+
const merged: IReportItem = {};
|
|
292
|
+
let key: string;
|
|
293
|
+
for (key in this._commonInfo) {
|
|
294
|
+
if (this._commonInfo.hasOwnProperty(key)) {
|
|
295
|
+
merged[key] = this._commonInfo[key];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
for (key in data) {
|
|
299
|
+
if (data.hasOwnProperty(key)) {
|
|
300
|
+
merged[key] = data[key];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// 自动填充 device_id
|
|
305
|
+
if (!merged.device_id) {
|
|
306
|
+
merged.device_id = supersetLewo.createDeviceId();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (immediate) {
|
|
310
|
+
// 立即发送(生命周期事件等需要及时上报的场景)
|
|
311
|
+
supersetLewo.superBatchReport(merged);
|
|
312
|
+
} else {
|
|
313
|
+
// 加入队列,凑批次后批量发送
|
|
314
|
+
_addToQueue(merged);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 批量上报
|
|
320
|
+
*/
|
|
321
|
+
reportBatch: function (dataList: IReportItem[], commonInfo?: IReportItem, immediate?: boolean) {
|
|
322
|
+
if (!this._initialized) {
|
|
323
|
+
console.warn('[Reporter] Not initialized. Call Reporter.init() first.');
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const mergedCommon: IReportItem = {};
|
|
328
|
+
let key: string;
|
|
329
|
+
|
|
330
|
+
// 合并初始化时的公共字段
|
|
331
|
+
for (key in this._commonInfo) {
|
|
332
|
+
if (this._commonInfo.hasOwnProperty(key)) {
|
|
333
|
+
mergedCommon[key] = this._commonInfo[key];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 合并传入的公共字段(优先级更高)
|
|
338
|
+
if (commonInfo) {
|
|
339
|
+
for (key in commonInfo) {
|
|
340
|
+
if (commonInfo.hasOwnProperty(key)) {
|
|
341
|
+
mergedCommon[key] = commonInfo[key];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 自动填充 device_id
|
|
347
|
+
if (!mergedCommon.device_id) {
|
|
348
|
+
mergedCommon.device_id = supersetLewo.createDeviceId();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 合并公共字段到各事件中
|
|
352
|
+
const items: IReportItem[] = [];
|
|
353
|
+
for (let i = 0; i < dataList.length; i++) {
|
|
354
|
+
const item: IReportItem = {};
|
|
355
|
+
for (key in mergedCommon) {
|
|
356
|
+
if (mergedCommon.hasOwnProperty(key)) {
|
|
357
|
+
item[key] = mergedCommon[key];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
for (key in dataList[i]) {
|
|
361
|
+
if (dataList[i].hasOwnProperty(key)) {
|
|
362
|
+
item[key] = dataList[i][key];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
items.push(item);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (immediate) {
|
|
369
|
+
// 立即发送
|
|
370
|
+
supersetLewo.batchReporting(items);
|
|
371
|
+
} else {
|
|
372
|
+
// 加入队列
|
|
373
|
+
_addBatchToQueue(items);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 立即刷新队列,将队列中所有事件立即发送
|
|
379
|
+
*/
|
|
380
|
+
flushQueue: function () {
|
|
381
|
+
_flushQueue();
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 上报「启动」事件 - APP启动成功后调用,记录启动时间
|
|
386
|
+
*/
|
|
387
|
+
reportAppStart: function () {
|
|
388
|
+
_sessionStartTime = Date.now();
|
|
389
|
+
this.report({
|
|
390
|
+
element_position: "AppLaunch",
|
|
391
|
+
position_name: "应用启动",
|
|
392
|
+
element_type: "page",
|
|
393
|
+
element_name: "app_start",
|
|
394
|
+
action_type: ActionType.Start,
|
|
395
|
+
action_value: ""
|
|
396
|
+
}, true);
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* 上报「切后台」事件 - APP切到后台时调用
|
|
401
|
+
*/
|
|
402
|
+
reportSwitchBackground: function () {
|
|
403
|
+
const duration = Math.floor((Date.now() - _sessionStartTime) / 1000);
|
|
404
|
+
this.report({
|
|
405
|
+
element_position: "AppBackground",
|
|
406
|
+
position_name: "应用切后台",
|
|
407
|
+
element_type: "page",
|
|
408
|
+
element_name: "app_switch_background",
|
|
409
|
+
action_type: ActionType.SwitchBackground,
|
|
410
|
+
action_value: String(duration)
|
|
411
|
+
}, true);
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 上报「切回」事件 - APP从后台切回时调用,上报后更新启动时间
|
|
416
|
+
*/
|
|
417
|
+
reportSwitchBack: function () {
|
|
418
|
+
this.report({
|
|
419
|
+
element_position: "AppForeground",
|
|
420
|
+
position_name: "应用切前台",
|
|
421
|
+
element_type: "page",
|
|
422
|
+
element_name: "app_switch_back",
|
|
423
|
+
action_type: ActionType.SwitchBack,
|
|
424
|
+
action_value: ""
|
|
425
|
+
}, true);
|
|
426
|
+
// 更新启动时间
|
|
427
|
+
_sessionStartTime = Date.now();
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* 上报「退出」事件 - APP退出前调用
|
|
432
|
+
*/
|
|
433
|
+
reportAppExit: function () {
|
|
434
|
+
// 先刷新队列中剩余事件
|
|
435
|
+
_flushQueue();
|
|
436
|
+
|
|
437
|
+
const duration = Math.floor((Date.now() - _sessionStartTime) / 1000);
|
|
438
|
+
this.report({
|
|
439
|
+
element_position: "AppExit",
|
|
440
|
+
position_name: "应用退出",
|
|
441
|
+
element_type: "page",
|
|
442
|
+
element_name: "app_exit",
|
|
443
|
+
action_type: ActionType.Exit,
|
|
444
|
+
action_value: String(duration)
|
|
445
|
+
}, true);
|
|
446
|
+
// 重置启动时间
|
|
447
|
+
_sessionStartTime = 0;
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 更新用户信息(登录后调用,传入memberId等)
|
|
452
|
+
*/
|
|
453
|
+
updateUserInfo: function (userInfo: Record<string, string>) {
|
|
454
|
+
if (!userInfo) return;
|
|
455
|
+
// 更新公共字段(合并到 data 事件中)
|
|
456
|
+
this.setCommonInfo(userInfo);
|
|
457
|
+
// 更新额外用户信息(合并到上报的 user 对象中)
|
|
458
|
+
for (const key in userInfo) {
|
|
459
|
+
if (userInfo.hasOwnProperty(key)) {
|
|
460
|
+
_extraUserInfo[key] = userInfo[key];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
console.log('[Reporter] updateUserInfo:', userInfo);
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* 获取或创建设备唯一ID
|
|
468
|
+
*/
|
|
469
|
+
createDeviceId: function () {
|
|
470
|
+
return supersetLewo.createDeviceId();
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* 重置设备ID(清除缓存、localStorage、cookie)
|
|
475
|
+
*/
|
|
476
|
+
resetDeviceId: function () {
|
|
477
|
+
supersetLewo.resetDeviceId();
|
|
478
|
+
if (this._commonInfo) {
|
|
479
|
+
this._commonInfo.device_id = supersetLewo.createDeviceId();
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* 更新公共字段(如用户登录后更新 user_id)
|
|
485
|
+
*/
|
|
486
|
+
setCommonInfo: function (info: Record<string, any>) {
|
|
487
|
+
for (const key in info) {
|
|
488
|
+
if (info.hasOwnProperty(key)) {
|
|
489
|
+
this._commonInfo[key] = info[key];
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 获取当前公共字段
|
|
496
|
+
*/
|
|
497
|
+
getCommonInfo: function () {
|
|
498
|
+
const copy: Record<string, any> = {};
|
|
499
|
+
for (const key in this._commonInfo) {
|
|
500
|
+
if (this._commonInfo.hasOwnProperty(key)) {
|
|
501
|
+
copy[key] = this._commonInfo[key];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return copy;
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/** 获取底层 supersetLewo 实例(高级用法) */
|
|
508
|
+
get instance() {
|
|
509
|
+
return supersetLewo;
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
export const Reporter: ReporterLike = Rep;
|
|
514
|
+
|
|
515
|
+
export default Reporter;
|