diff --git a/.gitignore b/.gitignore index 3907999..f63ba5f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ node_modules .next out + +# ide +.vscode +.idea diff --git a/.vscode/settings.json b/.vscode/settings.json index dc3fa81..4debe86 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ - "Turborepo", - "Turbopack" + "gtag", + "Turbopack", + "Turborepo" ] } diff --git a/README.md b/README.md new file mode 100644 index 0000000..25716a1 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Turbo 中文文档 + +这里是 Turbo 的中文文档翻译项目,欢迎大家加入 + +## 如何参与翻译 + +1. 在 `project` 这边领取任务,[前往 project](https://github.com/orgs/turbo-cn/projects/1/views/1) +2. 在 `project` 确定好要翻译的任务后,将对应的任务转换成 `issue`,并拖入 `In Progress` 阶段 +3. 在上一步转换的 `issue` 下评论 `该章节由我翻译` 或者 `Assignees` 给自己 +4. `fork` 并 `clone` 仓库(如果你已经做过此步则跳过) +5. 开始本地翻译,如果本地运行项目请参考下面的章节 + +## 如何运行项目 + +在你已经 clone 项目到本地之后,进入项目目录,执行以下命令,如果你使用其他包管理器,例如 `yarn` `pnpm` 请根据实际情况替换命令。 + +```bash +npm install +npm run dev +``` + +## 翻译注意点 + +1. 应尽量避免非翻译文本内容之外的改动 +2. 确保每个可跳转路由可以准确跳转 diff --git a/components/GoogleAnalytics.tsx b/components/GoogleAnalytics.tsx new file mode 100644 index 0000000..258ac8e --- /dev/null +++ b/components/GoogleAnalytics.tsx @@ -0,0 +1,44 @@ +import Script from 'next/script' +import { useRouter } from 'next/router' +import { useEffect, useMemo } from 'react' + +const GA_TRACKING_ID = 'G-K2NP44GKV1' + +export default () => { + const router = useRouter() + console.log('router', router) + + const script = useMemo(() => ` + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '${GA_TRACKING_ID}', { + page_path: window.location.pathname, + }); + `, []) + + useEffect(() => { + const handleRouteChange = url => { + if (router == null || router.events == null) return + + if ('gtag' in window && typeof window.gtag === 'function') { + window.gtag('config', GA_TRACKING_ID, { page_path: url }) + } else { + console.error('window.gtag is undefined or not function!') + } + } + + router.events.on('routeChangeComplete', handleRouteChange) + return () => router.events.off('routeChangeComplete', handleRouteChange) + }, [router]) + + return ( + <> +