google统计添加

This commit is contained in:
谢宇宁
2026-10-16 19:02:39 +07:00
parent 4afd5f9143
commit fe52aefe4a
7 changed files with 30 additions and 1 deletions
+2
View File
@@ -263,6 +263,8 @@ APP_DEEP_LINK_URL=
平台地址未配置时,按钮显示“前往下载页”,沿用上游 `AppAddr` 或 `/app/download/` 跳转;未配置 App 深链时隐藏打开 App 入口。链接保留原始跳转地址,不生成设计示例中的安装包、描述文件或 App Store 地址。
谷歌统计(GA4)由 `GOOGLE_ANALYTICS_ID` 配置,三套环境默认 `G-269F3ZFQFQ`,在根布局通过 `next/script` 于页面可交互后加载;留空即关闭。
所有 Telegram 联系入口(页尾、官方导航、回家的路、播放页链接、2257/DMCA、意见反馈,以及 Telegram 形式的「联系我们」客服链接)统一使用 `CONTACT_TELEGRAM_URL`,三套环境默认 `https://t.me/jbd125`,覆盖上游 `tgGroup`、`telegram`、`telegramAdd`。值无效时回退为默认账号。
## 接口和媒体
+2
View File
@@ -17,6 +17,8 @@ M3U8_KEY_FILE=./config/secrets/m3u8.key
SEO_INDEXNOW_KEY=d8e5b742d13809c10865fc3b29de24ee
SEO_BAIDU_SITE_VERIFICATION=
SEO_BAIDU_HTML_FILE=
# Google Analytics 4 measurement ID; leave empty to disable.
GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ
# 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=
+2
View File
@@ -13,6 +13,8 @@ M3U8_KEY_FILE=./config/secrets/m3u8.key
SEO_INDEXNOW_KEY=d8e5b742d13809c10865fc3b29de24ee
SEO_BAIDU_SITE_VERIFICATION=
SEO_BAIDU_HTML_FILE=
# Google Analytics 4 measurement ID; leave empty to disable.
GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ
# 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=
+2
View File
@@ -13,6 +13,8 @@ M3U8_KEY_FILE=./config/secrets/m3u8.key
SEO_INDEXNOW_KEY=d8e5b742d13809c10865fc3b29de24ee
SEO_BAIDU_SITE_VERIFICATION=
SEO_BAIDU_HTML_FILE=
# Google Analytics 4 measurement ID; leave empty to disable.
GOOGLE_ANALYTICS_ID=G-269F3ZFQFQ
# 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=
+3 -1
View File
@@ -38,6 +38,8 @@ import "@/styles/pages/playback.css";
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 { serverConfig } from "@/server/config";
import { pwaViewport } from "@/lib/pwa/config";
import { getRequestPage } from "@/server/react/request-page";
import { toNextMetadata } from "@/server/seo";
@@ -81,7 +83,7 @@ export default async function RootLayout({
/>
)}
</head>
<body className={presentation.bodyClass}><PwaProvider />{children}</body>
<body className={presentation.bodyClass}><PwaProvider />{children}<GoogleAnalytics id={serverConfig().googleAnalyticsID} /></body>
</html>
);
}
@@ -0,0 +1,17 @@
import Script from "next/script";
/** Google tag (gtag.js); loads after hydration so it never blocks rendering. */
export function GoogleAnalytics({ id }: { id: string }) {
if (!id) return null;
return (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${id}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config',${JSON.stringify(id)});`}
</Script>
</>
);
}
+2
View File
@@ -25,6 +25,8 @@ export function serverConfig() {
timeout: Math.max(100, Number(process.env.UPSTREAM_TIMEOUT_MS) || 20000),
m3u8KeyFile: process.env.M3U8_KEY_FILE || './config/secrets/m3u8.key',
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() : '',
/** Every Telegram contact entry points here, overriding the upstream tgGroup/telegram/telegramAdd. */
contactTelegramURL: installationURL(process.env.CONTACT_TELEGRAM_URL) || 'https://t.me/jbd125',
installation: {