我智商爆棚
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
7.8 KiB

4 weeks ago
import AppPlatform from "../Util/AppPlatform";
import { LogUtils } from "../Util/LogUtils";
import EventMgr from "../Event/EventMgr";
import { ryw_Event } from "../Event/EventEnum";
/**
* ,
*/
enum StatsFrameWorkEvent {
ReportAdClickSuccess_custom = "ReportAdClickSuccess",//点击广告成功
ReportAdClickFail_custom = "ReportAdClickFail",//点击广告失败
ReportAdClickStart_custom = "ReportAdClickStart",//点击广告
ReportLaunchOptions_custom = "ReportLaunchOptions",//场景值ip
LogReportInfo_custom = "LogReportInfo",//上报日志
LogReportError_custom = "LogReportError",//上报的异常日志
LoginReportInfo_custom = "LoginReportInfo",//登录日志
GameEventLVInto_custom = "Event_LVInto", //关卡进入人数 level
GameEventLVFinish_custom = 'Event_LVFinish', //完成关卡 level status 关卡状态 字符 win,lose duration
Event_Commerce_custom = "Event_Commerce",//商业行为
Event_Custom_custom = "Event_Custom",//个性事件
}
/*
* @Author: YeeChan
* @Date: 2020-11-24 19:30:12
* @Description:
*/
export class UmengMgr {
/**
*
* 使StatsMgr.sendEvent("事件ID")
* 使
* StatsMgr.sendEvent('事件ID', { '属性1':'属性值1','属性2':'属性值2' }); // 字符型属性值
* StatsMgr.sendEvent('事件ID', { 'PayAmount':6999 });// 数值型属性值
* @param event ID
* @param params
*/
public static sendEvent_custom(event: string, params?: { [key: string]: string | number }) {
if (AppPlatform.is_WECHAT_GAME_custom()) {
UmengMgr.uma_trackEvent(event, params);
} else if (AppPlatform.is_Iphone_custom() || AppPlatform.is_Android_custom()) {//ios
// FMApp.uma_trackEvent_custom(event, params);
}
EventMgr.emitEvent_custom(ryw_Event.ryw_Umeng_custom, { event: event });
}
/**
* IP
* @param scene
* @param dqip
* @param ipxq
*/
public static sendReportLaunchOptions_custom(scene: string, dqip: string, ipxq: string) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.ReportLaunchOptions_custom, {
"scene": scene,
"dqip": dqip,
"ipxq": ipxq,
})
}
/**
*
* @param title
* @param appid
*/
public static sendReportAdClickSuccess_custom(title: string, appid: string | number) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.ReportAdClickSuccess_custom, {
"title": title,
"appid": String(appid)
})
}
/**
*
* @param title
* @param appid
*/
public static sendReportAdClickFail_custom(title: string, appid: string | number) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.ReportAdClickFail_custom, {
"title": title,
"appid": String(appid)
})
}
/**
* 广
* @param title
* @param appid
*/
public static sendReportAdClickStart_custom(title: string, appid: string | number) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.ReportAdClickStart_custom, {
"title": title,
"appid": String(appid)
})
}
/**
*
* @param level id
*/
public static sendGameEventLvInto_custom(level: string) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.GameEventLVInto_custom, {
"level": level
})
//关卡开始
if (AppPlatform.is_WECHAT_GAME_custom()) {
window["wx"].uma.stage.onStart({
stageId: level + '',//该字段为固定字段不可修改,必传
stageName: '第' + level + '关',// 付费金额 (该字段必传) 格式:数值型,number;请注意值格式,传错不能进行金额计算
})
}
}
/**
* ,win
* @param level id
* @param isWin true/false
* @param duration ()
* @param custom
* isHome:0没有 1
*
*/
public static sendGameEventLvFinish_custom(level: string, isWin: boolean, duration: number, custom?: { [key: string]: string | number }) {
let status = "win";
if (!isWin) {
status = "lose";
}
let params = {};
params["level"] = level;
params["status"] = status;
params["duration"] = duration;
if (custom) {
for (const key in custom) {
if (Object.prototype.hasOwnProperty.call(custom, key)) {
const element = custom[key];
if (key == "status") {
if (element) {
params["status"] = "home";
}
} else {
params[key] = element;
}
}
}
}
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.GameEventLVFinish_custom, params)
//关卡结束
if (AppPlatform.is_WECHAT_GAME_custom()) {
let _um_sdu = 0
if (duration) {
_um_sdu = duration * 1000;//秒转毫秒
}
window["wx"].uma.stage.onEnd({
stageId: level + '',//该字段为固定字段不可修改,必传
stageName: '第' + level + '关',// 付费金额 (该字段必传) 格式:数值型,number;请注意值格式,传错不能进行金额计算
event: isWin ? "complete" : "fail",//关卡完成/关卡失败)
_um_sdu: _um_sdu //关卡耗时(毫秒)
})
}
}
/**
*
*/
public static sendEvent_Commerce_custom(params: { [key: string]: string | number }) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.Event_Commerce_custom, params)
}
/**
*
*/
public static sendEvent_Custom_custom(params: { [key: string]: string | number }) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.Event_Custom_custom, params)
}
/**
*
* @param info
*/
public static sendLogReportInfo_custom(info: string) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.LogReportInfo_custom, {
"info": info
})
}
/**
*
* @param info
*/
public static sendLogReportError_custom(info: string) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.LogReportError_custom, {
"info": info
})
}
/**
*
* @param type //
* @param state 012
* @param info
*/
public static sendLoginReportInfo_custom(type: string, state: number, info: string) {
UmengMgr.sendEvent_custom(StatsFrameWorkEvent.LoginReportInfo_custom, {
"type": type,
"state": state,
"info": info,
})
}
/**
*
* @param event
* @param params
*/
private static uma_trackEvent(event: string, params?: { [key: string]: string | number }) {
if (AppPlatform.is_WECHAT_GAME_custom()) {//需要增加合法域名 https://umini.shujupie.com
if (window["wx"].uma) {
window["wx"].uma.trackEvent(event, params);
} else {
LogUtils.error_custom("统计事件 无友盟");
}
}
}
}