drgame-cc 1.0.62 → 1.0.64
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 +417 -0
- package/drscript/ad-sdk/ad-sdk.ts.meta +10 -0
- package/drscript/ad-sdk/adapters/xiaomi-adapter.ts +497 -0
- package/drscript/ad-sdk/adapters/{xiaomi-adapter.js.meta → xiaomi-adapter.ts.meta} +9 -9
- 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 +228 -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} +63 -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,464 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sup 上报底层脚本 - 设备标识 & 批量埋点上报
|
|
3
|
+
* 使用方式:import supersetLewo from './superset-lewo';
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// 兼容 globalThis 缺失的环境
|
|
7
|
+
if (typeof (globalThis as any) === 'undefined') {
|
|
8
|
+
if (typeof (self as any) !== 'undefined') (self as any).globalThis = self;
|
|
9
|
+
else if (typeof (window as any) !== 'undefined') (window as any).globalThis = window;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 全局类型声明(aplus 友盟上报队列)
|
|
13
|
+
declare const aplus_queue: any;
|
|
14
|
+
|
|
15
|
+
export interface ISupersetUserInfo {
|
|
16
|
+
os_type?: string;
|
|
17
|
+
os_version?: string;
|
|
18
|
+
app_version?: string;
|
|
19
|
+
app_item?: string;
|
|
20
|
+
app_name?: string;
|
|
21
|
+
app_project?: string;
|
|
22
|
+
province?: string;
|
|
23
|
+
city?: string;
|
|
24
|
+
uid?: string;
|
|
25
|
+
user_id?: string;
|
|
26
|
+
device_brand?: string;
|
|
27
|
+
device_model?: string;
|
|
28
|
+
network_type?: string;
|
|
29
|
+
carrier?: string;
|
|
30
|
+
device_id?: string;
|
|
31
|
+
promotion_flag?: string;
|
|
32
|
+
user_type?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ISupersetReportItem {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ISupersetAjaxConfig {
|
|
40
|
+
url: string;
|
|
41
|
+
data: any;
|
|
42
|
+
async?: boolean;
|
|
43
|
+
type?: string;
|
|
44
|
+
contentType?: string;
|
|
45
|
+
dataType?: string;
|
|
46
|
+
headers?: Array<{ name: string; value: string }>;
|
|
47
|
+
success?: (xhr: XMLHttpRequest, rsp: any) => void;
|
|
48
|
+
error?: (xhr: XMLHttpRequest | null, rsp: any) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const supersetLewo = (function () {
|
|
52
|
+
// ========== 私有常量与缓存(闭包私有,外部不可访问) ==========
|
|
53
|
+
// 设备ID本地存储Key:localStorage + cookie共用
|
|
54
|
+
const STORAGE_KEY = 'analytics.device_id.uuid_v4';
|
|
55
|
+
// 内存缓存设备UUID,避免重复读取存储
|
|
56
|
+
let memoryCache: string | null = null;
|
|
57
|
+
// 全局缓存用户/设备公共信息,上报顶层user字段统一复用
|
|
58
|
+
let globalUserInfo: ISupersetUserInfo = {};
|
|
59
|
+
|
|
60
|
+
let initInfoFlag = false;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 生成标准 UUID v4 设备唯一标识
|
|
64
|
+
* 优先级:原生crypto.randomUUID > crypto.getRandomValues > Math.random伪随机兜底
|
|
65
|
+
* @returns {string} 小写标准UUID v4字符串
|
|
66
|
+
*/
|
|
67
|
+
function createUuidV4(): string {
|
|
68
|
+
const cryptoObj = (globalThis as any).crypto;
|
|
69
|
+
// 浏览器原生高性能UUID接口
|
|
70
|
+
if (cryptoObj?.randomUUID) {
|
|
71
|
+
return cryptoObj.randomUUID().toLowerCase();
|
|
72
|
+
}
|
|
73
|
+
// 支持加密随机字节,手动构造v4规范UUID
|
|
74
|
+
if (cryptoObj?.getRandomValues) {
|
|
75
|
+
const bytes = new Uint8Array(16);
|
|
76
|
+
cryptoObj.getRandomValues(bytes);
|
|
77
|
+
// UUID v4 固定版本位 0x40、变种位 0x80
|
|
78
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
79
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
80
|
+
// 字节转两位十六进制字符串
|
|
81
|
+
const hex = Array.from(bytes, function (val) {
|
|
82
|
+
return val.toString(16).padStart(2, '0');
|
|
83
|
+
}).join('');
|
|
84
|
+
// 拼接标准UUID分隔格式
|
|
85
|
+
return hex.slice(0, 8) + '-' + hex.slice(8, 12) + '-' +
|
|
86
|
+
hex.slice(12, 16) + '-' + hex.slice(16, 20) + '-' + hex.slice(20);
|
|
87
|
+
}
|
|
88
|
+
// 最低兼容兜底:Math.random生成伪随机UUID(熵较低,仅无加密API场景使用)
|
|
89
|
+
return generatePseudoUuid();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Math.random 伪随机UUID生成器,兼容极老浏览器
|
|
94
|
+
* @returns {string} 伪随机UUID v4格式字符串
|
|
95
|
+
*/
|
|
96
|
+
function generatePseudoUuid(): string {
|
|
97
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
98
|
+
const r = (Math.random() * 16) | 0;
|
|
99
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
100
|
+
return v.toString(16);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 安全读取Cookie,自动转义正则特殊字符,防止匹配失效
|
|
106
|
+
* @param {string} name cookie键名
|
|
107
|
+
* @returns {string | null} cookie值,无则返回null
|
|
108
|
+
*/
|
|
109
|
+
function getCookie(name: string): string | null {
|
|
110
|
+
try {
|
|
111
|
+
// 转义 . * + ? $ 等正则特殊符号
|
|
112
|
+
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
113
|
+
const reg = new RegExp('(^| )' + escapedName + '=([^;]+)');
|
|
114
|
+
const match = document.cookie.match(reg);
|
|
115
|
+
return match ? match[2] : null;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
// cookie读取异常直接返回空
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 设置持久化Cookie,有效期1年,自动适配HTTPS Secure标识
|
|
124
|
+
* @param {string} name cookie键名
|
|
125
|
+
* @param {string} value cookie存储值
|
|
126
|
+
*/
|
|
127
|
+
function setCookie(name: string, value: string): void {
|
|
128
|
+
try {
|
|
129
|
+
const isHttps = window.location.protocol === 'https:';
|
|
130
|
+
const parts = [
|
|
131
|
+
name + '=' + value,
|
|
132
|
+
'max-age=31536000', // 有效期365天
|
|
133
|
+
'path=/', // 全站生效
|
|
134
|
+
'SameSite=Lax' // 防跨站劫持
|
|
135
|
+
];
|
|
136
|
+
// HTTPS环境追加Secure标识
|
|
137
|
+
if (isHttps) parts.push('Secure');
|
|
138
|
+
document.cookie = parts.join(';');
|
|
139
|
+
} catch (e) { }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 时间格式化工具,统一输出 yyyy-MM-dd HH:mm:ss
|
|
144
|
+
* @returns {string} 格式化后的标准时间字符串
|
|
145
|
+
*/
|
|
146
|
+
function formatTime(): string {
|
|
147
|
+
const date_t = new Date();
|
|
148
|
+
const y_t = date_t.getFullYear();
|
|
149
|
+
const m_t = String(date_t.getMonth() + 1).padStart(2, '0');
|
|
150
|
+
const d_t = String(date_t.getDate()).padStart(2, '0');
|
|
151
|
+
const h_t = String(date_t.getHours()).padStart(2, '0');
|
|
152
|
+
const min_t = String(date_t.getMinutes()).padStart(2, '0');
|
|
153
|
+
const sec_t = String(date_t.getSeconds()).padStart(2, '0');
|
|
154
|
+
return y_t + "-" + m_t + "-" + d_t + " " + h_t + ":" + min_t + ":" + sec_t;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 填充单条埋点事件默认字段,缺失字段自动补空/默认行为类型,自动填充事件时间
|
|
159
|
+
* @param {ISupersetReportItem} eventItem 业务传入的单条埋点原始参数
|
|
160
|
+
* @returns {ISupersetReportItem} 补全默认值后的标准事件对象
|
|
161
|
+
*/
|
|
162
|
+
function fillEventDefault(eventItem: ISupersetReportItem): ISupersetReportItem {
|
|
163
|
+
// 事件字段默认模板,对齐后端data数组字段规范
|
|
164
|
+
const defaultEvent: ISupersetReportItem = {
|
|
165
|
+
element_position: "", // 产品定义元素位置编码(唯一标识)
|
|
166
|
+
position_name: "", // 元素位置中文名称
|
|
167
|
+
page_code: "", // OMS后台页面编码,无则空字符串
|
|
168
|
+
page_name: "", // OMS后台页面名称,无则空字符串
|
|
169
|
+
floor_id: "", // OMS后台楼层ID
|
|
170
|
+
floor_name: "", // OMS后台楼层名称
|
|
171
|
+
element_type: "", // 元素枚举:page/vlist/plist/res/act/link等
|
|
172
|
+
element_name: "", // 元素内部名称/标题
|
|
173
|
+
content_id: "", // 最小颗粒度内容ID(游戏/视频ID)
|
|
174
|
+
content_title: "", // 内容标题名称
|
|
175
|
+
ext_attr1: "", // 扩展属性1,存放自定义附属信息
|
|
176
|
+
ext_attr2: "", // 扩展属性2,存放附属ID类参数
|
|
177
|
+
action_type: "曝光", // 行为枚举:曝光/点击/开始播放/结束播放/分享/订购/启动/退出/切后台
|
|
178
|
+
action_value: "", // 行为附属值:播放时长填秒数、订购填金额(单位分)、无附属数据填空
|
|
179
|
+
event_time: "" // 事件发生时间,不传则自动生成当前标准时间
|
|
180
|
+
};
|
|
181
|
+
// 业务参数覆盖默认模板
|
|
182
|
+
const merged = Object.assign({}, defaultEvent, eventItem);
|
|
183
|
+
// 未传入时间自动填充当前客户端时间
|
|
184
|
+
if (!merged.event_time) merged.event_time = formatTime();
|
|
185
|
+
return merged;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ========== 对外暴露公共API ==========
|
|
189
|
+
return {
|
|
190
|
+
// 全局埋点配置项
|
|
191
|
+
config: {
|
|
192
|
+
reportUrl: 'https://sup.daoran.tv/bi-api/api/game/lewo/batch', // 批量上报接口地址
|
|
193
|
+
// reportUrl: '/bi-api/api/game/lewo/batch', // 批量上报接口地址
|
|
194
|
+
defaultHeaders: [] as Array<{ name: string; value: string }>, // 默认全局请求头数组
|
|
195
|
+
defaultContentType: 'application/json;charset=UTF-8' // 请求体类型
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 设置全局用户/设备公共信息(上报顶层user对象,全局复用)
|
|
200
|
+
* @param {ISupersetUserInfo} userObj 用户设备公共参数集合
|
|
201
|
+
*/
|
|
202
|
+
initUserInfo: function (userObj: ISupersetUserInfo): void {
|
|
203
|
+
if (initInfoFlag) { return; }
|
|
204
|
+
initInfoFlag = true;
|
|
205
|
+
// 未传入设备ID时,自动生成持久化UUID填充
|
|
206
|
+
if (!userObj.device_id) {
|
|
207
|
+
userObj.device_id = this.createDeviceId();
|
|
208
|
+
}
|
|
209
|
+
// 合并覆盖全局缓存,保留旧字段,新参数覆盖
|
|
210
|
+
globalUserInfo = Object.assign({}, globalUserInfo, userObj);
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
// 1. 异步加载 H5 专属 SDK
|
|
214
|
+
(function (w: any, d: Document, s: string, q: string, i: string) {
|
|
215
|
+
w[q] = w[q] || [];
|
|
216
|
+
const f = d.getElementsByTagName(s)[0],
|
|
217
|
+
j = d.createElement(s) as HTMLScriptElement;
|
|
218
|
+
j.async = true;
|
|
219
|
+
j.id = 'beacon-aplus';
|
|
220
|
+
// ✅ 使用 H5 网页专属 SDK 地址
|
|
221
|
+
j.src = 'https://d.alicdn.com/alilog/mlog/aplus/' + i + '.js';
|
|
222
|
+
f.parentNode.insertBefore(j, f);
|
|
223
|
+
})(window, document, 'script', 'aplus_queue', '203467608');
|
|
224
|
+
|
|
225
|
+
// ========= 基础配置 =========
|
|
226
|
+
// 2. 设置 AppKey (请确保与友盟后台 H5/Web 应用的 AppKey 一致)
|
|
227
|
+
aplus_queue.push({
|
|
228
|
+
action: 'aplus.setMetaInfo',
|
|
229
|
+
arguments: ['appKey', '6a55f95f6f259537c7c966c8'] // 替换你的Umini AppKey
|
|
230
|
+
});
|
|
231
|
+
// 3. 声明终端类型为 PC (关键配置)
|
|
232
|
+
aplus_queue.push({
|
|
233
|
+
action: 'aplus.setMetaInfo',
|
|
234
|
+
arguments: ['aplus-terminal', 'pc']
|
|
235
|
+
});
|
|
236
|
+
// 4. 采集模式配置
|
|
237
|
+
// 传统多页网站(PC)建议改为 'AUTO';如果是 Vue/React 单页应用(SPA)保持 'MAN'
|
|
238
|
+
aplus_queue.push({
|
|
239
|
+
action: 'aplus.setMetaInfo',
|
|
240
|
+
arguments: ['aplus-waiting', 'AUTO']
|
|
241
|
+
});
|
|
242
|
+
// 调试模式,上线务必改为false
|
|
243
|
+
aplus_queue.push({
|
|
244
|
+
action: 'aplus.setMetaInfo',
|
|
245
|
+
arguments: ['DEBUG', false]
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ✅【必须补充】显式初始化SDK
|
|
249
|
+
aplus_queue.push({
|
|
250
|
+
action: 'aplus.init'
|
|
251
|
+
});
|
|
252
|
+
} catch (e) { }
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
// 设置用户唯一ID(登录/游客都可以设置)
|
|
256
|
+
const u_user_id = userObj.uid || userObj.device_id || '';
|
|
257
|
+
aplus_queue.push({
|
|
258
|
+
action: 'aplus.setMetaInfo',
|
|
259
|
+
arguments: ['userId', u_user_id]
|
|
260
|
+
});
|
|
261
|
+
} catch (e) { }
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 获取当前全局缓存的user公共信息(拷贝返回,防止外部篡改缓存)
|
|
266
|
+
* @returns {ISupersetUserInfo} 完整user公参对象
|
|
267
|
+
*/
|
|
268
|
+
getUserInfo: function (): ISupersetUserInfo {
|
|
269
|
+
return Object.assign({}, globalUserInfo);
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 获取或生成持久化设备唯一ID
|
|
274
|
+
* 读取优先级:内存缓存 > localStorage > cookie > 新建UUID
|
|
275
|
+
* @returns {string} 小写标准UUID v4 device_id
|
|
276
|
+
*/
|
|
277
|
+
createDeviceId: function (): string {
|
|
278
|
+
// 内存存在直接返回,减少存储读取
|
|
279
|
+
if (memoryCache) return memoryCache;
|
|
280
|
+
// 第一步读取localStorage
|
|
281
|
+
try {
|
|
282
|
+
const storageId = localStorage.getItem(STORAGE_KEY);
|
|
283
|
+
if (storageId?.trim()) {
|
|
284
|
+
memoryCache = storageId.toLowerCase();
|
|
285
|
+
return memoryCache;
|
|
286
|
+
}
|
|
287
|
+
} catch (e) { }
|
|
288
|
+
// 第二步读取cookie
|
|
289
|
+
const cookieId = getCookie(STORAGE_KEY);
|
|
290
|
+
if (cookieId?.trim()) {
|
|
291
|
+
memoryCache = cookieId.toLowerCase();
|
|
292
|
+
// 同步写入localStorage,双存储统一
|
|
293
|
+
try { localStorage.setItem(STORAGE_KEY, memoryCache); } catch (e) { }
|
|
294
|
+
return memoryCache;
|
|
295
|
+
}
|
|
296
|
+
// 无存储记录,新建UUID并持久化
|
|
297
|
+
const newId = createUuidV4();
|
|
298
|
+
memoryCache = newId;
|
|
299
|
+
try { localStorage.setItem(STORAGE_KEY, newId); } catch (e) { }
|
|
300
|
+
setCookie(STORAGE_KEY, newId);
|
|
301
|
+
return newId;
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* 重置清除本地全部设备ID缓存(退出账号/清除游客标识场景使用)
|
|
306
|
+
*/
|
|
307
|
+
resetDeviceId: function (): void {
|
|
308
|
+
memoryCache = null;
|
|
309
|
+
// 删除本地存储
|
|
310
|
+
try { localStorage.removeItem(STORAGE_KEY); } catch (e) { }
|
|
311
|
+
// 过期销毁cookie
|
|
312
|
+
try {
|
|
313
|
+
const isHttps = window.location.protocol === 'https:';
|
|
314
|
+
const cookieParts = [STORAGE_KEY + '=', 'max-age=0', 'path=/', 'SameSite=Lax'];
|
|
315
|
+
if (isHttps) cookieParts.push('Secure');
|
|
316
|
+
document.cookie = cookieParts.join(';');
|
|
317
|
+
} catch (e) { }
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 上报请求中转封装,调用底层ES5 ajax
|
|
322
|
+
* @param {ISupersetReportItem} dataObj 完整上报报文 {user:{}, data:[]}
|
|
323
|
+
*/
|
|
324
|
+
supersetAjax: function (dataObj: ISupersetReportItem): void {
|
|
325
|
+
this.ajax({
|
|
326
|
+
url: this.config.reportUrl,
|
|
327
|
+
data: dataObj,
|
|
328
|
+
type: 'post',
|
|
329
|
+
dataType: 'json',
|
|
330
|
+
headers: [],
|
|
331
|
+
success: function (xhr: XMLHttpRequest /*, rsp */) {
|
|
332
|
+
// 上报成功回调,业务可自行扩展
|
|
333
|
+
},
|
|
334
|
+
error: function (xhr: XMLHttpRequest | null, rsp: any) {
|
|
335
|
+
console.error('[supersetLewo 埋点上报失败]', rsp);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* ES5 底层原生XMLHttpRequest AJAX封装(还原最初版本逻辑,无Promise/Beacon)
|
|
342
|
+
* @param {ISupersetAjaxConfig} config 请求配置对象
|
|
343
|
+
*/
|
|
344
|
+
ajax: function (config: ISupersetAjaxConfig): void {
|
|
345
|
+
let url = config.url;
|
|
346
|
+
let data = config.data;
|
|
347
|
+
const dataAsync = config.async !== false;
|
|
348
|
+
const type = (config.type || 'GET').toUpperCase();
|
|
349
|
+
const contentType = config.contentType || this.config.defaultContentType;
|
|
350
|
+
const dataType = config.dataType;
|
|
351
|
+
const headers = config.headers || this.config.defaultHeaders;
|
|
352
|
+
const fnSuccess = config.success || function () { };
|
|
353
|
+
const fnError = config.error || function () { };
|
|
354
|
+
let xmlhttp: any;
|
|
355
|
+
|
|
356
|
+
// 兼容IE低版本XMLHttpRequest
|
|
357
|
+
if (typeof window != 'undefined' && window.XMLHttpRequest) {
|
|
358
|
+
xmlhttp = new XMLHttpRequest();
|
|
359
|
+
} else if (typeof (ActiveXObject as any) != 'undefined') {
|
|
360
|
+
xmlhttp = new (ActiveXObject as any)("Microsoft.XMLHTTP");
|
|
361
|
+
} else {
|
|
362
|
+
fnError(null, { error: 'XMLHttpRequest is not supported in this environment' });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
xmlhttp.onreadystatechange = function () {
|
|
367
|
+
if (xmlhttp.readyState == 4) {
|
|
368
|
+
let rsp = xmlhttp.responseText || xmlhttp.responseXML;
|
|
369
|
+
let parseError = false;
|
|
370
|
+
// JSON解析异常捕获,防止页面报错
|
|
371
|
+
if (dataType == 'json' && typeof rsp == 'string') {
|
|
372
|
+
try {
|
|
373
|
+
rsp = JSON.parse(rsp);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
parseError = true;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (parseError) {
|
|
379
|
+
fnError(xmlhttp, rsp);
|
|
380
|
+
} else if (xmlhttp.status == 200) {
|
|
381
|
+
fnSuccess(xmlhttp, rsp);
|
|
382
|
+
} else {
|
|
383
|
+
fnError(xmlhttp, rsp);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
xmlhttp.open(type, url, dataAsync);
|
|
389
|
+
// 追加自定义请求头
|
|
390
|
+
for (let i = 0; i < headers.length; ++i) {
|
|
391
|
+
xmlhttp.setRequestHeader(headers[i].name, headers[i].value);
|
|
392
|
+
}
|
|
393
|
+
xmlhttp.setRequestHeader('Content-Type', contentType);
|
|
394
|
+
console.log('[supersetLewo 上报数据]', data);
|
|
395
|
+
// 对象转JSON字符串发送
|
|
396
|
+
data = JSON.stringify(data);
|
|
397
|
+
xmlhttp.send(data);
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* 单条埋点事件上报
|
|
402
|
+
* @param {ISupersetReportItem} eventParam 单条事件埋点参数,字段对齐data数组规范
|
|
403
|
+
*/
|
|
404
|
+
superBatchReport: function (eventParam: ISupersetReportItem): void {
|
|
405
|
+
// 填充缺失默认字段与事件时间
|
|
406
|
+
const eventItem = fillEventDefault(eventParam);
|
|
407
|
+
// 组装标准上报报文
|
|
408
|
+
const reportBody = {
|
|
409
|
+
user: this.getUserInfo(), // 全局公共用户设备信息
|
|
410
|
+
data: [eventItem] // 单事件数组
|
|
411
|
+
};
|
|
412
|
+
this.supersetAjax(reportBody);
|
|
413
|
+
|
|
414
|
+
try {
|
|
415
|
+
const action_type = eventParam.action_type == '点击' ? 'CLICK' : 'EXPOSURE';
|
|
416
|
+
const eventName = eventParam.element_position + '_' + action_type;
|
|
417
|
+
|
|
418
|
+
aplus_queue.push({
|
|
419
|
+
action: 'aplus.record',
|
|
420
|
+
// 第二个参数事件类型:CLICK / EXPOSURE / PAGE等,常规点击用CLICK
|
|
421
|
+
arguments: [eventName, action_type, eventParam]
|
|
422
|
+
});
|
|
423
|
+
} catch (e) {
|
|
424
|
+
console.log("superBatchReport-umeng error", e);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 批量多条埋点事件上报(一次性上报多个行为,减少请求次数)
|
|
430
|
+
* @param {ISupersetReportItem[]} eventList 多条埋点事件对象数组
|
|
431
|
+
*/
|
|
432
|
+
batchReporting: function (eventList: ISupersetReportItem[]): void {
|
|
433
|
+
// 非数组/空数组直接终止上报
|
|
434
|
+
if (!Array.isArray(eventList) || eventList.length === 0) return;
|
|
435
|
+
// 批量填充每条事件默认参数
|
|
436
|
+
const filledData: ISupersetReportItem[] = [];
|
|
437
|
+
for (let i = 0; i < eventList.length; i++) {
|
|
438
|
+
filledData.push(fillEventDefault(eventList[i]));
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
const action_type = eventList[i].action_type == '点击' ? 'CLICK' : 'EXPOSURE';
|
|
442
|
+
const eventName = eventList[i].element_position + '_' + action_type;
|
|
443
|
+
|
|
444
|
+
aplus_queue.push({
|
|
445
|
+
action: 'aplus.record',
|
|
446
|
+
// 第二个参数事件类型:CLICK / EXPOSURE / PAGE等,常规点击用CLICK
|
|
447
|
+
arguments: [eventName, action_type, eventList[i]]
|
|
448
|
+
});
|
|
449
|
+
} catch (e) {
|
|
450
|
+
console.log("batchReporting-umeng error", e);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// 组装批量上报报文
|
|
454
|
+
const reportBody = {
|
|
455
|
+
user: this.getUserInfo(),
|
|
456
|
+
data: filledData
|
|
457
|
+
};
|
|
458
|
+
this.supersetAjax(reportBody);
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
})();
|
|
462
|
+
|
|
463
|
+
// CommonJS 模块导出(兼容 IIFE 逻辑)
|
|
464
|
+
export default supersetLewo;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 聚合广告 SDK - 枚举定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** 广告平台标识 */
|
|
6
|
+
export enum AdPlatform {
|
|
7
|
+
None = 'none',
|
|
8
|
+
Xiaomi = 'xiaomi',
|
|
9
|
+
// 后续扩展
|
|
10
|
+
// Huawei = 'huawei',
|
|
11
|
+
// Tencent = 'tencent',
|
|
12
|
+
// ByteDance = 'bytedance',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 广告类型 */
|
|
16
|
+
export enum AdType {
|
|
17
|
+
/** 激励视频广告 */
|
|
18
|
+
RewardVideo = 'reward_video',
|
|
19
|
+
/** 插屏广告(预留) */
|
|
20
|
+
Interstitial = 'interstitial',
|
|
21
|
+
/** Banner 广告(预留) */
|
|
22
|
+
Banner = 'banner',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 广告事件 */
|
|
26
|
+
export enum AdEvent {
|
|
27
|
+
/** 广告加载完成,可以播放 */
|
|
28
|
+
Loaded = 'loaded',
|
|
29
|
+
/** 广告展示(开始播放) */
|
|
30
|
+
Show = 'show',
|
|
31
|
+
/** 广告点击 */
|
|
32
|
+
Click = 'click',
|
|
33
|
+
/** 广告关闭 */
|
|
34
|
+
Closed = 'closed',
|
|
35
|
+
/** 观看完成,应发放奖励 */
|
|
36
|
+
Reward = 'reward',
|
|
37
|
+
/** 广告失败 */
|
|
38
|
+
Error = 'error',
|
|
39
|
+
/** 退出确认(原生层确认退出) */
|
|
40
|
+
Exit = 'exit',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 广告错误码(聚合层统一) */
|
|
44
|
+
export enum AdErrorCode {
|
|
45
|
+
/** 成功 */
|
|
46
|
+
Success = 0,
|
|
47
|
+
/** 通用错误 */
|
|
48
|
+
Unknown = -1,
|
|
49
|
+
/** 广告开关已关闭 */
|
|
50
|
+
AdSwitchOff = 1001,
|
|
51
|
+
/** 无广告填充 */
|
|
52
|
+
NoFill = 1002,
|
|
53
|
+
/** 广告请求超时(5秒) */
|
|
54
|
+
Timeout = 1003,
|
|
55
|
+
/** 视频播放失败 */
|
|
56
|
+
PlayFailed = 1004,
|
|
57
|
+
/** 无兜底广告 */
|
|
58
|
+
NoFallbackAd = 1005,
|
|
59
|
+
/** 用户放弃观看(播放中途按返回键) */
|
|
60
|
+
UserAbandoned = 1006,
|
|
61
|
+
/** 广告播放中,不可重复请求 */
|
|
62
|
+
AdInProgress = 1007,
|
|
63
|
+
/** SDK 未初始化 */
|
|
64
|
+
NotInitialized = 2001,
|
|
65
|
+
/** 平台不支持 */
|
|
66
|
+
PlatformNotSupported = 2002,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 设备平台 */
|
|
70
|
+
export enum DevicePlatform {
|
|
71
|
+
/** 电视 */
|
|
72
|
+
TV = 'tv',
|
|
73
|
+
/** 手机(预留) */
|
|
74
|
+
Mobile = 'mobile',
|
|
75
|
+
/** 平板(预留) */
|
|
76
|
+
Tablet = 'tablet',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 遥控器按键码 */
|
|
80
|
+
export enum KeyCode {
|
|
81
|
+
/** 上 */
|
|
82
|
+
Up = 'up',
|
|
83
|
+
/** 下 */
|
|
84
|
+
Down = 'down',
|
|
85
|
+
/** 左 */
|
|
86
|
+
Left = 'left',
|
|
87
|
+
/** 右 */
|
|
88
|
+
Right = 'right',
|
|
89
|
+
/** 确认 (OK) */
|
|
90
|
+
Enter = 'enter',
|
|
91
|
+
/** 返回 */
|
|
92
|
+
Back = 'back',
|
|
93
|
+
/** 菜单 */
|
|
94
|
+
Menu = 'menu',
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 按键动作 */
|
|
98
|
+
export enum KeyAction {
|
|
99
|
+
/** 按下 */
|
|
100
|
+
Down = 'down',
|
|
101
|
+
/** 松开 */
|
|
102
|
+
Up = 'up',
|
|
103
|
+
}
|