statisticsManager.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, Component, Node, sys } from 'cc';
  2. import { statistics_collect_rewardVideo_data } from '../data/data';
  3. import { gameManager } from './run/gameManager';
  4. import { http } from './http';
  5. import { config } from './config';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('statisticsManager')
  8. export class statisticsManager extends Component {
  9. private static _instance: statisticsManager;
  10. public static get instance() {
  11. if (this._instance) {
  12. return this._instance;
  13. }
  14. this._instance = new statisticsManager();
  15. return this._instance;
  16. }
  17. /**
  18. * 获取收集广告数据
  19. *
  20. * @param {number} level_id
  21. * @param {number} actionType
  22. * @returns
  23. * @memberof StatisticsManager
  24. */
  25. public static get_collect_ads_data(level_id: number, ad_res:any, actionType=config.STATISTICS_ACTION_TYPE.UNKNOWN): statistics_collect_rewardVideo_data {
  26. if(gameManager.isFreeAds()) {
  27. return null
  28. }
  29. if(actionType == config.STATISTICS_ACTION_TYPE.UNKNOWN) {
  30. console.log('统计失败 - 未设置统计类型')
  31. return null
  32. }
  33. let collect_data = new statistics_collect_rewardVideo_data()
  34. collect_data.user_id = gameManager.getUserData().id
  35. collect_data.level_id = level_id
  36. collect_data.ads_status = ad_res.isEnded ? 1 : 0
  37. if(actionType==config.STATISTICS_ACTION_TYPE.TI_QIAN_JIE_SUO||actionType==config.STATISTICS_ACTION_TYPE.LIN_SHI_24_XIAO_SHI) {
  38. collect_data.ads_scene = gameManager.Singleton.getCurSceneIndex()
  39. } else {
  40. collect_data.ads_scene = gameManager.Singleton.getCurSceneIndex() + 1
  41. }
  42. if(ad_res.isEnded==false) {
  43. if(ad_res.errorString==undefined||ad_res.errorString==null) {
  44. collect_data.ads_remarks = '未观看完视频广告'
  45. } else {
  46. collect_data.ads_remarks = ad_res.errorString
  47. }
  48. }
  49. collect_data.ads_action = actionType
  50. return collect_data
  51. }
  52. /**
  53. * 请求收集激励视频广告数据
  54. *
  55. * @param {statistics_collect_rewardVideo_data} data_item
  56. * @param {Function} call_back
  57. * @returns
  58. * @memberof StatisticsManager
  59. */
  60. public static request_collect_rewardVideoData(data_item: statistics_collect_rewardVideo_data, call_back: any = null) {
  61. if(gameManager.isFreeAds()) {
  62. return
  63. }
  64. if (data_item == null) {
  65. return
  66. }
  67. if (data_item.ads_action == config.STATISTICS_ACTION_TYPE.UNKNOWN) {
  68. console.log('统计失败 - 未设置统计类型')
  69. return
  70. }
  71. let data_string = JSON.stringify(data_item)
  72. // console.log(data_string)
  73. let request_data = { 'adsdata': data_string }
  74. http.statistics_post(http.statistics_ads(),request_data,(_err,c_data)=> {
  75. console.log('_err=', _err, 'c_dat=', c_data)
  76. if (call_back != null) {
  77. call_back()
  78. }
  79. })
  80. }
  81. }