数数:埋点

This commit is contained in:
luying
2021-12-14 18:04:00 +08:00
parent b6501ee4a2
commit dd7cf449d6
23 changed files with 357 additions and 72 deletions
+25 -1
View File
@@ -2,6 +2,8 @@ import 'reflect-metadata'
import * as mongoose from 'mongoose';
import { Application, IBoot } from 'egg';
import { connectRedis } from './app/pubUtils/redis';
import { SDK_TA_CONST, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from '@consts';
const ThinkingAnalytics = require("thinkingdata-node");
export default class FooBoot implements IBoot {
private readonly app: Application;
@@ -16,7 +18,7 @@ export default class FooBoot implements IBoot {
// this is the last chance to modify the config.
await this.connectDB(this.app);
await this.connectRedis(this.app);
this.connectThinkingData(this.app);
}
configDidLoad() {
@@ -64,6 +66,28 @@ export default class FooBoot implements IBoot {
app.context.redisClient = redisClient;
}
}
public connectThinkingData(app: Application) {
let ta;
if(THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.DEBUG) {
ta = ThinkingAnalytics.initWithDebugMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.BATCH) {
ta = ThinkingAnalytics.initWithBatchMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.LOGGING) {
ta = ThinkingAnalytics.initWithLoggingMode(SDK_TA_CONST.LOG_PATH, {
pm2: true
});
}
// ta.setDynamicSuperProperties(() => {
// return {
// env: app.get('env'),
// server: app.getServerId(),
// mode: THINKING_DATA_MODE
// };
// });
app.context.ta = ta;
}
//#endregion
}