import "@/utils/loghub-tracking.js";
import { VUE_APP_SLS_STORE_NAME } from "@/constants/constants";
const host = "cn-shenzhen.log.aliyuncs.com";
const project = "examcloud";
const logstore = VUE_APP_SLS_STORE_NAME;
const logger = new window.Tracker(`${host}`, `${project}`, `${logstore}`);
// logger.push("customer", "zhangsan");
// logger.push("product", "iphone 6s");
// logger.push("price", 5500);
// logger.logger();
// logger.push("customer", "lisi");
// logger.push("product", "ipod");
// logger.push("price", 3000);
// logger.logger();

// 封装logger
// 注意没有 window.Tracker 的情况

import store from "@/store";

// console.log(store);
// console.log(store.state.user);

// export function createNoAuthLog(logs) {
//   for (let [k, v] of Object.entries(logs)) {
//     logger.push(k, v);
//   }
//   logger.logger();
// }

// ip 定位?
// 要在用户登录后调用
export function createUserLog() {
  try {
    const user = store.state.user;
    logger.push("userName", user.displayName);
    logger.push("userId", user.id);
    logger.push("rootOrgName", user.rootOrgName);
    logger.push("rootOrgId", user.rootOrgId);
    logger.logger();
  } catch (error) {
    console.log(error);
    window._hmt.push(["_trackEvent", "创建用户日志出错-1"]);
  }
}

export function createLog(logs) {
  try {
    const user = store.state.user;
    if (user) {
      logger.push("userId", user.id);
    }
    for (let [k, v] of Object.entries(logs)) {
      logger.push(k, v);
    }
    logger.logger();
  } catch (error) {
    console.log(error);
    window._hmt.push(["_trackEvent", "创建用户日志出错-2"]);
  }
}
