@chiyou/minigame-framework 1.4.1 → 1.4.3
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/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.ts +34 -5
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts +13 -33
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts +13 -11
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts +13 -49
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts +11 -10
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts +11 -10
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts +46 -34
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts +11 -10
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts +13 -12
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts +11 -10
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts +13 -47
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts +12 -11
- package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts +13 -42
- package/src/Framework/Definition/AnalyticsDefinition.ts +99 -23
- package/src/Framework/Manager/AnalyticsMgr.ts +155 -17
- package/src/Framework/Manager/LifeCycleMgr.ts +28 -31
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbsPlatformAdapter } from './AbsPlatformAdapter';
|
|
2
|
+
import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
|
|
2
3
|
import { LogUtils } from '../../Utils/LogUtils';
|
|
3
4
|
import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
|
|
4
5
|
import { ScreenInfo } from '../../Definition/SystemDefinition';
|
|
@@ -6,6 +7,15 @@ import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
|
|
|
6
7
|
|
|
7
8
|
export class PlatformAdapterVivo extends AbsPlatformAdapter {
|
|
8
9
|
static TAG: string = "PlatformAdapterVivo";
|
|
10
|
+
protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
|
|
11
|
+
[LaunchCategory.RecentUse, new Set([])],
|
|
12
|
+
[LaunchCategory.Desktop, new Set([])],
|
|
13
|
+
[LaunchCategory.Search, new Set([])],
|
|
14
|
+
[LaunchCategory.Chat, new Set([])],
|
|
15
|
+
[LaunchCategory.Share, new Set([])],
|
|
16
|
+
[LaunchCategory.Ad, new Set([])],
|
|
17
|
+
[LaunchCategory.Other, new Set([])],
|
|
18
|
+
]);
|
|
9
19
|
|
|
10
20
|
// Common
|
|
11
21
|
public init(): void {
|
|
@@ -279,7 +289,7 @@ export class PlatformAdapterVivo extends AbsPlatformAdapter {
|
|
|
279
289
|
|
|
280
290
|
public onGameColdStart(): void {
|
|
281
291
|
this.coldStartOptions = null;
|
|
282
|
-
this.
|
|
292
|
+
this._coldStartScene = "";
|
|
283
293
|
}
|
|
284
294
|
|
|
285
295
|
public onGameShowCallback(warmStartOptions: any): void {
|
|
@@ -331,17 +341,8 @@ export class PlatformAdapterVivo extends AbsPlatformAdapter {
|
|
|
331
341
|
|
|
332
342
|
}
|
|
333
343
|
|
|
334
|
-
public isLaunchFromRecentUse(): boolean {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
344
|
|
|
338
|
-
public isLaunchFromDesktopShortcut(): boolean {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
345
|
|
|
342
|
-
public isLaunchFromAdvertisement(): boolean {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
346
|
|
|
346
347
|
public checkSession(callback: (isValid: boolean) => void): void {
|
|
347
348
|
// Vivo不支持这个方法,直接返回true
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbsPlatformAdapter } from './AbsPlatformAdapter';
|
|
2
|
+
import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
|
|
2
3
|
import { LogUtils } from '../../Utils/LogUtils';
|
|
3
4
|
import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
|
|
4
5
|
import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
|
|
@@ -87,6 +88,15 @@ class WeiXinPlatformBusiness {
|
|
|
87
88
|
export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
88
89
|
|
|
89
90
|
static TAG: string = "PlatformAdapterWeiXin";
|
|
91
|
+
protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
|
|
92
|
+
[LaunchCategory.RecentUse, new Set(["1001", "1089", "1090", "1256", "1271"])],
|
|
93
|
+
[LaunchCategory.Desktop, new Set(["1023", "1113", "1114", "1223"])],
|
|
94
|
+
[LaunchCategory.Search, new Set(["1005", "1006", "1027", "1053", "1106", "1183"])],
|
|
95
|
+
[LaunchCategory.Chat, new Set(["1007", "1008", "1036", "1096"])],
|
|
96
|
+
[LaunchCategory.Share, new Set(["1044", "1073", "1074"])],
|
|
97
|
+
[LaunchCategory.Ad, new Set(["1045", "1046", "1067", "1084", "1095", "1200", "1201", "1228", "1232", "1238", "1274", "1295", "1387"])],
|
|
98
|
+
[LaunchCategory.Other, new Set([])],
|
|
99
|
+
]);
|
|
90
100
|
|
|
91
101
|
private portalGame: PortalGame = new PortalGame();
|
|
92
102
|
private gameClub: GameClub = new GameClub();
|
|
@@ -503,18 +513,18 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
|
503
513
|
|
|
504
514
|
public onGameColdStart(): void {
|
|
505
515
|
this.coldStartOptions = null;
|
|
506
|
-
this.
|
|
516
|
+
this._coldStartScene = "";
|
|
507
517
|
|
|
508
518
|
if (window["wx"] && window["wx"].getLaunchOptionsSync) {
|
|
509
519
|
this.coldStartOptions = window["wx"].getLaunchOptionsSync();
|
|
510
520
|
if (this.coldStartOptions !== null && this.coldStartOptions["scene"]) {
|
|
511
|
-
this.
|
|
521
|
+
this._coldStartScene = this.coldStartOptions["scene"].toString();
|
|
512
522
|
}
|
|
513
523
|
}
|
|
514
524
|
|
|
515
525
|
LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "冷启动场景更新", {
|
|
516
526
|
operation: "updateColdStartScene",
|
|
517
|
-
scene: this.
|
|
527
|
+
scene: this._coldStartScene
|
|
518
528
|
});
|
|
519
529
|
}
|
|
520
530
|
|
|
@@ -576,52 +586,8 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
|
576
586
|
|
|
577
587
|
}
|
|
578
588
|
|
|
579
|
-
public isLaunchFromRecentUse(): boolean {
|
|
580
|
-
let recentUseSceneSet: Set<string> = new Set<string>([
|
|
581
|
-
"1001",
|
|
582
|
-
"1089",
|
|
583
|
-
"1256",
|
|
584
|
-
"1103",
|
|
585
|
-
"1104",
|
|
586
|
-
"1257",
|
|
587
|
-
]);
|
|
588
|
-
|
|
589
|
-
let isLaunchFromRecentUse: boolean = recentUseSceneSet.has(this.coldStartScene) || recentUseSceneSet.has(this.warmStartScene);
|
|
590
|
-
LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否最近使用启动", {
|
|
591
|
-
operation: "isLaunchFromRecentUse",
|
|
592
|
-
result: isLaunchFromRecentUse
|
|
593
|
-
});
|
|
594
|
-
return isLaunchFromRecentUse;
|
|
595
|
-
}
|
|
596
589
|
|
|
597
|
-
public isLaunchFromDesktopShortcut(): boolean {
|
|
598
|
-
let desktopShortcutSceneSet: Set<string> = new Set<string>([
|
|
599
|
-
"1023",
|
|
600
|
-
"1223",
|
|
601
|
-
]);
|
|
602
590
|
|
|
603
|
-
let isLaunchFromDesktopShortcut: boolean = desktopShortcutSceneSet.has(this.coldStartScene) || desktopShortcutSceneSet.has(this.warmStartScene);
|
|
604
|
-
LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否桌面快捷方式启动", {
|
|
605
|
-
operation: "isLaunchFromDesktopShortcut",
|
|
606
|
-
result: isLaunchFromDesktopShortcut
|
|
607
|
-
});
|
|
608
|
-
return isLaunchFromDesktopShortcut;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
public isLaunchFromAdvertisement(): boolean {
|
|
612
|
-
let advertisementSceneSet: Set<string> = new Set<string>([
|
|
613
|
-
"1045", "1046", "1067", "1068", "1084", "1095",
|
|
614
|
-
"1189", "1200", "1201", "1215", "1228", "1230",
|
|
615
|
-
"1232", "1238", "1274", "1295",
|
|
616
|
-
]);
|
|
617
|
-
|
|
618
|
-
let isLaunchFromAdvertisement: boolean = advertisementSceneSet.has(this.coldStartScene);
|
|
619
|
-
LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否广告启动", {
|
|
620
|
-
operation: "isLaunchFromAdvertisement",
|
|
621
|
-
result: isLaunchFromAdvertisement
|
|
622
|
-
});
|
|
623
|
-
return isLaunchFromAdvertisement;
|
|
624
|
-
}
|
|
625
591
|
|
|
626
592
|
public checkSession(callback: (isValid: boolean) => void): void {
|
|
627
593
|
if (window["wx"] && window["wx"].checkSession) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbsPlatformAdapter } from './AbsPlatformAdapter';
|
|
2
|
+
import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
|
|
2
3
|
import { LogUtils } from '../../Utils/LogUtils';
|
|
3
4
|
import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
|
|
4
5
|
import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
|
|
@@ -7,6 +8,15 @@ import { ScreenInfo } from '../../Definition/SystemDefinition';
|
|
|
7
8
|
export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
|
|
8
9
|
|
|
9
10
|
static TAG: string = "PlatformAdapterXiaoMi";
|
|
11
|
+
protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
|
|
12
|
+
[LaunchCategory.RecentUse, new Set([])],
|
|
13
|
+
[LaunchCategory.Desktop, new Set([])],
|
|
14
|
+
[LaunchCategory.Search, new Set([])],
|
|
15
|
+
[LaunchCategory.Chat, new Set([])],
|
|
16
|
+
[LaunchCategory.Share, new Set([])],
|
|
17
|
+
[LaunchCategory.Ad, new Set([])],
|
|
18
|
+
[LaunchCategory.Other, new Set([])],
|
|
19
|
+
]);
|
|
10
20
|
|
|
11
21
|
// Common
|
|
12
22
|
public init(): void {
|
|
@@ -284,11 +294,11 @@ export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
|
|
|
284
294
|
|
|
285
295
|
public onGameColdStart(): void {
|
|
286
296
|
this.coldStartOptions = null;
|
|
287
|
-
this.
|
|
297
|
+
this._coldStartScene = "";
|
|
288
298
|
|
|
289
299
|
LogUtils.Instance.info(PlatformAdapterXiaoMi.TAG, "冷启动场景更新", {
|
|
290
300
|
operation: "updateColdStartScene",
|
|
291
|
-
scene: this.
|
|
301
|
+
scene: this._coldStartScene
|
|
292
302
|
});
|
|
293
303
|
}
|
|
294
304
|
|
|
@@ -346,17 +356,8 @@ export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
|
|
|
346
356
|
|
|
347
357
|
}
|
|
348
358
|
|
|
349
|
-
public isLaunchFromRecentUse(): boolean {
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
359
|
|
|
353
|
-
public isLaunchFromDesktopShortcut(): boolean {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
360
|
|
|
357
|
-
public isLaunchFromAdvertisement(): boolean {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
361
|
|
|
361
362
|
public checkSession(callback: (isValid: boolean) => void): void {
|
|
362
363
|
// XiaoMi不支持这个方法,直接返回true
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbsPlatformAdapter } from './AbsPlatformAdapter';
|
|
2
|
+
import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
|
|
2
3
|
import { LogUtils } from '../../Utils/LogUtils';
|
|
3
4
|
import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
|
|
4
5
|
import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
|
|
@@ -7,6 +8,15 @@ import { ScreenInfo } from '../../Definition/SystemDefinition';
|
|
|
7
8
|
export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
|
|
8
9
|
|
|
9
10
|
static TAG: string = "PlatformAdapterZhiFuBao";
|
|
11
|
+
protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
|
|
12
|
+
[LaunchCategory.RecentUse, new Set(["1000", "1001", "1002", "1003"])],
|
|
13
|
+
[LaunchCategory.Desktop, new Set(["1023"])],
|
|
14
|
+
[LaunchCategory.Search, new Set([])],
|
|
15
|
+
[LaunchCategory.Chat, new Set([])],
|
|
16
|
+
[LaunchCategory.Share, new Set([])],
|
|
17
|
+
[LaunchCategory.Ad, new Set(["1400"])],
|
|
18
|
+
[LaunchCategory.Other, new Set([])],
|
|
19
|
+
]);
|
|
10
20
|
|
|
11
21
|
// Common
|
|
12
22
|
public init(): void {
|
|
@@ -314,18 +324,18 @@ export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
|
|
|
314
324
|
|
|
315
325
|
public onGameColdStart(): void {
|
|
316
326
|
this.coldStartOptions = null;
|
|
317
|
-
this.
|
|
327
|
+
this._coldStartScene = "";
|
|
318
328
|
|
|
319
329
|
if (window["my"] && window["my"].getLaunchOptionsSync) {
|
|
320
330
|
this.coldStartOptions = window["my"].getLaunchOptionsSync();
|
|
321
331
|
if (this.coldStartOptions !== null && this.coldStartOptions["scene"]) {
|
|
322
|
-
this.
|
|
332
|
+
this._coldStartScene = this.coldStartOptions["scene"];
|
|
323
333
|
}
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "冷启动场景更新", {
|
|
327
337
|
operation: "updateColdStartScene",
|
|
328
|
-
scene: this.
|
|
338
|
+
scene: this._coldStartScene
|
|
329
339
|
});
|
|
330
340
|
}
|
|
331
341
|
|
|
@@ -387,47 +397,8 @@ export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
|
|
|
387
397
|
|
|
388
398
|
}
|
|
389
399
|
|
|
390
|
-
public isLaunchFromRecentUse(): boolean {
|
|
391
|
-
let recentUseSceneSet: Set<string> = new Set<string>([
|
|
392
|
-
"1000",
|
|
393
|
-
"1001",
|
|
394
|
-
"1002",
|
|
395
|
-
"1003",
|
|
396
|
-
]);
|
|
397
400
|
|
|
398
|
-
let isLaunchFromRecentUse: boolean = recentUseSceneSet.has(this.coldStartScene) || recentUseSceneSet.has(this.warmStartScene);
|
|
399
|
-
LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否最近使用启动", {
|
|
400
|
-
operation: "isLaunchFromRecentUse",
|
|
401
|
-
result: isLaunchFromRecentUse
|
|
402
|
-
});
|
|
403
|
-
return isLaunchFromRecentUse;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
public isLaunchFromDesktopShortcut(): boolean {
|
|
407
|
-
let desktopShortcutSceneSet: Set<string> = new Set<string>([
|
|
408
|
-
"1023",
|
|
409
|
-
]);
|
|
410
401
|
|
|
411
|
-
let isLaunchFromDesktopShortcut: boolean = desktopShortcutSceneSet.has(this.coldStartScene) || desktopShortcutSceneSet.has(this.warmStartScene);
|
|
412
|
-
LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否桌面快捷方式启动", {
|
|
413
|
-
operation: "isLaunchFromDesktopShortcut",
|
|
414
|
-
result: isLaunchFromDesktopShortcut
|
|
415
|
-
});
|
|
416
|
-
return isLaunchFromDesktopShortcut;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
public isLaunchFromAdvertisement(): boolean {
|
|
420
|
-
let advertisementSceneSet: Set<string> = new Set<string>([
|
|
421
|
-
"1400",
|
|
422
|
-
]);
|
|
423
|
-
|
|
424
|
-
let isLaunchFromAdvertisement: boolean = advertisementSceneSet.has(this.coldStartScene);
|
|
425
|
-
LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否广告启动", {
|
|
426
|
-
operation: "isLaunchFromAdvertisement",
|
|
427
|
-
result: isLaunchFromAdvertisement
|
|
428
|
-
});
|
|
429
|
-
return isLaunchFromAdvertisement;
|
|
430
|
-
}
|
|
431
402
|
|
|
432
403
|
public checkSession(callback: (isValid: boolean) => void): void {
|
|
433
404
|
// ZhiFuBao不支持这个方法,直接返回true
|
|
@@ -66,35 +66,111 @@ export interface UmaSDK {
|
|
|
66
66
|
shareAppMessage(options: object): void;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// ====================
|
|
69
|
+
// ==================== 事件 ID 与参数 ====================
|
|
70
70
|
|
|
71
|
-
/**
|
|
71
|
+
/** 事件 ID(按业务分类) */
|
|
72
72
|
export enum AnalyticsEventId {
|
|
73
|
+
// ==================== 留存 ====================
|
|
74
|
+
/** 游戏启动(DAU / 留存基数) */
|
|
75
|
+
GameLaunch = "game_launch",
|
|
76
|
+
|
|
77
|
+
// ==================== 关卡 ====================
|
|
78
|
+
/** 关卡开始 */
|
|
79
|
+
StageStart = "stage_start",
|
|
80
|
+
/** 关卡结束(成功 / 失败 / 放弃) */
|
|
81
|
+
StageEnd = "stage_end",
|
|
82
|
+
/** 复活成功 */
|
|
83
|
+
StageRevive = "stage_revive",
|
|
84
|
+
|
|
85
|
+
// ==================== 广告 ====================
|
|
86
|
+
/** 广告加载成功 */
|
|
87
|
+
AdLoadSuccess = "ad_load_success",
|
|
88
|
+
/** 广告加载失败 */
|
|
89
|
+
AdLoadError = "ad_load_error",
|
|
90
|
+
/** 广告展示 */
|
|
73
91
|
AdShow = "ad_show",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
/** 广告观看完成(isEnded=true) */
|
|
93
|
+
AdShowComplete = "ad_show_complete",
|
|
94
|
+
/** 广告跳过(isEnded=false) */
|
|
95
|
+
AdShowSkip = "ad_show_skip",
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 关卡结束结果 */
|
|
99
|
+
export enum StageResult {
|
|
100
|
+
Success = "success",
|
|
101
|
+
Fail = "fail",
|
|
102
|
+
Abandon = "abandon",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 复活方式 */
|
|
106
|
+
export enum ReviveMethod {
|
|
107
|
+
/** 广告复活 */
|
|
108
|
+
Ad = "ad",
|
|
109
|
+
/** 道具复活 */
|
|
110
|
+
Item = "item",
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 启动场景分类 */
|
|
114
|
+
export enum LaunchCategory {
|
|
115
|
+
/** 最近使用/我的小程序 */
|
|
116
|
+
RecentUse = "recent",
|
|
117
|
+
/** 桌面图标/快捷方式 */
|
|
118
|
+
Desktop = "desktop",
|
|
119
|
+
/** 搜索 */
|
|
120
|
+
Search = "search",
|
|
121
|
+
/** 聊天消息卡片 */
|
|
122
|
+
Chat = "chat",
|
|
123
|
+
/** 分享卡片 */
|
|
79
124
|
Share = "share",
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
125
|
+
/** 广告 */
|
|
126
|
+
Ad = "ad",
|
|
127
|
+
/** 其他/未知 */
|
|
128
|
+
Other = "other",
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 冷启动场景信息 */
|
|
132
|
+
export interface LaunchSceneInfo {
|
|
133
|
+
/** 原始场景值 */
|
|
134
|
+
scene: string;
|
|
135
|
+
/** 归并后的场景分类 */
|
|
136
|
+
category: LaunchCategory;
|
|
83
137
|
}
|
|
84
138
|
|
|
85
|
-
/**
|
|
139
|
+
/** 事件参数键名(按业务分类) */
|
|
86
140
|
export enum AnalyticsParamKey {
|
|
87
|
-
|
|
141
|
+
// ==================== 通用 ====================
|
|
142
|
+
/** 时长(毫秒),关卡耗时等通用场景 */
|
|
88
143
|
Duration = "duration",
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
144
|
+
|
|
145
|
+
// ==================== 留存 ====================
|
|
146
|
+
/** 原始启动场景值 */
|
|
147
|
+
LaunchScene = "launch_scene",
|
|
148
|
+
/** 归并后的场景分类 */
|
|
149
|
+
LaunchCategory = "launch_category",
|
|
150
|
+
/** 启动小时(0-23) */
|
|
151
|
+
LaunchHour = "launch_hour",
|
|
152
|
+
|
|
153
|
+
// ==================== 关卡 ====================
|
|
154
|
+
/** 关卡ID */
|
|
155
|
+
StageId = "stage_id",
|
|
156
|
+
/** 关卡名称 */
|
|
157
|
+
StageName = "stage_name",
|
|
158
|
+
/** 是否首次进入(1=首次, 0=重玩) */
|
|
159
|
+
IsFirst = "is_first",
|
|
160
|
+
/** 关卡结束结果(success / fail / abandon) */
|
|
161
|
+
Result = "result",
|
|
162
|
+
/** 关卡进度(0-1) */
|
|
163
|
+
Progress = "progress",
|
|
164
|
+
/** 是否复活后通关(1=是, 0=否) */
|
|
165
|
+
IsRevived = "is_revived",
|
|
166
|
+
/** 复活方式(ad / item) */
|
|
167
|
+
Method = "method",
|
|
168
|
+
|
|
169
|
+
// ==================== 广告 ====================
|
|
170
|
+
/** 广告场景(业务自定义,如 revive / daily_bonus) */
|
|
171
|
+
AdScene = "ad_scene",
|
|
172
|
+
/** 广告错误码 */
|
|
173
|
+
ErrCode = "err_code",
|
|
174
|
+
/** 广告错误信息 */
|
|
175
|
+
ErrMsg = "err_msg",
|
|
100
176
|
}
|
|
@@ -3,7 +3,7 @@ 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, CommonParams } from "../Definition/AnalyticsDefinition";
|
|
6
|
+
import { UmengConfig, EventParams, AnalyticsEventId, AnalyticsParamKey, StageResult, ReviveMethod, LaunchCategory, UmaSDK, CommonParams } from "../Definition/AnalyticsDefinition";
|
|
7
7
|
import { EventMgr } from "./EventMgr";
|
|
8
8
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
9
9
|
import type { SystemMgr } from "./SystemMgr";
|
|
@@ -23,6 +23,12 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
23
23
|
/** 通用属性(trackEvent 自动合并) */
|
|
24
24
|
private _commonParams: CommonParams = null;
|
|
25
25
|
|
|
26
|
+
/** 当前会话已进入过的关卡(用于 is_first 判重) */
|
|
27
|
+
private _sessionEnteredStages: Set<string> = new Set();
|
|
28
|
+
|
|
29
|
+
/** 各关卡的开始时间戳(用于自动计算 duration) */
|
|
30
|
+
private _stageStartTimestamps: Map<string, number> = new Map();
|
|
31
|
+
|
|
26
32
|
onLoad(): void {
|
|
27
33
|
super.onLoad();
|
|
28
34
|
|
|
@@ -295,24 +301,156 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
295
301
|
|
|
296
302
|
// ==================== 游戏特定事件 ====================
|
|
297
303
|
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
/**
|
|
305
|
+
* 关卡开始上报
|
|
306
|
+
* 自动判重,is_first=1 仅在该用户当前会话内首次进入该关卡时上报。
|
|
307
|
+
* 同时记录开始时间戳,供 stageTrackEnd 自动计算 duration。
|
|
308
|
+
* @param stageId 关卡ID(必传)
|
|
309
|
+
* @param stageName 关卡名称(必传)
|
|
310
|
+
*/
|
|
311
|
+
public stageTrackStart(stageId: string, stageName: string): void {
|
|
312
|
+
if (!this._isEnabled) return;
|
|
313
|
+
|
|
314
|
+
const isFirst = this._sessionEnteredStages.has(stageId) ? 0 : 1;
|
|
315
|
+
if (isFirst === 1) {
|
|
316
|
+
this._sessionEnteredStages.add(stageId);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 记录开始时间戳(毫秒)
|
|
320
|
+
this._stageStartTimestamps.set(stageId, Date.now());
|
|
321
|
+
|
|
322
|
+
this.trackEvent(AnalyticsEventId.StageStart, {
|
|
323
|
+
[AnalyticsParamKey.StageId]: stageId,
|
|
324
|
+
[AnalyticsParamKey.StageName]: stageName,
|
|
325
|
+
[AnalyticsParamKey.IsFirst]: isFirst,
|
|
326
|
+
});
|
|
306
327
|
}
|
|
307
328
|
|
|
308
|
-
/**
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
329
|
+
/**
|
|
330
|
+
* 关卡结束上报
|
|
331
|
+
* 规则:只有“最终结局”才上报。复活成功后的关卡仍在进行中,不报 stage_end。
|
|
332
|
+
* duration 由框架自动计算(当前时间戳 - stageTrackStart 记录的时间戳)。
|
|
333
|
+
* @param stageId 关卡ID
|
|
334
|
+
* @param result 结果:success / fail / abandon
|
|
335
|
+
* @param progress 关卡进度(0-1),成功时=1
|
|
336
|
+
* @param isRevived 是否为复活后通关(0=原始,1=复活后),默认 0
|
|
337
|
+
*/
|
|
338
|
+
public stageTrackEnd(
|
|
339
|
+
stageId: string,
|
|
340
|
+
result: StageResult,
|
|
341
|
+
progress: number,
|
|
342
|
+
isRevived: number = 0,
|
|
343
|
+
): void {
|
|
344
|
+
if (!this._isEnabled) return;
|
|
345
|
+
|
|
346
|
+
// 自动计算 duration(毫秒)
|
|
347
|
+
const startTs = this._stageStartTimestamps.get(stageId);
|
|
348
|
+
const duration = startTs ? Date.now() - startTs : 0;
|
|
349
|
+
// 上报后清除,避免内存泄漏
|
|
350
|
+
this._stageStartTimestamps.delete(stageId);
|
|
351
|
+
|
|
352
|
+
this.trackEvent(AnalyticsEventId.StageEnd, {
|
|
353
|
+
[AnalyticsParamKey.StageId]: stageId,
|
|
354
|
+
[AnalyticsParamKey.Result]: result,
|
|
355
|
+
[AnalyticsParamKey.Duration]: duration,
|
|
356
|
+
[AnalyticsParamKey.Progress]: progress,
|
|
357
|
+
[AnalyticsParamKey.IsRevived]: isRevived,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 复活成功上报
|
|
363
|
+
* 触发时机:玩家选择复活(看广告或使用道具)并成功复活后上报一次。
|
|
364
|
+
* 复活前的失败不报 stage_end(还未到最终结局)。
|
|
365
|
+
* @param stageId 关卡ID
|
|
366
|
+
* @param method 复活方式
|
|
367
|
+
*/
|
|
368
|
+
public stageTrackRevive(stageId: string, method: ReviveMethod): void {
|
|
369
|
+
if (!this._isEnabled) return;
|
|
370
|
+
|
|
371
|
+
this.trackEvent(AnalyticsEventId.StageRevive, {
|
|
372
|
+
[AnalyticsParamKey.StageId]: stageId,
|
|
373
|
+
[AnalyticsParamKey.Method]: method,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ==================== 留存事件 ====================
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* 游戏启动上报(DAU / 留存基数)
|
|
381
|
+
* 由 LifeCycleMgr.onGameColdStart() 自动调用,业务层无需手动上报。
|
|
382
|
+
* @param launchScene 原始启动场景值
|
|
383
|
+
* @param launchCategory 归并后的场景分类
|
|
384
|
+
* @param launchHour 启动小时(0-23)
|
|
385
|
+
*/
|
|
386
|
+
public trackGameLaunch(launchScene: string, launchCategory: LaunchCategory, launchHour: number): void {
|
|
387
|
+
if (!this._isEnabled) return;
|
|
388
|
+
this.trackEvent(AnalyticsEventId.GameLaunch, {
|
|
389
|
+
[AnalyticsParamKey.LaunchScene]: launchScene,
|
|
390
|
+
[AnalyticsParamKey.LaunchCategory]: launchCategory,
|
|
391
|
+
[AnalyticsParamKey.LaunchHour]: launchHour,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ==================== 广告事件 ====================
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 广告加载成功
|
|
399
|
+
* @param adScene 广告场景(业务自定义,如 revive / daily_bonus)
|
|
400
|
+
*/
|
|
401
|
+
public trackAdLoadSuccess(adScene: string): void {
|
|
402
|
+
if (!this._isEnabled) return;
|
|
403
|
+
this.trackEvent(AnalyticsEventId.AdLoadSuccess, {
|
|
404
|
+
[AnalyticsParamKey.AdScene]: adScene,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 广告加载失败
|
|
410
|
+
* @param adScene 广告场景
|
|
411
|
+
* @param errCode 错误码
|
|
412
|
+
* @param errMsg 错误信息
|
|
413
|
+
*/
|
|
414
|
+
public trackAdLoadError(adScene: string, errCode: number, errMsg: string): void {
|
|
415
|
+
if (!this._isEnabled) return;
|
|
416
|
+
this.trackEvent(AnalyticsEventId.AdLoadError, {
|
|
417
|
+
[AnalyticsParamKey.AdScene]: adScene,
|
|
418
|
+
[AnalyticsParamKey.ErrCode]: errCode,
|
|
419
|
+
[AnalyticsParamKey.ErrMsg]: errMsg,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 广告展示成功
|
|
425
|
+
* @param adScene 广告场景
|
|
426
|
+
*/
|
|
427
|
+
public trackAdShow(adScene: string): void {
|
|
428
|
+
if (!this._isEnabled) return;
|
|
429
|
+
this.trackEvent(AnalyticsEventId.AdShow, {
|
|
430
|
+
[AnalyticsParamKey.AdScene]: adScene,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 广告观看完成(isEnded=true)
|
|
436
|
+
* @param adScene 广告场景
|
|
437
|
+
*/
|
|
438
|
+
public trackAdShowComplete(adScene: string): void {
|
|
439
|
+
if (!this._isEnabled) return;
|
|
440
|
+
this.trackEvent(AnalyticsEventId.AdShowComplete, {
|
|
441
|
+
[AnalyticsParamKey.AdScene]: adScene,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* 广告跳过(isEnded=false)
|
|
447
|
+
* @param adScene 广告场景
|
|
448
|
+
*/
|
|
449
|
+
public trackAdShowSkip(adScene: string): void {
|
|
450
|
+
if (!this._isEnabled) return;
|
|
451
|
+
this.trackEvent(AnalyticsEventId.AdShowSkip, {
|
|
452
|
+
[AnalyticsParamKey.AdScene]: adScene,
|
|
453
|
+
});
|
|
316
454
|
}
|
|
317
455
|
|
|
318
456
|
// ==================== 状态查询 ====================
|