# 使用指南
# jssdk 的引入
<script type="text/javascript">
(function() {
// 高版本chrome浏览器内置Report对象,会与jssdk内置的Report对象产生冲突,最简单的方法是删除它。
delete window.Report;
window.Report = window.Report || [];
window.Report.methods = "_init track defineCom listen onError changeApi".split(
" "
);
window.Report.factory = function(b) {
return function() {
var a = Array.prototype.slice.call(arguments);
a.unshift(b);
window.Report.push(a);
return window.Report;
};
};
for (var i = 0; i < window.Report.methods.length; i++) {
var key = window.Report.methods[i];
window.Report[key] = window.Report.factory(key);
}
window.Report.load = function(b, x) {
if (!document.getElementById("report-js")) {
var a = document.createElement("script");
var verDate = new Date();
var verStr =
verDate.getFullYear().toString() +
verDate.getMonth().toString() +
verDate.getDate().toString();
a.type = "text/javascript";
a.id = "report-js";
a.async = !0;
a.src =
"https://aecore.glodon.com/static/prod-ops/sdk/isv/wdc.js?v=" +
verStr;
a.onerror = function() {
console.log("report sdk load failed");
};
var c = document.getElementsByTagName("script")[0];
c.parentNode.insertBefore(a, c);
window.Report._init(b);
}
};
window.Report.load({ env: "prod" });
})();
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
注意
- SDK 加载之前提前调用了 SDK 的接口,怎么办?
window.OPSDK.methods = "_init listen onError".split(" ");,你需要调用 OPSDK 的哪些接口,你都可以在里面添加。
这个操作可以使 SDK 加载完成之前的 SDK 接口调用保持有效性。
例如:window.OPSDK.methods = "_init track defineCom listen onError changeApi".split(" ");,这样你提前调用track也是有效地,它会被存储在执行队列中,SDK 加载完成之后被按顺序执行。
SDK 的接口具体请看之后的文档。
- SDK 上报数据是测试还是正式,如何配置?
当你将使用指南中的代码引入到你入口文件(index.html)中的时候,请留意代码最后一行:window.Report.load({ env: "prod" });,这代表正式数据,如果env: "test",则为测试数据,你也可以调用接口changeApi随时调整上报数据的性质,具体在接口文档中查看。如果你将 sdk 文件下载下来进行私有化部署,那么请留意window.Report._init(b);,这是初始化 sdk 的接口。
- 埋点数据哪里看?
登录AECORE (opens new window),创建应用,开通采集服务即可查看埋点数据。
- 如何兼容乾坤等微服务框架
将 js 引入代码中的a.src = "https://aecore.glodon.com/static/prod-ops/sdk/isv/wdc.js?v=" + verStr;改为a.src = "https://aecore-static.glodon.com/prod-ops/sdk/isv/wdc.js?v=" + verStr;即可。