window.ApeMonitorSdk = { trace: "", account: "", env: "", error(str) { console.error(str); }, init(account, env) { if (!account) { console.error("请设置account"); } this.initHxsdLog(); this.setAccount(account); this.initLoad(); this.initLoadJs(env); }, initLoadJs(env) { this.env = env; var ma = document.createElement("script"); ma.type = "text/javascript"; ma.async = true; if (env == "local") { ma.src = "https://rzsj-test.hxsd.tv/l.js?v=1.1"; } else { ma.src = "https://rzsj.hxsd.tv/l.js?v=1.1"; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ma, s); }, initHxsdLog() { if (!window._hxsd_log_m) { window._hxsd_log_m = []; } return window._hxsd_log_m; }, initLoad() { var self = this; this.getHxsdLog().push([ "_setCallback", function (isFirst) { self.firstSend(isFirst); var event = new CustomEvent("onApeMonitorLoad"); window.dispatchEvent(event, isFirst); }, ]); // 回调 }, firstSend(isFirst) { // 首次访问或不同域名调用,用于记录首次请求埋点 if ( isFirst === 1 || (document.referrer != "" && document.referrer.indexOf("//" + document.domain) < 0 && /http(s)?:\/\/[^\?\/]*\.hxsd\..*/.test(document.referrer) == false) ) { this.getHxsdLog().push(["trace", "landing"]); } }, getCookieByName(name) { var strcookie = document.cookie; //获取cookie字符串 var arrcookie = strcookie.split("; "); //分割 //遍历匹配 for (var i = 0; i < arrcookie.length; i++) { var arr = arrcookie[i].split("="); if (arr[0] == name) { return arr[1]; } } return ""; }, setAccount(account) { this.account = account; this.getHxsdLog().push(["_setAccount", account]); //账户 }, load(cb) { window.addEventListener("onApeMonitorLoad", cb); }, getHxsdLog() { return window._hxsd_log_m; }, getTRACE() { if (!this.trace) { this.trace = this.getCookieByName("HXSD_U_TRACE"); if (!this.trace) this.error("没有trace"); } return this.trace; }, };