123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import { _decorator, Component, Node, sys } from 'cc';
- import { statistics_collect_rewardVideo_data } from '../data/data';
- import { gameManager } from './run/gameManager';
- import { http } from './http';
- import { config } from './config';
- const { ccclass, property } = _decorator;
- @ccclass('statisticsManager')
- export class statisticsManager extends Component {
- private static _instance: statisticsManager;
- public static get instance() {
- if (this._instance) {
- return this._instance;
- }
- this._instance = new statisticsManager();
- return this._instance;
- }
- /**
- * 获取收集广告数据
- *
- * @param {number} level_id
- * @param {number} actionType
- * @returns
- * @memberof StatisticsManager
- */
- public static get_collect_ads_data(level_id: number, ad_res:any, actionType=config.STATISTICS_ACTION_TYPE.UNKNOWN): statistics_collect_rewardVideo_data {
- if(gameManager.isFreeAds()) {
- return null
- }
- if(actionType == config.STATISTICS_ACTION_TYPE.UNKNOWN) {
- console.log('统计失败 - 未设置统计类型')
- return null
- }
- let collect_data = new statistics_collect_rewardVideo_data()
- collect_data.user_id = gameManager.getUserData().id
- collect_data.level_id = level_id
- collect_data.ads_status = ad_res.isEnded ? 1 : 0
- if(actionType==config.STATISTICS_ACTION_TYPE.TI_QIAN_JIE_SUO||actionType==config.STATISTICS_ACTION_TYPE.LIN_SHI_24_XIAO_SHI) {
- collect_data.ads_scene = gameManager.Singleton.getCurSceneIndex()
- } else {
- collect_data.ads_scene = gameManager.Singleton.getCurSceneIndex() + 1
- }
- if(ad_res.isEnded==false) {
- if(ad_res.errorString==undefined||ad_res.errorString==null) {
- collect_data.ads_remarks = '未观看完视频广告'
- } else {
- collect_data.ads_remarks = ad_res.errorString
- }
- }
- collect_data.ads_action = actionType
- return collect_data
- }
- /**
- * 请求收集激励视频广告数据
- *
- * @param {statistics_collect_rewardVideo_data} data_item
- * @param {Function} call_back
- * @returns
- * @memberof StatisticsManager
- */
- public static request_collect_rewardVideoData(data_item: statistics_collect_rewardVideo_data, call_back: any = null) {
- if(gameManager.isFreeAds()) {
- return
- }
- if (data_item == null) {
- return
- }
- if (data_item.ads_action == config.STATISTICS_ACTION_TYPE.UNKNOWN) {
- console.log('统计失败 - 未设置统计类型')
- return
- }
- let data_string = JSON.stringify(data_item)
- // console.log(data_string)
- let request_data = { 'adsdata': data_string }
- http.statistics_post(http.statistics_ads(),request_data,(_err,c_data)=> {
- console.log('_err=', _err, 'c_dat=', c_data)
- if (call_back != null) {
- call_back()
- }
- })
- }
- }
|