@@ -17,24 +17,57 @@ import {
1717} from '../support/marketing/utils' ;
1818import { ShortUrlParams } from '@fastgpt/global/support/marketing/type' ;
1919
20+ type MarketingQueryParams = {
21+ hiId ?: string ;
22+ bd_vid ?: string ;
23+ k ?: string ;
24+ sourceDomain ?: string ;
25+ utm_source ?: string ;
26+ utm_medium ?: string ;
27+ utm_content ?: string ;
28+ utm_workflow ?: string ;
29+ } ;
30+
31+ const MARKETING_PARAMS : ( keyof MarketingQueryParams ) [ ] = [
32+ 'hiId' ,
33+ 'bd_vid' ,
34+ 'k' ,
35+ 'sourceDomain' ,
36+ 'utm_source' ,
37+ 'utm_medium' ,
38+ 'utm_content' ,
39+ 'utm_workflow'
40+ ] ;
41+
2042export const useInitApp = ( ) => {
2143 const router = useRouter ( ) ;
2244 const { hiId, bd_vid, k, sourceDomain, utm_source, utm_medium, utm_content, utm_workflow } =
23- router . query as {
24- hiId ?: string ;
25- bd_vid ?: string ;
26- k ?: string ;
27- sourceDomain ?: string ;
28- utm_source ?: string ;
29- utm_medium ?: string ;
30- utm_content ?: string ;
31- utm_workflow ?: string ;
32- } ;
45+ router . query as MarketingQueryParams ;
3346 const { loadGitStar, setInitd, feConfigs } = useSystemStore ( ) ;
3447 const { userInfo } = useUserStore ( ) ;
3548 const [ scripts , setScripts ] = useState < FastGPTFeConfigsType [ 'scripts' ] > ( [ ] ) ;
3649 const [ title , setTitle ] = useState ( process . env . SYSTEM_NAME || 'AI' ) ;
3750
51+ const getPathWithoutMarketingParams = ( ) => {
52+ const filteredQuery = { ...router . query } ;
53+ MARKETING_PARAMS . forEach ( ( param ) => {
54+ delete filteredQuery [ param ] ;
55+ } ) ;
56+
57+ const newQuery = new URLSearchParams ( ) ;
58+ Object . entries ( filteredQuery ) . forEach ( ( [ key , value ] ) => {
59+ if ( value ) {
60+ if ( Array . isArray ( value ) ) {
61+ value . forEach ( ( v ) => newQuery . append ( key , v ) ) ;
62+ } else {
63+ newQuery . append ( key , value ) ;
64+ }
65+ }
66+ } ) ;
67+
68+ return `${ router . pathname } ${ newQuery . toString ( ) ? `?${ newQuery . toString ( ) } ` : '' } ` ;
69+ } ;
70+
3871 const initFetch = useMemoizedFn ( async ( ) => {
3972 const {
4073 feConfigs : { scripts, isPlus, systemTitle }
@@ -98,7 +131,8 @@ export const useInitApp = () => {
98131 setUtmParams ( utmParams ) ;
99132 setFastGPTSem ( { keyword : k , ...utmParams } ) ;
100133
101- router . replace ( router . pathname ) ;
134+ const newPath = getPathWithoutMarketingParams ( ) ;
135+ router . replace ( newPath ) ;
102136 } ) ;
103137
104138 return {
0 commit comments