File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
global/common/middle/tracks
service/common/middle/tracks
projects/app/src/pages/api/support/user/account Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11export enum TrackEnum {
22 login = 'login' ,
3+ dailyUserActive = 'dailyUserActive' ,
34 createApp = 'createApp' ,
45 useAppTemplate = 'useAppTemplate' ,
56 createDataset = 'createDataset' ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type { AppTypeEnum } from '@fastgpt/global/core/app/constants';
77import type { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants' ;
88import { getAppLatestVersion } from '../../../core/app/version/controller' ;
99import { type ShortUrlParams } from '@fastgpt/global/support/marketing/type' ;
10+ import { getRedisCache , setRedisCache } from '../../redis/cache' ;
1011
1112const createTrack = ( { event, data } : { event : TrackEnum ; data : Record < string , any > } ) => {
1213 if ( ! global . feConfigs ?. isPlus ) return ;
@@ -66,8 +67,31 @@ export const pushTrack = {
6667 return createTrack ( {
6768 event : TrackEnum . login ,
6869 data
70+ } ) ?. then ( ( ) => {
71+ pushTrack . dailyUserActive ( {
72+ uid : data . uid ,
73+ teamId : data . teamId ,
74+ tmbId : data . tmbId
75+ } ) ;
6976 } ) ;
7077 } ,
78+ dailyUserActive : async ( data : PushTrackCommonType ) => {
79+ try {
80+ const today = new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
81+ const key = `dailyUserActive:${ data . uid } _${ today } ` ;
82+ const cache = await getRedisCache ( key ) ;
83+ if ( cache ) return ;
84+
85+ await setRedisCache ( key , '1' , 24 * 60 * 60 ) ;
86+
87+ return createTrack ( {
88+ event : TrackEnum . dailyUserActive ,
89+ data
90+ } ) ;
91+ } catch ( error ) {
92+ addLog . error ( 'Failed to track daily user active:' , error ) ;
93+ }
94+ } ,
7195 createApp : (
7296 data : PushTrackCommonType &
7397 ShortUrlParams & {
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { getUserDetail } from '@fastgpt/service/support/user/controller';
33import type { ApiRequestProps , ApiResponseType } from '@fastgpt/service/type/next' ;
44import { NextAPI } from '@/service/middleware/entry' ;
55import { type UserType } from '@fastgpt/global/support/user/type' ;
6+ import { pushTrack } from '@fastgpt/service/common/middle/tracks/utils' ;
7+ import { getGlobalRedisConnection } from '@fastgpt/service/common/redis' ;
68
79export type TokenLoginQuery = { } ;
810export type TokenLoginBody = { } ;
@@ -12,9 +14,15 @@ async function handler(
1214 req : ApiRequestProps < TokenLoginBody , TokenLoginQuery > ,
1315 _res : ApiResponseType < any >
1416) : Promise < TokenLoginResponse > {
15- const { tmbId } = await authCert ( { req, authToken : true } ) ;
17+ const { tmbId, userId , teamId } = await authCert ( { req, authToken : true } ) ;
1618 const user = await getUserDetail ( { tmbId } ) ;
1719
20+ pushTrack . dailyUserActive ( {
21+ uid : userId ,
22+ teamId : teamId ,
23+ tmbId : tmbId
24+ } ) ;
25+
1826 // Remove sensitive information
1927 // if (user.team.lafAccount) {
2028 // user.team.lafAccount = {
You can’t perform that action at this time.
0 commit comments