From 04208361099ed7a1d9b52519b889b0b8205f91d0 Mon Sep 17 00:00:00 2001 From: moux1024 <403053463@qq.com> Date: Sun, 28 Sep 2025 18:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 3 + .env.production | 3 + Dockerfile | 3 + app/layout.tsx | 35 ++-- app/pricing/page.tsx | 34 +++- app/types/global.d.ts | 4 + components/auth/auth-guard.tsx | 46 ++++- hooks/useAnalytics.ts | 194 +++++++++++++++++++ hooks/useAppStartupAnalytics.ts | 67 +++++++ lib/auth.ts | 20 ++ utils/analytics.ts | 334 ++++++++++++++++++++++++++++++++ 11 files changed, 728 insertions(+), 15 deletions(-) create mode 100644 hooks/useAnalytics.ts create mode 100644 hooks/useAppStartupAnalytics.ts create mode 100644 utils/analytics.ts diff --git a/.env.development b/.env.development index bf2ed3a..3f8d61f 100644 --- a/.env.development +++ b/.env.development @@ -3,6 +3,9 @@ NEXT_PUBLIC_JAVA_URL = https://auth.test.movieflow.ai NEXT_PUBLIC_BASE_URL = https://77.smartvideo.py.qikongjian.com NEXT_PUBLIC_CUT_URL = https://77.smartcut.py.qikongjian.com NEXT_PUBLIC_CUT_URL_TO = https://smartcut.huiying.video +# google analysis +NEXT_PUBLIC_GA_MEASUREMENT_ID = G-BHBXC1B1JL +NEXT_PUBLIC_GA_ENABLED = true # 失败率 NEXT_PUBLIC_ERROR_CONFIG = 0.5 # Google OAuth配置 diff --git a/.env.production b/.env.production index 8c74643..1720734 100644 --- a/.env.production +++ b/.env.production @@ -19,3 +19,6 @@ NEXT_PUBLIC_ERROR_CONFIG = 0.2 # Google OAuth配置 NEXT_PUBLIC_GOOGLE_CLIENT_ID=847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com +# google analysis +NEXT_PUBLIC_GA_MEASUREMENT_ID = G-E6VBGZ4ER5 +NEXT_PUBLIC_GA_ENABLED = true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f561afc..434b572 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,9 @@ COPY package.json package-lock.json* ./ COPY public ./public ENV NODE_ENV=production +# Google Analytics 环境变量 +ENV NEXT_PUBLIC_GA_MEASUREMENT_ID=G-4BDXV6TWF4 +ENV NEXT_PUBLIC_GA_ENABLED=true EXPOSE 3000 diff --git a/app/layout.tsx b/app/layout.tsx index 118ff61..da2fb2f 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -4,6 +4,7 @@ import { createContext, useContext, useEffect, useState } from 'react'; import { Providers } from '@/components/providers'; import { ConfigProvider, theme } from 'antd'; import CallbackModal from '@/components/common/CallbackModal'; +import { useAppStartupAnalytics } from '@/hooks/useAppStartupAnalytics'; // 创建上下文来传递弹窗控制方法 const CallbackModalContext = createContext<{ @@ -26,6 +27,10 @@ export default function RootLayout({ }) { const [showCallbackModal, setShowCallbackModal] = useState(false) const [paymentType, setPaymentType] = useState<'subscription' | 'token'>('subscription') + + // 应用启动时设置用户GA属性 + useAppStartupAnalytics(); + const openCallback = async function (ev: MessageEvent) { if (ev.data.type === 'waiting-payment') { setPaymentType(ev.data.paymentType || 'subscription') @@ -48,17 +53,25 @@ export default function RootLayout({ - - +