Ge.ts
1.95 KB
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
47
48
49
50
import { sys } from "cc";
import { GAMEDATA } from "../../framework/wxsdk/base/SDKConst";
import { SDKToolsPlus } from "./SDKToolsPlus";
export class Ge {
private static _instance: GravityAnalyticsAPI;
static get I(): GravityAnalyticsAPI {
return this._instance;
}
constructor() {
}
public static init() {
// console.log("ge初始化")
const config = {
accessToken: "ihcpiWLHTqDs5oZEGsnyxCrFXBaSeoju", // 项目通行证,在:网站后台-->管理中心-->应用列表中找到Access Token列 复制(首次使用可能需要先新增应用)
clientId: SDKToolsPlus.openId, // 用户唯一标识,如微信小程序的openid
autoTrack: {
appLaunch: true, // 自动采集 $MPLaunch
appShow: true, // 自动采集 $MPShow
appHide: true, // 自动采集 $MPHide
},
name: "ge", // 全局变量名称
// debugMode: "debug", // 是否开启测试模式,开启测试模式后,可以在 网站后台--管理中心--元数据--事件流中查看实时数据上报结果。(测试时使用,上线之后一定要关掉,改成none或者删除)
};
let ge = new GravityAnalyticsAPI(config);
ge.init();
let isFirst = sys.localStorage.getItem('tt_register');
if (!isFirst) {
// 首次注册
let arr = GAMEDATA.version.split(".");
let version = +(arr[0] + arr[1] + arr[2]);
ge.register({
name: SDKToolsPlus.uid,
version,
wx_openid: SDKToolsPlus.openId,
wx_unionid: "",
}).then((success) => {
// console.log("注册成功", success);
sys.localStorage.setItem('tt_register', "1")
}).catch((fail) => {
// console.error("注册失败", fail)
})
}
this._instance = ge;
}
}