drgame-cc 1.0.28 → 1.0.30
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/build-templates/web-mobile/index.html +1 -1
- package/drscript/GameAnalytics.ts +74 -3
- package/drscript/PlatformAdapter.ts +12 -6
- package/drscript/ad-sdk/leaderboard/leaderboard.js +2 -2
- package/drscript/ad-sdk/reporters/superset-lewo.js +19 -4
- package/drscript/ad-sdk/types/interfaces.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionType, Reporter } from "./ad-sdk/ad-sdk";
|
|
1
|
+
import { ActionType, Reporter, IReportItem } from "./ad-sdk/ad-sdk";
|
|
2
2
|
|
|
3
3
|
export enum GameAnalyticsPlatform {
|
|
4
4
|
XiaomiTv = "xiaomi",
|
|
@@ -44,6 +44,9 @@ export default class GameAnalytics {
|
|
|
44
44
|
private static initialized: boolean = false;
|
|
45
45
|
private static loadingReported: boolean = false;
|
|
46
46
|
private static reportedExposures: { [event: string]: boolean } = {};
|
|
47
|
+
private static reportInterval: number = 1000 * 30; // 30秒上报一次
|
|
48
|
+
private static reportMaxSize: number = 50;
|
|
49
|
+
private static reportKey = "game_analytics_report_cache";
|
|
47
50
|
|
|
48
51
|
private static readonly definitions: { [event: string]: AnalyticsEventDefinition } = {
|
|
49
52
|
game_loading: {
|
|
@@ -88,6 +91,19 @@ export default class GameAnalytics {
|
|
|
88
91
|
});
|
|
89
92
|
this.initialized = true;
|
|
90
93
|
if (config.user_id !== undefined) this.setUserId(config.user_id);
|
|
94
|
+
var httpReq = new XMLHttpRequest();
|
|
95
|
+
httpReq.open("GET", 'https://sup.daoran.tv/bi-api/api/config/get');
|
|
96
|
+
httpReq.setRequestHeader("Content-Type", "application/json");
|
|
97
|
+
httpReq.setRequestHeader("Accept", "application/json");
|
|
98
|
+
httpReq.send();
|
|
99
|
+
httpReq.onreadystatechange = () => {
|
|
100
|
+
if (httpReq.readyState === 4 && httpReq.status === 200) {
|
|
101
|
+
console.log("[GameAnalytics] report batch success", httpReq.responseText);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
setInterval(() => {
|
|
105
|
+
this.reportBatchCache();
|
|
106
|
+
}, this.reportInterval);
|
|
91
107
|
} catch (error) {
|
|
92
108
|
console.warn("[GameAnalytics] init failed", error);
|
|
93
109
|
}
|
|
@@ -141,9 +157,64 @@ export default class GameAnalytics {
|
|
|
141
157
|
if (event === AnalyticsEvent.RewardVideoAd) {
|
|
142
158
|
reportItem.ad_request_id = adRequestId || "";
|
|
143
159
|
}
|
|
144
|
-
|
|
160
|
+
var reportCache: IReportItem[] = null;
|
|
161
|
+
const cache = localStorage.getItem(this.reportKey);
|
|
162
|
+
if (cache) {
|
|
163
|
+
reportCache = JSON.parse(cache);
|
|
164
|
+
}
|
|
165
|
+
if (reportCache) {
|
|
166
|
+
reportCache.push(reportItem);
|
|
167
|
+
} else {
|
|
168
|
+
reportCache = [reportItem];
|
|
169
|
+
}
|
|
170
|
+
localStorage.setItem(this.reportKey, JSON.stringify(reportCache));
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.warn("[GameAnalytics] report failed", error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public static reportBatch(
|
|
177
|
+
events: AnalyticsEvent[]
|
|
178
|
+
): void {
|
|
179
|
+
if (!this.initialized) return;
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
var reportArr: IReportItem[] = [];
|
|
183
|
+
for (const e of events) {
|
|
184
|
+
const definition = this.definitions[e];
|
|
185
|
+
const eventName = definition.exposureEventName;
|
|
186
|
+
const reportItem: any = {
|
|
187
|
+
element_position: definition.elementPosition,
|
|
188
|
+
action_type: ActionType.Exposure,
|
|
189
|
+
event_name: eventName,
|
|
190
|
+
};
|
|
191
|
+
reportItem.ad_request_id = "";
|
|
192
|
+
reportArr.push(reportItem);
|
|
193
|
+
}
|
|
194
|
+
Reporter.reportBatch(reportArr);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.warn("[GameAnalytics] report failed", error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private static reportBatchCache(): void {
|
|
201
|
+
if (!this.initialized) return;
|
|
202
|
+
|
|
203
|
+
var reportCache: IReportItem[] = null;
|
|
204
|
+
const cache = localStorage.getItem(this.reportKey);
|
|
205
|
+
if (cache) {
|
|
206
|
+
reportCache = JSON.parse(cache);
|
|
207
|
+
}
|
|
208
|
+
if (!reportCache || reportCache.length === 0) return;
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const reportItem = reportCache.splice(0, this.reportMaxSize);
|
|
212
|
+
Reporter.reportBatch(reportItem);
|
|
145
213
|
} catch (error) {
|
|
146
214
|
console.warn("[GameAnalytics] report failed", error);
|
|
215
|
+
reportCache = [];
|
|
216
|
+
} finally {
|
|
217
|
+
localStorage.setItem(this.reportKey, JSON.stringify(reportCache));
|
|
147
218
|
}
|
|
148
219
|
}
|
|
149
220
|
|
|
@@ -157,4 +228,4 @@ export default class GameAnalytics {
|
|
|
157
228
|
);
|
|
158
229
|
return APP_ITEM_BY_PLATFORM[GameAnalyticsPlatform.XiaomiTv];
|
|
159
230
|
}
|
|
160
|
-
}
|
|
231
|
+
}
|
|
@@ -9,19 +9,17 @@ import ToastManager from "./toast/ToastManager";
|
|
|
9
9
|
import { InternalUitl } from "./InternalUitl";
|
|
10
10
|
/** 平台适配器,名字有点长防止和Platform,Adapter冲突 */
|
|
11
11
|
export class PlatformAdapter {
|
|
12
|
-
private static readonly cpId = "xhbj";
|
|
13
12
|
private static readonly version = "1.0.0";
|
|
14
13
|
private static readonly designWidth = 1920;
|
|
15
14
|
private static readonly designHeight = 1080;
|
|
16
15
|
/** 初始化
|
|
17
16
|
* @param cnName 中文名称
|
|
18
|
-
* @param minigameID 小游戏ID
|
|
17
|
+
* @param minigameID 小游戏ID,文档地址:https://doc.weixin.qq.com/sheet/e3_AcEAlgaLALsCNiuHzH2NOQGCjVc3a?scode=AOcA0AdfAAoSqmh5BfAQIA6AYEAB4&tab=BB08J2
|
|
19
18
|
*/
|
|
20
19
|
public static async init(cnName: string, minigameID: number) {
|
|
21
|
-
var platform = GameAnalyticsPlatform.XiaomiTv;//平台由sdk
|
|
20
|
+
var platform = GameAnalyticsPlatform.XiaomiTv;//平台由sdk后续处理
|
|
22
21
|
var appItem = GameAnalytics.getAppItem(platform);
|
|
23
22
|
var contentId = minigameID.toString();//InternalUitl.getChineseInitials(cnName);
|
|
24
|
-
await ToastManager.Inst.init();
|
|
25
23
|
TvUi.init({
|
|
26
24
|
cpId: contentId,
|
|
27
25
|
version: this.version,
|
|
@@ -71,7 +69,7 @@ export class PlatformAdapter {
|
|
|
71
69
|
content_id: contentId, // 游戏ID(具体乐窝的游戏ID)
|
|
72
70
|
content_title: cnName, // 游戏名(具体的乐窝游戏名)
|
|
73
71
|
});
|
|
74
|
-
|
|
72
|
+
await ToastManager.Inst.init();
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
/**
|
|
@@ -203,7 +201,7 @@ export class PlatformAdapter {
|
|
|
203
201
|
}
|
|
204
202
|
|
|
205
203
|
/**
|
|
206
|
-
* 上报事件
|
|
204
|
+
* 上报事件(缓存)
|
|
207
205
|
* @param event 事件类型
|
|
208
206
|
* @param action 事件操作 曝光or点击 默认点击
|
|
209
207
|
* @param adRequestId 广告请求ID
|
|
@@ -211,4 +209,12 @@ export class PlatformAdapter {
|
|
|
211
209
|
public static report(event: AnalyticsEvent, action: AnalyticsAction = AnalyticsAction.Click, adRequestId?: string) {
|
|
212
210
|
GameAnalytics.report(event, action, adRequestId);
|
|
213
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 批量上报事件(不缓存,只在仅需要曝光多个时用,点击不会同时操作多个可忽略)
|
|
215
|
+
* @param events 事件类型数组
|
|
216
|
+
*/
|
|
217
|
+
public static reportBatch(events: AnalyticsEvent[]) {
|
|
218
|
+
GameAnalytics.reportBatch(events);
|
|
219
|
+
}
|
|
214
220
|
}
|
|
@@ -372,6 +372,7 @@ var supersetLewo = (function () {
|
|
|
372
372
|
xmlhttp.setRequestHeader(headers[i].name, headers[i].value);
|
|
373
373
|
}
|
|
374
374
|
xmlhttp.setRequestHeader('Content-Type', contentType);
|
|
375
|
+
console.log('[supersetLewo 上报数据]', data)
|
|
375
376
|
// 对象转JSON字符串发送
|
|
376
377
|
data = JSON.stringify(data);
|
|
377
378
|
xmlhttp.send(data);
|
|
@@ -421,6 +422,19 @@ var supersetLewo = (function () {
|
|
|
421
422
|
var filledData = [];
|
|
422
423
|
for (var i = 0; i < eventList.length; i++) {
|
|
423
424
|
filledData.push(fillEventDefault(eventList[i]));
|
|
425
|
+
|
|
426
|
+
try {
|
|
427
|
+
var action_type = eventList[i].action_type == '点击' ? 'CLICK' : 'EXPOSURE'
|
|
428
|
+
var eventName = eventList[i].element_position + '_' + action_type
|
|
429
|
+
|
|
430
|
+
aplus_queue.push({
|
|
431
|
+
action: 'aplus.record',
|
|
432
|
+
// 第二个参数事件类型:CLICK / EXPOSURE / PAGE等,常规点击用CLICK
|
|
433
|
+
arguments: [eventName, action_type, eventList[i]]
|
|
434
|
+
});
|
|
435
|
+
} catch (e) {
|
|
436
|
+
console.log("batchReporting-umeng error", e)
|
|
437
|
+
}
|
|
424
438
|
}
|
|
425
439
|
// 组装批量上报报文
|
|
426
440
|
var reportBody = {
|
|
@@ -454,10 +468,11 @@ var supersetLewo = (function () {
|
|
|
454
468
|
device_brand: "", // 手机品牌小写
|
|
455
469
|
device_model: "", // 手机完整型号
|
|
456
470
|
network_type: "", // 蜂窝流量网络
|
|
457
|
-
carrier: "" // 运营商
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
471
|
+
carrier: "", // 运营商
|
|
472
|
+
promotion_flag: "0", //推广标识(ubp接口获取,1表示推广流量,0表示自然流量),
|
|
473
|
+
user_type: "0" //用户身份类型(0游客/1注册用户/2付费用户)
|
|
474
|
+
});
|
|
475
|
+
console.log("initUserInfo", supersetLewo.getUserInfo());*/
|
|
461
476
|
|
|
462
477
|
/**
|
|
463
478
|
* 示例2:单条埋点上报 - 首页曝光事件
|
|
@@ -126,7 +126,7 @@ export interface IAddPointParams {
|
|
|
126
126
|
/** 积分值 */
|
|
127
127
|
point: number;
|
|
128
128
|
/** 扩展数据(JSON 字符串,如 {url, nickname}) */
|
|
129
|
-
|
|
129
|
+
jsonData?: string;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/** 排行榜条目 */
|
|
@@ -138,10 +138,10 @@ export interface IRankItem {
|
|
|
138
138
|
/** 排名 */
|
|
139
139
|
rank: number;
|
|
140
140
|
/** 扩展数据(如头像、昵称) */
|
|
141
|
-
|
|
142
|
-
/** 昵称(从
|
|
141
|
+
jsonData?: string;
|
|
142
|
+
/** 昵称(从 jsonData 解析) */
|
|
143
143
|
nickname?: string;
|
|
144
|
-
/** 头像 URL(从
|
|
144
|
+
/** 头像 URL(从 jsonData 解析) */
|
|
145
145
|
avatar?: string;
|
|
146
146
|
}
|
|
147
147
|
|