ThinkingDataMgr.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import Config from "../Config";
  2. import Gamecfg from "../common/gameCfg";
  3. import { gameMethod } from "../common/gameMethod";
  4. /**
  5. * ThinkingData 数数SDK埋点数据管理
  6. */
  7. export default class ThinkingDataMgr {
  8. // static TDAnalytics: TDAnalytics;
  9. static isOpenTd: boolean
  10. static TDInit () {
  11. this.isOpenTD()
  12. if (!this.isOpenTd) {
  13. console.log("数数上报开关未开启")
  14. return
  15. }
  16. // TA SDK 配置对象
  17. var config = {
  18. appId: "5899ad9ea9dd4e1f9c031b2645cfe33a", // 项目 APP ID
  19. serverUrl: "https://thinking-receiver.szfangzhouhd.com", // 上报地址
  20. enableLog:false,
  21. autoTrack: {
  22. // appLaunch: true, // 自动采集 ta_mp_launch
  23. appShow: true, // 自动采集 ta_mp_show
  24. appHide: true, // 自动采集 ta_mp_hide
  25. // pageShow: true, // 自动采集 ta_mp_view
  26. // pageShare: true, // 自动采集 ta_mp_share
  27. }
  28. };
  29. // var ThinkingAnalyticsAPI = window['TDAnalytics'];
  30. // this.TDAnalytics = new ThinkingAnalyticsAPI(config);
  31. // 初始化
  32. TDAnalytics.init(config);
  33. }
  34. static isOpenTD(){
  35. if (Config.openTD == 0) {
  36. this.isOpenTd = false;
  37. }else{
  38. this.isOpenTd = true;
  39. }
  40. }
  41. static TDLogin (accoundId:string) {
  42. if (!this.isOpenTd) {
  43. return
  44. }
  45. //登录
  46. TDAnalytics.login(accoundId);
  47. }
  48. static TDIdentify (openid:string){
  49. if (!this.isOpenTd) {
  50. return
  51. }
  52. // TDAnalytics.identify(openid);
  53. TDAnalytics.setDistinctId(openid);
  54. }
  55. static TDLogout () {
  56. if (!this.isOpenTd) {
  57. return
  58. }
  59. //登出
  60. TDAnalytics.logout();
  61. }
  62. static TDSetSuperProperties (superProperties:object) {
  63. if (!this.isOpenTd) {
  64. return
  65. }
  66. //设置公共事件属性
  67. // var superProperties = {
  68. // channel : "ta", //字符串
  69. // age : 1,//数字
  70. // isSuccess : true,//布尔
  71. // birthday : new Date(),//对象
  72. // object : { key : "value" },//对象
  73. // object_arr : [ { key : "value" } ],//对象组
  74. // arr : [ "value" ]//数组
  75. // };
  76. TDAnalytics.setSuperProperties(superProperties);
  77. }
  78. static TDTrack (eventName:string, properties:object) {
  79. if (!this.isOpenTd) {
  80. return
  81. }
  82. // console.log("TDTrack===",JSON.stringify(properties))
  83. //发送事件
  84. TDAnalytics.track({eventName: eventName, properties: properties});
  85. // eventName: "product_buy", // 事件名称
  86. // properties: {
  87. // product_name: "商品名"
  88. // } //事件属性
  89. }
  90. static TDUserSet (properties:object) {
  91. if (!this.isOpenTd) {
  92. return
  93. }
  94. //设置用户属性
  95. TDAnalytics.userSet(properties);
  96. // properties: {
  97. // username: "TE"
  98. // }
  99. }
  100. }