diff --git a/src/components/home/Content/CardContent/CardContentItem/index.js b/src/components/home/Content/CardContent/CardContentItem/index.js index b39be3ba67..2b761c66ad 100644 --- a/src/components/home/Content/CardContent/CardContentItem/index.js +++ b/src/components/home/Content/CardContent/CardContentItem/index.js @@ -4,6 +4,7 @@ import LearnMore from '../../LearnMore' import clsx from 'clsx' import { InfoContext } from '@/context' import { useContext } from 'react' +import { useUtmParams } from '@/hooks/useUtmParams' const CardContentItem = ({ imageSrc, @@ -15,6 +16,7 @@ const CardContentItem = ({ reverse, }) => { const { t } = useTranslation('home') + const utmUrl = useUtmParams(moreHref) const info = useContext(InfoContext) return (
@@ -33,7 +35,7 @@ const CardContentItem = ({ {t(title)} {t(desc)} - +
diff --git a/src/components/home/Content/MoreTemplate/index.js b/src/components/home/Content/MoreTemplate/index.js index 01767826f0..bd021f37cd 100644 --- a/src/components/home/Content/MoreTemplate/index.js +++ b/src/components/home/Content/MoreTemplate/index.js @@ -3,6 +3,7 @@ import style from './index.module.css' import LearnMore from '../LearnMore' import { useContext } from 'react' import { InfoContext } from '@/context' +import { useUtmParams } from '@/hooks/useUtmParams' const MORE_TEMPLATE_CONTENT = { title: 'template.title.quickly_start_from_a', @@ -42,47 +43,52 @@ const MORE_TEMPLATE_CONTENT = { ], } +const MoeTemplateItem = ({ content, isMobile }) => { + const { + templateDesc, + templateMoreHref, + templateMoreTitle, + templateSrc, + templateTitle, + mobileTemplateSrc, + } = content + const { t } = useTranslation('home') + const utmTemplateDetailUrl = useUtmParams(templateMoreHref) + return ( +
+ +
+

{t(templateTitle)}

+

{t(templateDesc)}

+ +
+
+ ) +} + const MoreTemplate = () => { const { t } = useTranslation('home') const info = useContext(InfoContext) + const utmMoreUrl = useUtmParams(MORE_TEMPLATE_CONTENT.href) + return (

{t(MORE_TEMPLATE_CONTENT.title)}

- +
- {MORE_TEMPLATE_CONTENT.items.map( - ({ - templateDesc, - templateMoreHref, - templateMoreTitle, - templateSrc, - templateTitle, - mobileTemplateSrc, - }) => ( -
- -
-

- {t(templateTitle)} -

-

{t(templateDesc)}

- -
-
- ), - )} + {MORE_TEMPLATE_CONTENT.items.map((content) => ( + + ))}
) diff --git a/src/constants/utmKeys.js b/src/constants/utmKeys.js new file mode 100644 index 0000000000..2a99cd186c --- /dev/null +++ b/src/constants/utmKeys.js @@ -0,0 +1 @@ +export const keys = ['utm_source', 'utm_medium', 'utm_campaign'] diff --git a/src/hooks/useUtmParams.js b/src/hooks/useUtmParams.js index c08a3fbe80..ac28ff087a 100644 --- a/src/hooks/useUtmParams.js +++ b/src/hooks/useUtmParams.js @@ -1,12 +1,15 @@ import { useRouter } from 'next/router' import { addParams } from '@/utils/addParams' +import { keys } from '@/constants/utmKeys' export const useUtmParams = (url) => { const router = useRouter() - const keys = ['utm_source', 'utm_medium', 'utm_campaign'] - if (router?.query && Object.keys(router?.query).some(key => keys.includes(key))) { + if ( + router?.query && + Object.keys(router?.query).some((key) => keys.includes(key)) + ) { const { utm_source, utm_medium, utm_campaign } = router.query return addParams(url, { utm_source, utm_medium, utm_campaign }) } else { return url } -} \ No newline at end of file +} diff --git a/src/pages/[pageName].js b/src/pages/[pageName].js index ef1e383623..5eeed95ba1 100644 --- a/src/pages/[pageName].js +++ b/src/pages/[pageName].js @@ -95,7 +95,7 @@ const LandingPageIndex = ({ pageName, uri, isMobile }) => { ) } -export const getServerSideProps = async ({ locale, params, req }) => { +export const getServerSideProps = async ({ locale, params, req, query }) => { const { pageName } = params if (!pageMap[pageName]) { return { @@ -105,7 +105,7 @@ export const getServerSideProps = async ({ locale, params, req }) => { }, } } - const uri = await getGithubOauth() + const uri = await getGithubOauth(query) return { props: { diff --git a/src/pages/[pageName]/[name].js b/src/pages/[pageName]/[name].js index 73bbbe5ac7..6073cde096 100644 --- a/src/pages/[pageName]/[name].js +++ b/src/pages/[pageName]/[name].js @@ -1,10 +1,9 @@ -import { useEffect, useState } from 'react' +import { useEffect } from 'react' import Nav from '@/components/common/Nav' import Footer from '@/components/common/Footer' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import Head from 'next/head' import { useTranslation } from 'next-i18next' -import { BookDemo } from '@/components/home/Form/BookDemo' import style from '@/components/LandingPage/index.module.css' import { LpHeader } from '@/components/LandingPage/LpHeader' import { LpTemplate } from '@/components/LandingPage/LpTemplate' @@ -85,7 +84,7 @@ const LandingPageSecond = ({ pageName, name, locale, uri, isMobile }) => { ) } -export const getServerSideProps = async ({ locale, params, req }) => { +export const getServerSideProps = async ({ locale, params, req, query }) => { const { pageName, name } = params if (!pageMap[pageName]) { return { @@ -95,7 +94,7 @@ export const getServerSideProps = async ({ locale, params, req }) => { }, } } - const uri = await getGithubOauth() + const uri = await getGithubOauth(query) return { props: { ...(await serverSideTranslations(locale, [ diff --git a/src/pages/illa-self-host.js b/src/pages/illa-self-host.js index 688aa62a02..6302c2f576 100644 --- a/src/pages/illa-self-host.js +++ b/src/pages/illa-self-host.js @@ -43,8 +43,8 @@ const Cloud = ({ uri, isMobile }) => { ) } -export const getServerSideProps = async ({ locale, req }) => { - const uri = await getGithubOauth() +export const getServerSideProps = async ({ locale, req, query }) => { + const uri = await getGithubOauth(query) return { props: { ...(await serverSideTranslations(locale, [ diff --git a/src/pages/illacloud.js b/src/pages/illacloud.js index 8b1fc948e4..bcab51e360 100644 --- a/src/pages/illacloud.js +++ b/src/pages/illacloud.js @@ -47,8 +47,8 @@ const Cloud = ({ uri, isMobile }) => { ) } -export const getServerSideProps = async ({ locale, req }) => { - const uri = await getGithubOauth() +export const getServerSideProps = async ({ locale, req, query }) => { + const uri = await getGithubOauth(query) return { props: { ...(await serverSideTranslations(locale, [ diff --git a/src/pages/illadrive.js b/src/pages/illadrive.js index a2e9e1aa4c..b91b4f4cb7 100644 --- a/src/pages/illadrive.js +++ b/src/pages/illadrive.js @@ -46,8 +46,8 @@ const Drive = ({ uri, isMobile }) => { ) } -export const getServerSideProps = async ({ locale, req }) => { - const uri = await getGithubOauth() +export const getServerSideProps = async ({ locale, req, query }) => { + const uri = await getGithubOauth(query) return { props: { ...(await serverSideTranslations(locale, ['drive', 'home', 'common'])), diff --git a/src/pages/index.js b/src/pages/index.js index 7cb1918f43..f3c01e4276 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -48,22 +48,7 @@ const Home = ({ starCounts, uri, isMobile }) => {