数数:埋点
This commit is contained in:
+25
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user