cf318d37-e2b9-4820-bef3-81d4b3cda27f.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. "use strict";
  2. cc._RF.push(module, 'cf318034rlIIL7zgdSzzaJ/', 'YouWanAnalytics');
  3. // common-plugin/Scripts/YouWanSDK/YouWanAnalytics.ts
  4. "use strict";
  5. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var PlatUtils_1 = require("../PlatUtils");
  13. var Utils_1 = require("../Utils");
  14. var YZ_Constant_1 = require("../YZ_Constant");
  15. var YZ_LocalStorage_1 = require("../YZ_LocalStorage");
  16. var EventAdInfo_1 = require("./EventAdInfo");
  17. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  18. var YouWanAnalytics = /** @class */ (function () {
  19. function YouWanAnalytics() {
  20. }
  21. Object.defineProperty(YouWanAnalytics, "_yw_uid", {
  22. // private static LOGIN_URL: string = "http://192.168.31.108:8080/as/login";
  23. // private static EVENT_AD_URL: string = "http://192.168.31.108:8080/ae/ad";
  24. get: function () {
  25. return parseInt(YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_YOUWAN_UID, "-1"));
  26. },
  27. enumerable: false,
  28. configurable: true
  29. });
  30. YouWanAnalytics.login = function (callBackFunc) {
  31. var _this = this;
  32. if (!Utils_1.utils.config.otherconfig.yw_app_id) {
  33. this.showLog("yw_app_id 未配置,不进行上报!");
  34. return;
  35. }
  36. var data = {};
  37. this.getDeviceInfo(data);
  38. this.getStaticParame(data);
  39. this.connect(this.LOGIN_URL, data, function (res, data) {
  40. if (res) {
  41. _this.showLog("登录成功! >>result:" + JSON.stringify(data) + " #uid=" + data.uid);
  42. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_YOUWAN_UID, data.uid);
  43. }
  44. else {
  45. _this.showLog("登录失败!");
  46. }
  47. callBackFunc && callBackFunc(res, data);
  48. });
  49. };
  50. YouWanAnalytics.EventAd = function (adType, adStatus) {
  51. var _this = this;
  52. if (!Utils_1.utils.config.otherconfig.yw_app_id) {
  53. this.showLog("yw_app_id 未配置,不进行上报!");
  54. return;
  55. }
  56. if (!PlatUtils_1.default.IsOPPO)
  57. return;
  58. var adInfo = new EventAdInfo_1.default(adType, adStatus);
  59. var data = {};
  60. this.getStaticParame(data);
  61. data.ad_data = [];
  62. data.ad_data[0] = adInfo.toJsonData();
  63. this.connect(this.EVENT_AD_URL, data, function (res) {
  64. if (res) {
  65. _this.showLog("\u4E0A\u62A5\u5E7F\u544A\u4E8B\u4EF6\u6210\u529F:" + JSON.stringify(adInfo.toJsonData()));
  66. }
  67. else {
  68. _this.showLog("\u4E0A\u62A5\u5E7F\u544A\u4E8B\u4EF6\u5931\u8D25:" + JSON.stringify(adInfo.toJsonData()));
  69. }
  70. });
  71. };
  72. YouWanAnalytics.EventAdWithObj = function (adType, adStatus, adEventParameter) {
  73. var _this = this;
  74. if (!Utils_1.utils.config.otherconfig.yw_app_id) {
  75. this.showLog("yw_app_id 未配置,不进行上报!");
  76. return;
  77. }
  78. if (!PlatUtils_1.default.IsOPPO)
  79. return;
  80. var adInfo = new EventAdInfo_1.default(adType, adStatus, adEventParameter);
  81. var data = {};
  82. this.getStaticParame(data);
  83. data.ad_data = [];
  84. data.ad_data[0] = adInfo.toJsonData();
  85. this.connect(this.EVENT_AD_URL, data, function (res) {
  86. if (res) {
  87. _this.showLog("\u4E0A\u62A5\u5E7F\u544A\u4E8B\u4EF6\u6210\u529F:" + JSON.stringify(adInfo.toJsonData()));
  88. }
  89. else {
  90. _this.showLog("\u4E0A\u62A5\u5E7F\u544A\u4E8B\u4EF6\u5931\u8D25:" + JSON.stringify(adInfo.toJsonData()));
  91. }
  92. });
  93. };
  94. YouWanAnalytics.getStaticParame = function (data) {
  95. data.app_id = Utils_1.utils.config.otherconfig.yw_app_id;
  96. data.sdk_version = Utils_1.utils.utilsVersion;
  97. data.app_type = 1;
  98. if (this._yw_uid != -1) {
  99. data.uid = this._yw_uid;
  100. }
  101. data.country = "CN";
  102. data.uuid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_UUID, "") || Utils_1.utils.generateUUID();
  103. if (PlatUtils_1.default.IsOPPO) {
  104. data.channel = "oppo";
  105. data.app_version = Utils_1.utils.config.oppoconfig.version;
  106. }
  107. };
  108. YouWanAnalytics.getDeviceInfo = function (data) {
  109. var systemInfo = {};
  110. if (PlatUtils_1.default.IsOPPO) {
  111. systemInfo = Utils_1.utils.oppoTool.SysInfo;
  112. data.pkg = Utils_1.utils.config.oppoconfig.packageName;
  113. data.device_id = Utils_1.utils.oppoTool._device_id;
  114. data.kernel_version = systemInfo.platformVersionCode;
  115. data.device_model = systemInfo.model;
  116. data.device_manufactory = systemInfo.brand;
  117. data.screen_height = systemInfo.screenHeight;
  118. data.screen_width = systemInfo.screenWidth;
  119. data.language = systemInfo.language;
  120. data.os = "Android";
  121. if (systemInfo.system.indexOf(" ") > -1) {
  122. data.os_version_release = systemInfo.system.substr(systemInfo.system.indexOf(" ") + 1);
  123. }
  124. else {
  125. data.os_version_release = systemInfo.system;
  126. }
  127. }
  128. };
  129. YouWanAnalytics.connect = function (url, parame, callBackFunc) {
  130. var _this = this;
  131. var xhr = new XMLHttpRequest();
  132. xhr.timeout = 6000; // 单位毫秒
  133. xhr.open('POST', url + "?time_stamp=" + (new Date()).getTime());
  134. xhr.send("data=" + JSON.stringify(parame));
  135. this.showLog("connect:#url=" + url);
  136. this.showLog("connect\uFF1A #parame==" + JSON.stringify(parame));
  137. xhr.onreadystatechange = function () {
  138. _this.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status + " ; responseText=", xhr.responseText);
  139. if (xhr.readyState == 4) {
  140. if (xhr.status == 200) {
  141. if (xhr.responseText) {
  142. try {
  143. var result = JSON.parse(xhr.responseText);
  144. if (result.code == 0) {
  145. callBackFunc && callBackFunc(true, result.data || "");
  146. }
  147. else {
  148. callBackFunc && callBackFunc(false);
  149. }
  150. }
  151. catch (error) {
  152. _this.showLog("connect erro:#msg=" + error);
  153. }
  154. }
  155. }
  156. else {
  157. _this.showLog("connect erro\uFF1A #parame==" + JSON.stringify(parame));
  158. callBackFunc && callBackFunc(false);
  159. }
  160. }
  161. };
  162. xhr.ontimeout = function () {
  163. _this.showLog("connect timeout!");
  164. callBackFunc && callBackFunc(false);
  165. };
  166. xhr.onerror = function () {
  167. _this.showLog("connect onerror!");
  168. callBackFunc && callBackFunc(false);
  169. };
  170. };
  171. YouWanAnalytics.showLog = function (msg) {
  172. var any = [];
  173. for (var _i = 1; _i < arguments.length; _i++) {
  174. any[_i - 1] = arguments[_i];
  175. }
  176. Utils_1.utils.showLog("[YouWan] --- " + msg, any);
  177. };
  178. YouWanAnalytics.LOGIN_URL = "http://as.youlesp.com/as/login";
  179. YouWanAnalytics.EVENT_AD_URL = "http://e.youlesp.com/ae/ad";
  180. YouWanAnalytics = __decorate([
  181. ccclass
  182. ], YouWanAnalytics);
  183. return YouWanAnalytics;
  184. }());
  185. exports.default = YouWanAnalytics;
  186. cc._RF.pop();