@chiyou/minigame-framework 1.4.0 → 1.4.1
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
|
@@ -32,88 +32,14 @@ export interface UmengConfig {
|
|
|
32
32
|
|
|
33
33
|
// ==================== SDK 类型声明 ====================
|
|
34
34
|
|
|
35
|
-
/** 关卡结束事件类型 */
|
|
36
|
-
export enum StageEventType {
|
|
37
|
-
/** 关卡完成 */
|
|
38
|
-
Complete = "complete",
|
|
39
|
-
/** 关卡失败 */
|
|
40
|
-
Fail = "fail",
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 关卡中行为事件类型 */
|
|
44
|
-
export enum StageRunningEventType {
|
|
45
|
-
/** 使用道具 */
|
|
46
|
-
Tools = "tools",
|
|
47
|
-
/** 获得奖励 */
|
|
48
|
-
Award = "award",
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** 关卡开始参数 */
|
|
52
|
-
export interface StageStartParams {
|
|
53
|
-
/** 关卡ID(必传,string类型) */
|
|
54
|
-
stageId: string;
|
|
55
|
-
/** 关卡名称(必传) */
|
|
56
|
-
stageName: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** 关卡结束参数 */
|
|
60
|
-
export interface StageEndParams {
|
|
61
|
-
/** 关卡ID(必传,string类型) */
|
|
62
|
-
stageId: string;
|
|
63
|
-
/** 关卡名称(必传) */
|
|
64
|
-
stageName: string;
|
|
65
|
-
/** 关卡结束结果(必传,complete/fail) */
|
|
66
|
-
event: StageEventType;
|
|
67
|
-
/** 关卡耗时(毫秒,可选) */
|
|
68
|
-
_um_sdu?: number;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 关卡中行为事件参数 */
|
|
72
|
-
export interface StageRunningParams {
|
|
73
|
-
/** 关卡ID(必传,string类型) */
|
|
74
|
-
stageId: string;
|
|
75
|
-
/** 关卡名称(必传) */
|
|
76
|
-
stageName: string;
|
|
77
|
-
/** 事件类型(必传,tools/award) */
|
|
78
|
-
event: StageRunningEventType;
|
|
79
|
-
/** 事件参数 */
|
|
80
|
-
params?: StageRunningItemParams;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** 关卡中行为物品参数 */
|
|
84
|
-
export interface StageRunningItemParams {
|
|
85
|
-
/** 商品/道具名称(必传) */
|
|
86
|
-
itemName: string;
|
|
87
|
-
/** 商品/道具ID(可选) */
|
|
88
|
-
itemId?: string;
|
|
89
|
-
/** 商品/道具数量(可选) */
|
|
90
|
-
itemCount?: number;
|
|
91
|
-
/** 商品/道具单价(可选) */
|
|
92
|
-
itemMoney?: number;
|
|
93
|
-
/** 描述(可选) */
|
|
94
|
-
desc?: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** 友盟关卡 SDK 接口 */
|
|
98
|
-
export interface UmaSDKStage {
|
|
99
|
-
/** 关卡开始 */
|
|
100
|
-
onStart(params: StageStartParams): void;
|
|
101
|
-
/** 关卡结束 */
|
|
102
|
-
onEnd(params: StageEndParams): void;
|
|
103
|
-
/** 关卡中行为 */
|
|
104
|
-
onRunning(params: StageRunningParams): void;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
35
|
/**
|
|
108
36
|
* 友盟 SDK 接口定义
|
|
109
37
|
*
|
|
110
|
-
* 仅包含实际可用的方法(共
|
|
38
|
+
* 仅包含实际可用的方法(共11个)
|
|
111
39
|
* 已移除:removeUserid, setUserInfo, setAnonymousid, setAppVersion, setSuperProperty(不可用)
|
|
112
40
|
* 已移除:revenue, stage, level, rc(插件方法)
|
|
113
41
|
*
|
|
114
42
|
* 使用方式:SDK 在 game.js 中初始化后,通过 wx.uma 全局实例访问
|
|
115
|
-
*
|
|
116
|
-
* 关卡行为上报通过 wx.uma.stage 对象访问
|
|
117
43
|
*/
|
|
118
44
|
export interface UmaSDK {
|
|
119
45
|
/** 恢复会话(onShow 时调用) */
|
|
@@ -138,8 +64,6 @@ export interface UmaSDK {
|
|
|
138
64
|
onShareAppMessage(callback: () => object): void;
|
|
139
65
|
/** 调用分享 */
|
|
140
66
|
shareAppMessage(options: object): void;
|
|
141
|
-
/** 关卡行为上报(stage 对象) */
|
|
142
|
-
stage: UmaSDKStage;
|
|
143
67
|
}
|
|
144
68
|
|
|
145
69
|
// ==================== 预定义事件 ID ====================
|
|
@@ -3,10 +3,10 @@ import { LogUtils } from "../Utils/LogUtils";
|
|
|
3
3
|
import { ServiceLocator } from "../Utils/ServiceLocator";
|
|
4
4
|
import { FwkErrorCode } from "../Definition/FwkErrorDefinition";
|
|
5
5
|
import { PlatformID } from "../Definition/SystemDefinition";
|
|
6
|
-
import { UmengConfig, EventParams, AnalyticsEventId, AnalyticsParamKey, UmaSDK,
|
|
6
|
+
import { UmengConfig, EventParams, AnalyticsEventId, AnalyticsParamKey, UmaSDK, CommonParams } from "../Definition/AnalyticsDefinition";
|
|
7
7
|
import { EventMgr } from "./EventMgr";
|
|
8
8
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
9
|
-
import { SystemMgr } from "./SystemMgr";
|
|
9
|
+
import type { SystemMgr } from "./SystemMgr";
|
|
10
10
|
|
|
11
11
|
export class AnalyticsMgr extends BaseMgr {
|
|
12
12
|
/** 单例实例 */
|
|
@@ -20,8 +20,6 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
20
20
|
private _isEnabled: boolean = false;
|
|
21
21
|
/** 当前平台对应的 SDK 实例(通过 wx.uma 全局访问) */
|
|
22
22
|
private _sdk: UmaSDK = null;
|
|
23
|
-
/** 关卡 SDK 实例 */
|
|
24
|
-
private _sdkStage: UmaSDKStage = null;
|
|
25
23
|
/** 通用属性(trackEvent 自动合并) */
|
|
26
24
|
private _commonParams: CommonParams = null;
|
|
27
25
|
|
|
@@ -74,12 +72,20 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
74
72
|
|
|
75
73
|
// 根据当前平台是否开启统计来决定是否启用
|
|
76
74
|
const platformID: PlatformID = BaseMgr.Instance.getCurrentPlatformID();
|
|
77
|
-
|
|
75
|
+
let enabled = umengConfig.platformEnableMap.get(platformID);
|
|
76
|
+
|
|
77
|
+
if (enabled) {
|
|
78
|
+
// 额外检查:本地游戏无网络请求能力,不上报统计
|
|
79
|
+
const systemMgr = ServiceLocator.Instance.get<SystemMgr>("SystemMgr");
|
|
80
|
+
if (systemMgr && !systemMgr.supportRequest()) {
|
|
81
|
+
enabled = false;
|
|
82
|
+
LogUtils.Instance.info(AnalyticsMgr.TAG, "本地游戏不支持网络请求,统计禁用");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
78
85
|
|
|
79
86
|
if (enabled) {
|
|
80
87
|
// 从全局获取 SDK 实例(在 game.js 中初始化后挂载到 wx.uma)
|
|
81
88
|
this._sdk = this._getGlobalSDK();
|
|
82
|
-
this._sdkStage = this._sdk?.stage || null;
|
|
83
89
|
this._isEnabled = !!this._sdk;
|
|
84
90
|
} else {
|
|
85
91
|
this._isEnabled = false;
|
|
@@ -139,7 +145,6 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
139
145
|
* 后续所有 trackEvent 调用自动合并这些属性。
|
|
140
146
|
* 合并规则:通用属性与自定义属性同级平铺,自定义属性可覆盖同名通用属性。
|
|
141
147
|
*
|
|
142
|
-
* 注意:仅适用于 trackEvent,不适用于 stage 系列接口。
|
|
143
148
|
* 友盟 SDK 的 setSuperProperty 在小游戏环境不可用,需在框架封装层实现。
|
|
144
149
|
*/
|
|
145
150
|
private _initCommonParams(): void {
|
|
@@ -310,157 +315,6 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
310
315
|
this.trackEvent(AnalyticsEventId.AdClick, params);
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
// ==================== 关卡行为上报(友盟 stage 接口) ====================
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* 关卡开始
|
|
317
|
-
* @param stageId 关卡ID(string类型)
|
|
318
|
-
* @param stageName 关卡名称
|
|
319
|
-
*/
|
|
320
|
-
public stageOnStart(stageId: string, stageName: string): void {
|
|
321
|
-
if (!this._isEnabled || !this._sdkStage) return;
|
|
322
|
-
try {
|
|
323
|
-
this._sdkStage.onStart({ stageId, stageName });
|
|
324
|
-
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡开始", {
|
|
325
|
-
operation: "stageOnStart",
|
|
326
|
-
stageId,
|
|
327
|
-
stageName,
|
|
328
|
-
});
|
|
329
|
-
} catch (e) {
|
|
330
|
-
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
331
|
-
operation: "stageOnStart",
|
|
332
|
-
reason: String(e),
|
|
333
|
-
stageId,
|
|
334
|
-
stageName,
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* 关卡结束
|
|
341
|
-
* @param stageId 关卡ID(string类型)
|
|
342
|
-
* @param stageName 关卡名称
|
|
343
|
-
* @param event 结束结果("complete" | "fail")
|
|
344
|
-
* @param duration 关卡耗时(毫秒,可选)
|
|
345
|
-
*/
|
|
346
|
-
public stageOnEnd(stageId: string, stageName: string, event: StageEventType, duration?: number): void {
|
|
347
|
-
if (!this._isEnabled || !this._sdkStage) return;
|
|
348
|
-
try {
|
|
349
|
-
const params: StageEndParams = { stageId, stageName, event };
|
|
350
|
-
if (duration !== undefined) {
|
|
351
|
-
params._um_sdu = duration;
|
|
352
|
-
}
|
|
353
|
-
this._sdkStage.onEnd(params);
|
|
354
|
-
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡结束", {
|
|
355
|
-
operation: "stageOnEnd",
|
|
356
|
-
stageId,
|
|
357
|
-
stageName,
|
|
358
|
-
event,
|
|
359
|
-
duration,
|
|
360
|
-
});
|
|
361
|
-
} catch (e) {
|
|
362
|
-
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
363
|
-
operation: "stageOnEnd",
|
|
364
|
-
reason: String(e),
|
|
365
|
-
stageId,
|
|
366
|
-
stageName,
|
|
367
|
-
event,
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* 关卡中行为 - 使用道具
|
|
374
|
-
* @param stageId 关卡ID(string类型)
|
|
375
|
-
* @param stageName 关卡名称
|
|
376
|
-
* @param itemName 道具名称
|
|
377
|
-
* @param itemId 道具ID(可选)
|
|
378
|
-
* @param itemCount 道具数量(可选)
|
|
379
|
-
* @param itemMoney 道具单价(可选)
|
|
380
|
-
*/
|
|
381
|
-
public stageOnRunningTools(
|
|
382
|
-
stageId: string,
|
|
383
|
-
stageName: string,
|
|
384
|
-
itemName: string,
|
|
385
|
-
itemId?: string,
|
|
386
|
-
itemCount?: number,
|
|
387
|
-
itemMoney?: number
|
|
388
|
-
): void {
|
|
389
|
-
if (!this._isEnabled || !this._sdkStage) return;
|
|
390
|
-
try {
|
|
391
|
-
const params: StageRunningParams = {
|
|
392
|
-
stageId,
|
|
393
|
-
stageName,
|
|
394
|
-
event: StageRunningEventType.Tools,
|
|
395
|
-
params: { itemName, itemId, itemCount, itemMoney },
|
|
396
|
-
};
|
|
397
|
-
this._sdkStage.onRunning(params);
|
|
398
|
-
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡使用道具", {
|
|
399
|
-
operation: "stageOnRunningTools",
|
|
400
|
-
stageId,
|
|
401
|
-
stageName,
|
|
402
|
-
itemName,
|
|
403
|
-
itemId,
|
|
404
|
-
itemCount,
|
|
405
|
-
itemMoney,
|
|
406
|
-
});
|
|
407
|
-
} catch (e) {
|
|
408
|
-
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
409
|
-
operation: "stageOnRunningTools",
|
|
410
|
-
reason: String(e),
|
|
411
|
-
stageId,
|
|
412
|
-
stageName,
|
|
413
|
-
itemName,
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* 关卡中行为 - 获得奖励
|
|
420
|
-
* @param stageId 关卡ID(string类型)
|
|
421
|
-
* @param stageName 关卡名称
|
|
422
|
-
* @param itemName 奖励名称
|
|
423
|
-
* @param itemId 奖励ID(可选)
|
|
424
|
-
* @param itemCount 奖励数量(可选)
|
|
425
|
-
* @param itemMoney 奖励单价(可选)
|
|
426
|
-
*/
|
|
427
|
-
public stageOnRunningAward(
|
|
428
|
-
stageId: string,
|
|
429
|
-
stageName: string,
|
|
430
|
-
itemName: string,
|
|
431
|
-
itemId?: string,
|
|
432
|
-
itemCount?: number,
|
|
433
|
-
itemMoney?: number
|
|
434
|
-
): void {
|
|
435
|
-
if (!this._isEnabled || !this._sdkStage) return;
|
|
436
|
-
try {
|
|
437
|
-
const params: StageRunningParams = {
|
|
438
|
-
stageId,
|
|
439
|
-
stageName,
|
|
440
|
-
event: StageRunningEventType.Award,
|
|
441
|
-
params: { itemName, itemId, itemCount, itemMoney },
|
|
442
|
-
};
|
|
443
|
-
this._sdkStage.onRunning(params);
|
|
444
|
-
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡获得奖励", {
|
|
445
|
-
operation: "stageOnRunningAward",
|
|
446
|
-
stageId,
|
|
447
|
-
stageName,
|
|
448
|
-
itemName,
|
|
449
|
-
itemId,
|
|
450
|
-
itemCount,
|
|
451
|
-
itemMoney,
|
|
452
|
-
});
|
|
453
|
-
} catch (e) {
|
|
454
|
-
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
455
|
-
operation: "stageOnRunningAward",
|
|
456
|
-
reason: String(e),
|
|
457
|
-
stageId,
|
|
458
|
-
stageName,
|
|
459
|
-
itemName,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
318
|
// ==================== 状态查询 ====================
|
|
465
319
|
|
|
466
320
|
/** 是否已初始化 */
|