From bbd86e4119f1096e4f53a171347fa20baf1e0b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=AE=87=E5=AE=81?= Date: Sat, 17 Oct 2026 09:59:58 +0700 Subject: [PATCH] =?UTF-8?q?yandex=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- config/development.env | 2 ++ config/production.env | 2 ++ config/test.env | 2 ++ src/app/layout.tsx | 3 ++- src/components/analytics/YandexMetrika.tsx | 23 ++++++++++++++++++++++ src/server/config.ts | 2 ++ 7 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/components/analytics/YandexMetrika.tsx diff --git a/README.md b/README.md index c700c03..0c39672 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ APP_DEEP_LINK_URL= 平台地址未配置时,按钮显示“前往下载页”,沿用上游 `AppAddr` 或 `/app/download/` 跳转;未配置 App 深链时隐藏打开 App 入口。链接保留原始跳转地址,不生成设计示例中的安装包、描述文件或 App Store 地址。 -谷歌统计(GA4)由 `GOOGLE_ANALYTICS_ID` 配置,三套环境默认 `G-269F3ZFQFQ`,在根布局通过 `next/script` 于页面可交互后加载;留空即关闭。 +谷歌统计(GA4)由 `GOOGLE_ANALYTICS_ID` 配置,三套环境默认 `G-269F3ZFQFQ`,在根布局通过 `next/script` 于页面可交互后加载;留空即关闭。Yandex.Metrika 由 `YANDEX_METRIKA_ID` 配置,三套环境默认 `113657403`,同样在根布局加载并带 noscript 像素;留空即关闭。 所有 Telegram 联系入口(页尾、官方导航、回家的路、播放页链接、2257/DMCA、意见反馈,以及 Telegram 形式的「联系我们」客服链接)统一使用 `CONTACT_TELEGRAM_URL`,三套环境默认 `https://t.me/jbd125`,覆盖上游 `tgGroup`、`telegram`、`telegramAdd`。值无效时回退为默认账号。 diff --git a/config/development.env b/config/development.env index 6f469cd..7aedf71 100644 --- a/config/development.env +++ b/config/development.env @@ -19,6 +19,8 @@ SEO_BAIDU_SITE_VERIFICATION= SEO_BAIDU_HTML_FILE= # Google Analytics 4 measurement ID; leave empty to disable. GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ +# Yandex.Metrika counter ID; leave empty to disable. +YANDEX_METRIKA_ID=113657403 # Telegram contact for every TG entry (footer, navigation, return-home, legal pages, customer service). CONTACT_TELEGRAM_URL=https://t.me/jbd125 APP_IOS_STORE_URL= diff --git a/config/production.env b/config/production.env index 2316d8d..c362650 100644 --- a/config/production.env +++ b/config/production.env @@ -15,6 +15,8 @@ SEO_BAIDU_SITE_VERIFICATION= SEO_BAIDU_HTML_FILE= # Google Analytics 4 measurement ID; leave empty to disable. GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ +# Yandex.Metrika counter ID; leave empty to disable. +YANDEX_METRIKA_ID=113657403 # Telegram contact for every TG entry (footer, navigation, return-home, legal pages, customer service). CONTACT_TELEGRAM_URL=https://t.me/jbd125 APP_IOS_STORE_URL= diff --git a/config/test.env b/config/test.env index 4d88cbc..b258f9b 100644 --- a/config/test.env +++ b/config/test.env @@ -15,6 +15,8 @@ SEO_BAIDU_SITE_VERIFICATION= SEO_BAIDU_HTML_FILE= # Google Analytics 4 measurement ID; leave empty to disable. GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ +# Yandex.Metrika counter ID; leave empty to disable. +YANDEX_METRIKA_ID=113657403 # Telegram contact for every TG entry (footer, navigation, return-home, legal pages, customer service). CONTACT_TELEGRAM_URL=https://t.me/jbd125 APP_IOS_STORE_URL= diff --git a/src/app/layout.tsx b/src/app/layout.tsx index e35c71c..404edbe 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -39,6 +39,7 @@ import "@/styles/overrides/pwa-safe-area.css"; import type { ReactNode } from "react"; import { PwaProvider } from "@/components/pwa/PwaProvider"; import { GoogleAnalytics } from "@/components/analytics/GoogleAnalytics"; +import { YandexMetrika } from "@/components/analytics/YandexMetrika"; import { serverConfig } from "@/server/config"; import { pwaViewport } from "@/lib/pwa/config"; import { getRequestPage } from "@/server/react/request-page"; @@ -83,7 +84,7 @@ export default async function RootLayout({ /> )} - {children} + {children} ); } diff --git a/src/components/analytics/YandexMetrika.tsx b/src/components/analytics/YandexMetrika.tsx new file mode 100644 index 0000000..8f52254 --- /dev/null +++ b/src/components/analytics/YandexMetrika.tsx @@ -0,0 +1,23 @@ +import Script from "next/script"; + +/** Yandex.Metrika counter; loads after hydration, with the official noscript pixel. */ +export function YandexMetrika({ id }: { id: string }) { + if (!id) return null; + const src = `https://mc.yandex.ru/metrika/tag.js?id=${id}`; + return ( + <> + + + + ); +} diff --git a/src/server/config.ts b/src/server/config.ts index 1942f10..591ebe0 100644 --- a/src/server/config.ts +++ b/src/server/config.ts @@ -27,6 +27,8 @@ export function serverConfig() { navigationOnly: process.env.NAVIGATION_ONLY === 'true', /** Google Analytics 4 measurement ID; empty or invalid disables the Google tag. */ googleAnalyticsID: /^G-[A-Z0-9]{4,20}$/.test((process.env.GOOGLE_ANALYTICS_ID || '').trim()) ? (process.env.GOOGLE_ANALYTICS_ID || '').trim() : '', + /** Yandex.Metrika counter ID; empty or invalid disables the counter. */ + yandexMetrikaID: /^\d{4,12}$/.test((process.env.YANDEX_METRIKA_ID || '').trim()) ? (process.env.YANDEX_METRIKA_ID || '').trim() : '', /** Every Telegram contact entry points here, overriding the upstream tgGroup/telegram/telegramAdd. */ contactTelegramURL: installationURL(process.env.CONTACT_TELEGRAM_URL) || 'https://t.me/jbd125', installation: {