数数:创建角色埋点放到服务器

This commit is contained in:
luying
2022-02-26 11:52:14 +08:00
parent e478a41d9f
commit 87ce274831
4 changed files with 30 additions and 5 deletions
+1
View File
@@ -929,6 +929,7 @@ export enum ITEM_CHANGE_REASON {
export enum TA_EVENT { export enum TA_EVENT {
REGISTER = 'register', // 注册 REGISTER = 'register', // 注册
CREATE_ROLE = 'create_role', // 创建角色
RECHARGE = 'recharge', // 发起充值 RECHARGE = 'recharge', // 发起充值
RECHARGE_SUCCESS = 'recharge_success', // 充值成功 RECHARGE_SUCCESS = 'recharge_success', // 充值成功
RECHARGE_FAIL = 'recharge_fail', // 充值失败 RECHARGE_FAIL = 'recharge_fail', // 充值失败
+2 -2
View File
@@ -46,8 +46,8 @@ export default class AccountController extends Controller {
public async createRole() { public async createRole() {
const { ctx } = this; const { ctx } = this;
const { serverId } = ctx.request.body; const { serverId, distinctId } = ctx.request.body;
ctx.body = await ctx.service.auth.createRole(serverId); ctx.body = await ctx.service.auth.createRole(serverId, distinctId);
} }
public async bind() { public async bind() {
+4 -3
View File
@@ -302,7 +302,7 @@ export default class Auth extends Service {
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND); return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
} }
public async createRole(serverId: number) { public async createRole(serverId: number, distinctId: string) {
console.log('enter Auth createRole'); console.log('enter Auth createRole');
const ctx = this.ctx; const ctx = this.ctx;
const { uid } = ctx; const { uid } = ctx;
@@ -324,6 +324,7 @@ export default class Auth extends Service {
// 任务 // 任务
await checkTask(roleId, TASK_TYPE.ROLE_LV, role.lv, false, {}); await checkTask(roleId, TASK_TYPE.ROLE_LV, role.lv, false, {});
ctx.service.sdk.reportTAEventWithRoleIdAndDistinctId(roleId, distinctId, TA_EVENT.REGISTER, null, ctx.clientIp);
return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId }); return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId });
} }
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND); return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
@@ -401,7 +402,7 @@ export default class Auth extends Service {
public async channelLogin(params: { public async channelLogin(params: {
channelType: string, pst: string, clientId: string, deviceId: string, platform: string, platformAppid: string, childGameId: number, pkgName: string, serverType: string, getuiCID: string, distinctId: 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, distinctId } = params; const { channelType, pst, clientId, deviceId, platform, platformAppid, childGameId, pkgName, serverType, getuiCID } = params;
const ctx = this.ctx; const ctx = this.ctx;
@@ -418,7 +419,7 @@ export default class Auth extends Service {
...requestResult.data, childGameId, platformAppid ...requestResult.data, childGameId, platformAppid
}, token, platform, pkgName, serverType, deviceId, ctx.clientIp); }, token, platform, pkgName, serverType, deviceId, ctx.clientIp);
if(isCreate) { if(isCreate) {
ctx.service.sdk.reportTAEventWithDistinctId(distinctId, TA_EVENT.REGISTER, null, ctx.clientIp); // ctx.service.sdk.reportTAEventWithDistinctId(distinctId, TA_EVENT.REGISTER, null, ctx.clientIp);
} }
if (getuiCID) {//更新个推cid if (getuiCID) {//更新个推cid
+23
View File
@@ -277,4 +277,27 @@ export default class Sdk extends Service {
ta.track(event); ta.track(event);
} }
public reportTAEventWithRoleIdAndDistinctId(roleId: string, distinctId: string, eventName: string, properties: any, ip?: string) {
let ta = this.app.context.ta;
let event = {
// 账号 ID (可选)
accountId: `${roleId}`,
// 访客 ID (可选),账号 ID 和访客 ID 不可以都为空
distinctId: distinctId? `${distinctId}`: "",
// 事件名称 (必填)
event: eventName,
// 事件时间 (可选) 如果不填,将以调用接口时的时间作为事件时间
time: new Date(),
// 事件 IP (可选) 当传入 IP 地址时,后台可以解析所在地
ip: ip,
// 事件属性 (可选)
properties,
callback(err) {
console.log('*****测试接入事件', err)
}
};
ta.track(event);
}
} }