diff --git a/web/app/components/swr-initor.tsx b/web/app/components/swr-initor.tsx index ae27738d42850..61a4344fc6d37 100644 --- a/web/app/components/swr-initor.tsx +++ b/web/app/components/swr-initor.tsx @@ -15,6 +15,14 @@ const SwrInitor = ({ const searchParams = useSearchParams() const consoleToken = searchParams.get('console_token') const consoleTokenFromLocalStorage = localStorage?.getItem('console_token') + const utm = { + utm_source: searchParams.get('utm_source') || '', + utm_medium: searchParams.get('utm_medium') || '', + utm_campaign: searchParams.get('utm_campaign') || '', + utm_content: searchParams.get('utm_content') || '', + utm_term: searchParams.get('utm_term') || '', + } + localStorage?.setItem('utm', JSON.stringify(utm)) const [init, setInit] = useState(false) useEffect(() => { @@ -23,7 +31,7 @@ const SwrInitor = ({ if (consoleToken) { localStorage?.setItem('console_token', consoleToken!) - router.replace('/apps', { forceOptimisticNavigation: false }) + router.replace('/apps', { forceOptimisticNavigation: false } as any) } setInit(true) }, []) diff --git a/web/context/provider-context.tsx b/web/context/provider-context.tsx index 56d6bc04038ca..ae8b8dbbf1806 100644 --- a/web/context/provider-context.tsx +++ b/web/context/provider-context.tsx @@ -7,6 +7,7 @@ import { fetchModelList, fetchModelProviders, fetchSupportRetrievalMethods, + operationUtm, } from '@/service/common' import { ModelFeatureEnum, @@ -97,6 +98,23 @@ export const ProviderContextProvider = ({ const [isFetchedPlan, setIsFetchedPlan] = useState(false) const [enableBilling, setEnableBilling] = useState(true) const [enableReplaceWebAppLogo, setEnableReplaceWebAppLogo] = useState(false) + + const handleOperateUtm = () => { + let utm + try { + utm = JSON.parse(localStorage?.getItem('utm') || '{}') + } + catch (e) { + utm = { + utm_source: '', + utm_medium: '', + utm_campaign: '', + utm_content: '', + utm_term: '', + } + } + operationUtm({ url: '/operation/utm', body: utm }) + } useEffect(() => { (async () => { const data = await fetchCurrentPlanInfo() @@ -105,13 +123,7 @@ export const ProviderContextProvider = ({ setEnableReplaceWebAppLogo(data.can_replace_logo) if (enabled) { setPlan(parseCurrentPlan(data)) - // setPlan(parseCurrentPlan({ - // ...data, - // annotation_quota_limit: { - // ...data.annotation_quota_limit, - // limit: 10, - // }, - // })) + handleOperateUtm() setIsFetchedPlan(true) } })() diff --git a/web/models/common.ts b/web/models/common.ts index f8038d5d3507f..5f8795688ee2f 100644 --- a/web/models/common.ts +++ b/web/models/common.ts @@ -251,3 +251,11 @@ export type ModerationService = ( text: string } ) => Promise + +export type Utm = { + utm_source?: string + utm_medium?: string + utm_campaign?: string + utm_term?: string + utm_content?: string +} diff --git a/web/service/common.ts b/web/service/common.ts index a3a1c7c8118f3..2ae3cf964679d 100644 --- a/web/service/common.ts +++ b/web/service/common.ts @@ -20,6 +20,7 @@ import type { ProviderAzureToken, SetupStatusResponse, UserProfileOriginResponse, + Utm, } from '@/models/common' import type { UpdateOpenAIKeyResponse, @@ -262,3 +263,7 @@ type RetrievalMethodsRes = { export const fetchSupportRetrievalMethods: Fetcher = (url) => { return get(url) } + +export const operationUtm: Fetcher = ({ url, body }) => { + return post(url, { body }) as Promise +}