//神策公共函数
//埋点信息记录
(function(para) {
  var p = para.sdk_url, n = para.name, w = window, d = document, s = 'script',x = null,y = null;
  if(typeof(w['sensorsDataAnalytic201505']) !== 'undefined') {
      return false;
  }
  w['sensorsDataAnalytic201505'] = n;
  w[n] = w[n] || function(a) {return function() {(w[n]._q = w[n]._q || []).push([a, arguments]);}};
  var ifs = ['track','quick','register','registerPage','registerOnce','trackSignup', 'trackAbtest', 'setProfile','setOnceProfile','appendProfile', 'incrementProfile', 'deleteProfile', 'unsetProfile', 'identify','login','logout','trackLink','clearAllRegister','getAppStatus'];
  for (var i = 0; i < ifs.length; i++) {
    w[n][ifs[i]] = w[n].call(null, ifs[i]);
  }
  if (!w[n]._t) {
    x = d.createElement(s), y = d.getElementsByTagName(s)[0];
    x.async = 1;
    x.src = p;
    x.setAttribute('charset','UTF-8');
    w[n].para = para;
    y.parentNode.insertBefore(x, y);
  }
})({
  sdk_url: 'https://cdn.jsdelivr.net/npm/sa-sdk-javascript@1.14.13/sensorsdata.min.js',
  heatmap_url: 'https://cdn.jsdelivr.net/npm/sa-sdk-javascript@1.14.13/heatmap.min.js',
  name: 'sensors',
  //server_url: 'https://newdsj.gtjadev.com/sa?project=fuyi',   //生产地址
  server_url: 'https://newdsj.gtjadev.com:9091/sa?project=fuyi',  //测试地址
  // heatmap:{}
});
var userMac
$.ajax({
    async:false,
    url: "./_common/pc.dat",
    type: "GET",
    success: function (data) {
      var myUrlParams = data.split('\n');
      var terminalinfo = myUrlParams[1].split("|");
      userMac = terminalinfo[0]
   },
    error: function(xhr){
    }
});
sensors.identify(userMac, true)

/****** 神策埋点 ********/
var sensorPubObj ={
  app_name:"富易",
  platform_type:"fuyi",
  login_status:"游客",
  user_level:"",
  cust_id:"",
  user_code:"",
  mobile:"",
}

var sensor_wrap = fyCallbackWrap();
var sensor_exports = {
  getUserInfo: function () {
      return wrap('用户信息获取', {
          fytype: 'innercmd',
          method: 'getuserinfo',
          mname: '用户信息获取'
      })
  }  
};

sensor_exports.getUserInfo().then(function(res){
  // console.log('sssssssss:'+JSON.stringify(res))
  let userInfo = res.list[res.USERCOUNT];
  sensorPubObj.cust_id=userInfo.USER_CUSTID;
  sensorPubObj.user_code=userInfo.MUSERCODE;
  sensorPubObj.mobile=userInfo.MOBILENO;
  if(userInfo.USER_CUSTID){
    sensorPubObj.login_status = "登录状态"
  }else if(userInfo.MOBILENO){
    sensorPubObj.login_status = "注册状态"
  }

})


var sensorTrack = function(eventName, parame){
  sensors.track(eventName, Object.assign({}, sensorPubObj, parame));
}