From 572c2ed9208a25bb11eab1e37c0e046c2b33ffdc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 15:39:46 +0000 Subject: [PATCH] =?UTF-8?q?feat(growth):=20UTM=20=E8=B7=9F=E8=B8=AA=20doc?= =?UTF-8?q?=20=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5=20+=20turbopack=20root?= =?UTF-8?q?=20=E9=94=81=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 恢复自 i18n PR 之前 stash 出来的 utm-tracking 工作。 UTM 跟踪: - README badge / logo 链接加 utm_source=github,utm_medium=readme, utm_campaign={logo,badge},让 GA Source 维度看到 GitHub 入站流量 - DocShareButton 复制链接时打 utm_source=doc_share,utm_medium=user_share, 用户分享到 DC/微信/X 后回流在 GA 看到,区别于 (direct)/(none) turbopack root: - next.config.mjs 显式锁定 turbopack root 和 outputFileTracingRoot 到 frontend/ 自己目录。Next.js 16 默认会向上搜 lockfile 推 workspace root, 开发机上 /home/ubuntu/package-lock.json 之类的会把 root 推到上层, turbopack 解析 node_modules 错位 → "Can't resolve 'tailwindcss'" 类报错。 --- README.en.md | 4 ++-- README.md | 4 ++-- app/components/DocShareButton.tsx | 7 ++++++- next.config.mjs | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.en.md b/README.en.md index 8f6c6fb2..52cc6cf8 100644 --- a/README.en.md +++ b/README.en.md @@ -3,7 +3,7 @@

- + @@ -21,7 +21,7 @@ Next.js Vercel - + Official Website

diff --git a/README.md b/README.md index 3806d707..f214e01f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- + @@ -21,7 +21,7 @@ Next.js Vercel - + Official Website

diff --git a/app/components/DocShareButton.tsx b/app/components/DocShareButton.tsx index a92d64db..d2934573 100644 --- a/app/components/DocShareButton.tsx +++ b/app/components/DocShareButton.tsx @@ -20,7 +20,12 @@ export function DocShareButton() { }, []); const handleCopy = async () => { - const url = window.location.href; + // 用户点"复制链接"必然是要发到外面(DC/微信/X) + // 给链接打上 UTM,回流时能在 GA Source 维度看到 doc_share,区别于 (direct) + const target = new URL(window.location.href); + target.searchParams.set("utm_source", "doc_share"); + target.searchParams.set("utm_medium", "user_share"); + const url = target.toString(); try { await navigator.clipboard.writeText(url); setCopied(true); diff --git a/next.config.mjs b/next.config.mjs index 79863feb..e2e25af6 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,8 +1,18 @@ // next.config.mjs +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { createMDX } from "fumadocs-mdx/next"; import createNextIntlPlugin from "next-intl/plugin"; import { withSentryConfig } from "@sentry/nextjs"; +// Next.js 16 detects multi-lockfile environments by searching upward for +// pnpm-lock.yaml / package-lock.json / yarn.lock. 当父目录意外有 lockfile +// 时(如开发服务器上 /home/ubuntu/package-lock.json),Next 会把 workspace +// root 推到上层,turbopack 跟着到错的目录解析 node_modules, +// 触发 "Can't resolve 'tailwindcss'" 之类报错。 +// 显式锁定到 frontend 自己目录,turbopack + outputFileTracing 双保险。 +const projectRoot = path.dirname(fileURLToPath(import.meta.url)); + /** * IMPORTANT: remarkImage 配置已移至 source.config.ts 统一管理 * @@ -22,6 +32,12 @@ const withNextIntl = createNextIntlPlugin("./i18n/request.ts"); /** @type {import('next').NextConfig} */ const config = { reactStrictMode: true, + // 强制锁定 turbopack 和 SSR file tracing 的根目录到 frontend/ 自己, + // 避免上层意外 lockfile 把 root 推错(详见文件顶部注释)。 + turbopack: { + root: projectRoot, + }, + outputFileTracingRoot: projectRoot, /** * docs 目录整理产生的 URL 变化 → 301 重定向。 *