@chiyou/minigame-framework 1.3.7 → 1.3.8
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
|
@@ -4,6 +4,8 @@ import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
|
|
|
4
4
|
import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
|
|
5
5
|
import { ScreenInfo } from '../../Definition/SystemDefinition';
|
|
6
6
|
import { AdMgr } from '../../Manager/AdMgr';
|
|
7
|
+
import { ServiceLocator } from '../../Utils/ServiceLocator';
|
|
8
|
+
import type { AnalyticsMgr } from '../../Manager/AnalyticsMgr';
|
|
7
9
|
|
|
8
10
|
class PortalGame {
|
|
9
11
|
pageManager: any;
|
|
@@ -93,6 +95,7 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
|
93
95
|
|
|
94
96
|
private business: WeiXinPlatformBusiness = new WeiXinPlatformBusiness();
|
|
95
97
|
|
|
98
|
+
private analyticsMgr: AnalyticsMgr = null;
|
|
96
99
|
// Common
|
|
97
100
|
public init(): void {
|
|
98
101
|
|
|
@@ -296,11 +299,21 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
|
296
299
|
window["wx"].onShareAppMessage(() => {
|
|
297
300
|
this.isShareActive = true;
|
|
298
301
|
|
|
299
|
-
|
|
302
|
+
let shareParam = {
|
|
300
303
|
title: title,
|
|
301
304
|
imageUrl: imageUrl,
|
|
302
305
|
imageUrlId: templateId,
|
|
303
306
|
query: query,
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
if (this.analyticsMgr === null) {
|
|
310
|
+
this.analyticsMgr = ServiceLocator.Instance.get<AnalyticsMgr>("AnalyticsMgr");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (this.analyticsMgr && this.analyticsMgr.isEnabled) {
|
|
314
|
+
return this.analyticsMgr.trackShare(shareParam);
|
|
315
|
+
} else {
|
|
316
|
+
return shareParam;
|
|
304
317
|
}
|
|
305
318
|
});
|
|
306
319
|
}
|
|
@@ -331,13 +344,24 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
|
|
|
331
344
|
});
|
|
332
345
|
|
|
333
346
|
this.isShareActive = true;
|
|
334
|
-
|
|
335
|
-
|
|
347
|
+
|
|
348
|
+
let shareParam = {
|
|
336
349
|
title: title,
|
|
337
350
|
imageUrl: imageUrl,
|
|
338
351
|
imageUrlId: templateId,
|
|
339
352
|
query: query,
|
|
340
|
-
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
if (this.analyticsMgr === null) {
|
|
356
|
+
this.analyticsMgr = ServiceLocator.Instance.get<AnalyticsMgr>("AnalyticsMgr");
|
|
357
|
+
}
|
|
358
|
+
// onShow回调
|
|
359
|
+
if (this.analyticsMgr && this.analyticsMgr.isEnabled) {
|
|
360
|
+
let data = this.analyticsMgr.trackShare(shareParam);
|
|
361
|
+
window["wx"].shareAppMessage(data);
|
|
362
|
+
} else {
|
|
363
|
+
window["wx"].shareAppMessage(shareParam);
|
|
364
|
+
}
|
|
341
365
|
}
|
|
342
366
|
}
|
|
343
367
|
|
|
@@ -20,6 +20,78 @@ export interface UmengConfig {
|
|
|
20
20
|
|
|
21
21
|
// ==================== SDK 类型声明 ====================
|
|
22
22
|
|
|
23
|
+
/** 关卡结束事件类型 */
|
|
24
|
+
export enum StageEventType {
|
|
25
|
+
/** 关卡完成 */
|
|
26
|
+
Complete = "complete",
|
|
27
|
+
/** 关卡失败 */
|
|
28
|
+
Fail = "fail",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 关卡中行为事件类型 */
|
|
32
|
+
export enum StageRunningEventType {
|
|
33
|
+
/** 使用道具 */
|
|
34
|
+
Tools = "tools",
|
|
35
|
+
/** 获得奖励 */
|
|
36
|
+
Award = "award",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 关卡开始参数 */
|
|
40
|
+
export interface StageStartParams {
|
|
41
|
+
/** 关卡ID(必传,string类型) */
|
|
42
|
+
stageId: string;
|
|
43
|
+
/** 关卡名称(必传) */
|
|
44
|
+
stageName: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 关卡结束参数 */
|
|
48
|
+
export interface StageEndParams {
|
|
49
|
+
/** 关卡ID(必传,string类型) */
|
|
50
|
+
stageId: string;
|
|
51
|
+
/** 关卡名称(必传) */
|
|
52
|
+
stageName: string;
|
|
53
|
+
/** 关卡结束结果(必传,complete/fail) */
|
|
54
|
+
event: StageEventType;
|
|
55
|
+
/** 关卡耗时(毫秒,可选) */
|
|
56
|
+
_um_sdu?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 关卡中行为事件参数 */
|
|
60
|
+
export interface StageRunningParams {
|
|
61
|
+
/** 关卡ID(必传,string类型) */
|
|
62
|
+
stageId: string;
|
|
63
|
+
/** 关卡名称(必传) */
|
|
64
|
+
stageName: string;
|
|
65
|
+
/** 事件类型(必传,tools/award) */
|
|
66
|
+
event: StageRunningEventType;
|
|
67
|
+
/** 事件参数 */
|
|
68
|
+
params?: StageRunningItemParams;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 关卡中行为物品参数 */
|
|
72
|
+
export interface StageRunningItemParams {
|
|
73
|
+
/** 商品/道具名称(必传) */
|
|
74
|
+
itemName: string;
|
|
75
|
+
/** 商品/道具ID(可选) */
|
|
76
|
+
itemId?: string;
|
|
77
|
+
/** 商品/道具数量(可选) */
|
|
78
|
+
itemCount?: number;
|
|
79
|
+
/** 商品/道具单价(可选) */
|
|
80
|
+
itemMoney?: number;
|
|
81
|
+
/** 描述(可选) */
|
|
82
|
+
desc?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 友盟关卡 SDK 接口 */
|
|
86
|
+
export interface UmaStageSDK {
|
|
87
|
+
/** 关卡开始 */
|
|
88
|
+
onStart(params: StageStartParams): void;
|
|
89
|
+
/** 关卡结束 */
|
|
90
|
+
onEnd(params: StageEndParams): void;
|
|
91
|
+
/** 关卡中行为 */
|
|
92
|
+
onRunning(params: StageRunningParams): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
23
95
|
/**
|
|
24
96
|
* 友盟 SDK 接口定义
|
|
25
97
|
*
|
|
@@ -28,6 +100,8 @@ export interface UmengConfig {
|
|
|
28
100
|
* 已移除:revenue, stage, level, rc(插件方法)
|
|
29
101
|
*
|
|
30
102
|
* 使用方式:SDK 在 game.js 中初始化后,通过 wx.uma 全局实例访问
|
|
103
|
+
*
|
|
104
|
+
* 关卡行为上报通过 wx.uma.stage 对象访问
|
|
31
105
|
*/
|
|
32
106
|
export interface UmaSDK {
|
|
33
107
|
/** 恢复会话(onShow 时调用) */
|
|
@@ -52,15 +126,14 @@ export interface UmaSDK {
|
|
|
52
126
|
onShareAppMessage(callback: () => object): void;
|
|
53
127
|
/** 调用分享 */
|
|
54
128
|
shareAppMessage(options: object): void;
|
|
129
|
+
/** 关卡行为上报(stage 对象) */
|
|
130
|
+
stage: UmaStageSDK;
|
|
55
131
|
}
|
|
56
132
|
|
|
57
133
|
// ==================== 预定义事件 ID ====================
|
|
58
134
|
|
|
59
135
|
/** 预定义事件 ID */
|
|
60
136
|
export enum AnalyticsEventId {
|
|
61
|
-
LevelStart = "level_start",
|
|
62
|
-
LevelComplete = "level_complete",
|
|
63
|
-
LevelFail = "level_fail",
|
|
64
137
|
AdShow = "ad_show",
|
|
65
138
|
AdClick = "ad_click",
|
|
66
139
|
AdComplete = "ad_complete",
|
|
@@ -75,7 +148,6 @@ export enum AnalyticsEventId {
|
|
|
75
148
|
|
|
76
149
|
/** 事件参数键名 */
|
|
77
150
|
export enum AnalyticsParamKey {
|
|
78
|
-
Level = "level",
|
|
79
151
|
Score = "score",
|
|
80
152
|
Duration = "duration",
|
|
81
153
|
Reason = "reason",
|
|
@@ -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 } from "../Definition/AnalyticsDefinition";
|
|
6
|
+
import { UmengConfig, EventParams, AnalyticsEventId, AnalyticsParamKey, UmaSDK, UmaStageSDK, StageEventType, StageRunningEventType, StageEndParams, StageRunningParams } from "../Definition/AnalyticsDefinition";
|
|
7
7
|
import { EventMgr } from "./EventMgr";
|
|
8
8
|
import { FrameworkBase } from "../Definition/FrameworkBase";
|
|
9
9
|
|
|
@@ -19,6 +19,8 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
19
19
|
private _isEnabled: boolean = false;
|
|
20
20
|
/** 当前平台对应的 SDK 实例(通过 wx.uma 全局访问) */
|
|
21
21
|
private _sdk: UmaSDK = null;
|
|
22
|
+
/** 关卡 SDK 实例 */
|
|
23
|
+
private _stageSdk: UmaStageSDK = null;
|
|
22
24
|
|
|
23
25
|
onLoad(): void {
|
|
24
26
|
super.onLoad();
|
|
@@ -74,6 +76,7 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
74
76
|
if (enabled) {
|
|
75
77
|
// 从全局获取 SDK 实例(在 game.js 中初始化后挂载到 wx.uma)
|
|
76
78
|
this._sdk = this._getGlobalSDK();
|
|
79
|
+
this._stageSdk = this._sdk?.stage || null;
|
|
77
80
|
this._isEnabled = !!this._sdk;
|
|
78
81
|
} else {
|
|
79
82
|
this._isEnabled = false;
|
|
@@ -223,37 +226,21 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
223
226
|
}
|
|
224
227
|
}
|
|
225
228
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
public trackLevelComplete(level: string | number, score?: number, duration?: number, extraParams?: EventParams): void {
|
|
239
|
-
const params: Record<string, any> = {
|
|
240
|
-
[AnalyticsParamKey.Level]: level,
|
|
241
|
-
...(score !== undefined ? { [AnalyticsParamKey.Score]: score } : {}),
|
|
242
|
-
...(duration !== undefined ? { [AnalyticsParamKey.Duration]: duration } : {}),
|
|
243
|
-
...this._flattenParams(extraParams),
|
|
244
|
-
};
|
|
245
|
-
this.trackEvent(AnalyticsEventId.LevelComplete, params);
|
|
229
|
+
/** 调用友盟 trackShare,返回带统计参数的分享对象 */
|
|
230
|
+
public trackShare(shareOptions: object): object | null {
|
|
231
|
+
if (!this._isEnabled) return null;
|
|
232
|
+
try {
|
|
233
|
+
return this._sdk.trackShare(shareOptions);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
236
|
+
operation: "trackShare",
|
|
237
|
+
reason: String(e),
|
|
238
|
+
});
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
246
241
|
}
|
|
247
242
|
|
|
248
|
-
|
|
249
|
-
public trackLevelFail(level: string | number, reason?: string, extraParams?: EventParams): void {
|
|
250
|
-
const params: Record<string, any> = {
|
|
251
|
-
[AnalyticsParamKey.Level]: level,
|
|
252
|
-
...(reason ? { [AnalyticsParamKey.Reason]: reason } : {}),
|
|
253
|
-
...this._flattenParams(extraParams),
|
|
254
|
-
};
|
|
255
|
-
this.trackEvent(AnalyticsEventId.LevelFail, params);
|
|
256
|
-
}
|
|
243
|
+
// ==================== 游戏特定事件 ====================
|
|
257
244
|
|
|
258
245
|
/** 广告展示 */
|
|
259
246
|
public trackAdShow(adType: string, adId: string, extraParams?: EventParams): void {
|
|
@@ -275,13 +262,155 @@ export class AnalyticsMgr extends BaseMgr {
|
|
|
275
262
|
this.trackEvent(AnalyticsEventId.AdClick, params);
|
|
276
263
|
}
|
|
277
264
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
265
|
+
// ==================== 关卡行为上报(友盟 stage 接口) ====================
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 关卡开始
|
|
269
|
+
* @param stageId 关卡ID(string类型)
|
|
270
|
+
* @param stageName 关卡名称
|
|
271
|
+
*/
|
|
272
|
+
public stageOnStart(stageId: string, stageName: string): void {
|
|
273
|
+
if (!this._isEnabled || !this._stageSdk) return;
|
|
274
|
+
try {
|
|
275
|
+
this._stageSdk.onStart({ stageId, stageName });
|
|
276
|
+
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡开始", {
|
|
277
|
+
operation: "stageOnStart",
|
|
278
|
+
stageId,
|
|
279
|
+
stageName,
|
|
280
|
+
});
|
|
281
|
+
} catch (e) {
|
|
282
|
+
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
283
|
+
operation: "stageOnStart",
|
|
284
|
+
reason: String(e),
|
|
285
|
+
stageId,
|
|
286
|
+
stageName,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 关卡结束
|
|
293
|
+
* @param stageId 关卡ID(string类型)
|
|
294
|
+
* @param stageName 关卡名称
|
|
295
|
+
* @param event 结束结果("complete" | "fail")
|
|
296
|
+
* @param duration 关卡耗时(毫秒,可选)
|
|
297
|
+
*/
|
|
298
|
+
public stageOnEnd(stageId: string, stageName: string, event: StageEventType, duration?: number): void {
|
|
299
|
+
if (!this._isEnabled || !this._stageSdk) return;
|
|
300
|
+
try {
|
|
301
|
+
const params: StageEndParams = { stageId, stageName, event };
|
|
302
|
+
if (duration !== undefined) {
|
|
303
|
+
params._um_sdu = duration;
|
|
304
|
+
}
|
|
305
|
+
this._stageSdk.onEnd(params);
|
|
306
|
+
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡结束", {
|
|
307
|
+
operation: "stageOnEnd",
|
|
308
|
+
stageId,
|
|
309
|
+
stageName,
|
|
310
|
+
event,
|
|
311
|
+
duration,
|
|
312
|
+
});
|
|
313
|
+
} catch (e) {
|
|
314
|
+
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
315
|
+
operation: "stageOnEnd",
|
|
316
|
+
reason: String(e),
|
|
317
|
+
stageId,
|
|
318
|
+
stageName,
|
|
319
|
+
event,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 关卡中行为 - 使用道具
|
|
326
|
+
* @param stageId 关卡ID(string类型)
|
|
327
|
+
* @param stageName 关卡名称
|
|
328
|
+
* @param itemName 道具名称
|
|
329
|
+
* @param itemId 道具ID(可选)
|
|
330
|
+
* @param itemCount 道具数量(可选)
|
|
331
|
+
* @param itemMoney 道具单价(可选)
|
|
332
|
+
*/
|
|
333
|
+
public stageOnRunningTools(
|
|
334
|
+
stageId: string,
|
|
335
|
+
stageName: string,
|
|
336
|
+
itemName: string,
|
|
337
|
+
itemId?: string,
|
|
338
|
+
itemCount?: number,
|
|
339
|
+
itemMoney?: number
|
|
340
|
+
): void {
|
|
341
|
+
if (!this._isEnabled || !this._stageSdk) return;
|
|
342
|
+
try {
|
|
343
|
+
const params: StageRunningParams = {
|
|
344
|
+
stageId,
|
|
345
|
+
stageName,
|
|
346
|
+
event: StageRunningEventType.Tools,
|
|
347
|
+
params: { itemName, itemId, itemCount, itemMoney },
|
|
348
|
+
};
|
|
349
|
+
this._stageSdk.onRunning(params);
|
|
350
|
+
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡使用道具", {
|
|
351
|
+
operation: "stageOnRunningTools",
|
|
352
|
+
stageId,
|
|
353
|
+
stageName,
|
|
354
|
+
itemName,
|
|
355
|
+
itemId,
|
|
356
|
+
itemCount,
|
|
357
|
+
itemMoney,
|
|
358
|
+
});
|
|
359
|
+
} catch (e) {
|
|
360
|
+
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
361
|
+
operation: "stageOnRunningTools",
|
|
362
|
+
reason: String(e),
|
|
363
|
+
stageId,
|
|
364
|
+
stageName,
|
|
365
|
+
itemName,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 关卡中行为 - 获得奖励
|
|
372
|
+
* @param stageId 关卡ID(string类型)
|
|
373
|
+
* @param stageName 关卡名称
|
|
374
|
+
* @param itemName 奖励名称
|
|
375
|
+
* @param itemId 奖励ID(可选)
|
|
376
|
+
* @param itemCount 奖励数量(可选)
|
|
377
|
+
* @param itemMoney 奖励单价(可选)
|
|
378
|
+
*/
|
|
379
|
+
public stageOnRunningAward(
|
|
380
|
+
stageId: string,
|
|
381
|
+
stageName: string,
|
|
382
|
+
itemName: string,
|
|
383
|
+
itemId?: string,
|
|
384
|
+
itemCount?: number,
|
|
385
|
+
itemMoney?: number
|
|
386
|
+
): void {
|
|
387
|
+
if (!this._isEnabled || !this._stageSdk) return;
|
|
388
|
+
try {
|
|
389
|
+
const params: StageRunningParams = {
|
|
390
|
+
stageId,
|
|
391
|
+
stageName,
|
|
392
|
+
event: StageRunningEventType.Award,
|
|
393
|
+
params: { itemName, itemId, itemCount, itemMoney },
|
|
394
|
+
};
|
|
395
|
+
this._stageSdk.onRunning(params);
|
|
396
|
+
LogUtils.Instance.info(AnalyticsMgr.TAG, "关卡获得奖励", {
|
|
397
|
+
operation: "stageOnRunningAward",
|
|
398
|
+
stageId,
|
|
399
|
+
stageName,
|
|
400
|
+
itemName,
|
|
401
|
+
itemId,
|
|
402
|
+
itemCount,
|
|
403
|
+
itemMoney,
|
|
404
|
+
});
|
|
405
|
+
} catch (e) {
|
|
406
|
+
LogUtils.Instance.error(AnalyticsMgr.TAG, FwkErrorCode.Analytics.SDKCallFailed, {
|
|
407
|
+
operation: "stageOnRunningAward",
|
|
408
|
+
reason: String(e),
|
|
409
|
+
stageId,
|
|
410
|
+
stageName,
|
|
411
|
+
itemName,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
285
414
|
}
|
|
286
415
|
|
|
287
416
|
// ==================== 状态查询 ====================
|