/* * @Descripttion: * @version: 1.0.0 * @Author: YeeChan * @Date: 2020-07-09 18:54:38 */ import AppPlatform from "./AppPlatform"; import { LogUtils } from "./LogUtils"; export enum ALDEventDef { None_custom = "", ReportAdClickSuccess_custom = "广告导出成功", ReportAdClickFail_custom = "广告导出失败", ReportLaunchOptions_custom = "用户启动参数", //todo:添加你自己的阿拉丁事件 } //阿拉丁相关接口FD export default class ALD { /** * 上报 阿拉丁 openid * @param openid */ public static aldSendOpenId_custom(openid: string) { if (AppPlatform.is_WECHAT_GAME_custom()) { window["wx"].aldSendOpenid(openid); LogUtils.log_custom("ALD 上报 openid : ", openid); } else if (AppPlatform.is_QQ_PLAY_custom()) { window["qq"].aldSendOpenid(openid); LogUtils.log_custom("ALD 上报 openid : ", openid); } } /** * 上报 阿拉丁 自定义事件 * @param event * @param data */ public static aldSendEvent_custom(event: ALDEventDef | string, data: any) { var eventName: string = event; if (AppPlatform.is_WECHAT_GAME_custom()) { window["wx"].aldSendEvent(eventName, data); } else if (AppPlatform.is_QQ_PLAY_custom()) { window["qq"].aldSendEvent(eventName, data); } } /** * 导出 成功 * @param data */ public static aldSendReportAdClickSuccess_custom(data: any) { var type = ALDEventDef.ReportAdClickSuccess_custom + " " + data.title + ":" + String(data.appid) ALD.aldSendEvent_custom(type, { "导出成功": data.title + ":" + String(data.appid) }) } /** * 导出 失败 * @param data */ public static aldSendReportAdClickFail_custom(data: any) { var type = ALDEventDef.ReportAdClickFail_custom + " " + data.title + ":" + String(data.appid) ALD.aldSendEvent_custom(type, { "导出失败": data.title + ":" + String(data.appid) }) } /** * 场景值 IP 地区 * @param sceneid * @param ip * @param location */ public static aldSendReportLaunchOptions_custom(sceneid: string, ip: string, location: Object) { var type = ALDEventDef.ReportLaunchOptions_custom; ALD.aldSendEvent_custom(type, { "场景值:": String(sceneid), "Ip:": String(ip), "地区:": JSON.stringify(location) }) } /** * 关卡数据统计 关卡开始时调用 * 接口传入的关卡数必须是同一关,否则后台统计的数据会异常 * @param levelId id */ public static aldLevelStart(levelId: number) { if (AppPlatform.is_WECHAT_GAME_custom()) { window["wx"].aldStage.onStart({ stageId: levelId + "", stageName: "关卡" + levelId, }); } else if (AppPlatform.is_QQ_PLAY_custom()) { window["qq"].aldStage.onStart({ stageId: levelId + "", stageName: "关卡" + levelId, }); } } /** * 关卡数据统计 游戏中 * @param levelId * @param event * @param params */ public static aldLevelRunning(levelId: number, event: string = "operation", params: any) { if (AppPlatform.is_WECHAT_GAME_custom()) { window["wx"].aldStage.onRunning({ stageId: levelId + "", stageName: "关卡" + levelId, event: event, params: params //params中必须含有itemName字段 }); } else if (AppPlatform.is_QQ_PLAY_custom()) { window["11"].aldStage.onRunning({ stageId: levelId + "", stageName: "关卡" + levelId, event: event, params: params //params中必须含有itemName字段 }); } } /** * 关卡数据统计 关卡结束调用 * 传入的event字段必须是规定字符串,游戏胜利使用complete,失败fail * @param levelId * @param event * @param desc */ public static aldLevelEnd(levelId: number, event: string = "complete", desc: string = "关卡结束") { if (AppPlatform.is_WECHAT_GAME_custom()) { window["wx"].aldStage.onEnd({ stageId: levelId + "", stageName: "关卡" + levelId, event: event, params: { desc: desc } }); } else if (AppPlatform.is_QQ_PLAY_custom()) { window["qq"].aldStage.onEnd({ stageId: levelId + "", stageName: "关卡" + levelId, event: event, params: { desc: desc } }); } } }