数数:埋点
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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE } from '@consts';
|
||||
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE, TA_EVENT } from '@consts';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { UserModel, UserType } from '@db/User';
|
||||
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
||||
@@ -389,9 +389,9 @@ export default class Auth extends Service {
|
||||
* @returns
|
||||
*/
|
||||
public async channelLogin(params: {
|
||||
channelType: string, pst: string, clientId: string, deviceId: string, platform: string, platformAppid: string, childGameId: number, pkgName: string, serverType: string, getuiCID: string
|
||||
channelType: string, pst: string, clientId: string, deviceId: string, platform: string, platformAppid: string, childGameId: number, pkgName: string, serverType: string, getuiCID: string, distinctId: string
|
||||
}) {
|
||||
const { channelType, pst, clientId, deviceId, platform, platformAppid, childGameId, pkgName, serverType, getuiCID } = params;
|
||||
const { channelType, pst, clientId, deviceId, platform, platformAppid, childGameId, pkgName, serverType, getuiCID, distinctId } = params;
|
||||
|
||||
const ctx = this.ctx;
|
||||
const ip = ctx.request.ip;
|
||||
@@ -405,9 +405,13 @@ export default class Auth extends Service {
|
||||
|
||||
let channelId = getChannelId(channelType, requestResult.data.uid);
|
||||
const token = ctx.service.utils.generateStr(256);
|
||||
let user = await UserModel.createOrUpdateChannelUser(channelId, channelType, {
|
||||
let { isCreate, user} = await UserModel.createOrUpdateChannelUser(channelId, channelType, {
|
||||
...requestResult.data, childGameId, platformAppid
|
||||
}, token, platform, pkgName, serverType, deviceId, ip);
|
||||
if(isCreate) {
|
||||
ctx.service.sdk.reportTAEventWithDistinctId(distinctId, TA_EVENT.REGISTER, null, ip);
|
||||
}
|
||||
|
||||
if (getuiCID) {//更新个推cid
|
||||
await UserModel.updateGetuiCIDByChannel(channelId, getuiCID);
|
||||
}
|
||||
|
||||
@@ -258,4 +258,28 @@ export default class Sdk extends Service {
|
||||
msg: '成功'
|
||||
}
|
||||
}
|
||||
|
||||
public reportTAEventWithDistinctId(distinctId: string, eventName: string, properties: any, ip: string) {
|
||||
let ta = this.app.context.ta;
|
||||
let event = {
|
||||
// 账号 ID (可选)
|
||||
accountId: "",
|
||||
// 访客 ID (可选),账号 ID 和访客 ID 不可以都为空
|
||||
distinctId: `${distinctId}`,
|
||||
// 事件名称 (必填)
|
||||
event: eventName,
|
||||
// 事件时间 (可选) 如果不填,将以调用接口时的时间作为事件时间
|
||||
time: new Date(),
|
||||
// 事件 IP (可选) 当传入 IP 地址时,后台可以解析所在地
|
||||
ip: ip,
|
||||
// 事件属性 (可选)
|
||||
properties,
|
||||
callback(err) {
|
||||
console.log('*****测试接入事件', err)
|
||||
}
|
||||
|
||||
};
|
||||
ta.track(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Generated
+65
-4
@@ -3343,6 +3343,11 @@
|
||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-1.2.0.tgz",
|
||||
"integrity": "sha512-vKQ9DTQPN1FLYiiEEOQ6IBGFqvjCa5rSK3cWMy/Nespm5d/x3dGFT9UBZnkLxCwua/IXBi2TYnwTEpsOvhC4UQ=="
|
||||
},
|
||||
"date-format": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/date-format/-/date-format-2.1.0.tgz",
|
||||
"integrity": "sha512-bYQuGLeFxhkxNOF3rcMtiZxvCBAquGzZm6oWA1oZ0g2THUzivaRhv8uOhdr19LmoobSOLoIAxeUK2RdbM8IFTA=="
|
||||
},
|
||||
"debounce": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.0.tgz",
|
||||
@@ -5685,8 +5690,7 @@
|
||||
"flatted": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz",
|
||||
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA=="
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
@@ -5743,6 +5747,16 @@
|
||||
"resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz",
|
||||
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"fs-minipass": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
|
||||
@@ -5994,8 +6008,7 @@
|
||||
"graceful-fs": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
|
||||
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
|
||||
},
|
||||
"graceful-process": {
|
||||
"version": "1.2.0",
|
||||
@@ -6871,6 +6884,14 @@
|
||||
"integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=",
|
||||
"dev": true
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"jsonp-body": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonp-body/-/jsonp-body-1.0.0.tgz",
|
||||
@@ -7160,6 +7181,18 @@
|
||||
"chalk": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"log4js": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/log4js/-/log4js-5.3.0.tgz",
|
||||
"integrity": "sha512-PZHXaXJKMKEscvQxSnTjM4UosQalSDlNpMw63eCKW+/DiAFKIZPW1jGyIPXZDjiEYFusMfiI7zzvnxeGozUcAw==",
|
||||
"requires": {
|
||||
"date-format": "^2.1.0",
|
||||
"debug": "^4.1.1",
|
||||
"flatted": "^2.0.1",
|
||||
"rfdc": "^1.1.4",
|
||||
"streamroller": "^2.2.2"
|
||||
}
|
||||
},
|
||||
"long": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
|
||||
@@ -9894,6 +9927,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
|
||||
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg=="
|
||||
},
|
||||
"rfdc": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
|
||||
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
|
||||
@@ -10461,6 +10499,16 @@
|
||||
"resolved": "https://registry.npmjs.org/stream-wormhole/-/stream-wormhole-1.1.0.tgz",
|
||||
"integrity": "sha512-gHFfL3px0Kctd6Po0M8TzEvt3De/xu6cnRrjlfYNhwbhLPLwigI2t1nc6jrzNuaYg5C4YF78PPFuQPzRiqn9ew=="
|
||||
},
|
||||
"streamroller": {
|
||||
"version": "2.2.4",
|
||||
"resolved": "https://registry.npmjs.org/streamroller/-/streamroller-2.2.4.tgz",
|
||||
"integrity": "sha512-OG79qm3AujAM9ImoqgWEY1xG4HX+Lw+yY6qZj9R1K2mhF5bEmQ849wvrb+4vt4jLMLzwXttJlQbOdPOQVRv7DQ==",
|
||||
"requires": {
|
||||
"date-format": "^2.1.0",
|
||||
"debug": "^4.1.1",
|
||||
"fs-extra": "^8.1.0"
|
||||
}
|
||||
},
|
||||
"streamsearch": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
|
||||
@@ -10822,6 +10870,14 @@
|
||||
"thenify": ">= 3.1.0 < 4"
|
||||
}
|
||||
},
|
||||
"thinkingdata-node": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/thinkingdata-node/-/thinkingdata-node-1.2.2.tgz",
|
||||
"integrity": "sha512-U5Nz2/OsFj3oFGboo/OmQcc1bcbibNJm2KVMPy7JpIVdYAH8U/VKzXCHfuVvbGSalLAdvMiBklL49r5uQnVqvw==",
|
||||
"requires": {
|
||||
"log4js": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"throat": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/throat/-/throat-4.1.0.tgz",
|
||||
@@ -11157,6 +11213,11 @@
|
||||
"object-keys": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||
},
|
||||
"unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"request": "^2.88.2",
|
||||
"request-promise": "^4.2.6",
|
||||
"thinkingdata-node": "^1.2.2",
|
||||
"underscore": "^1.13.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user