fix(ratewise): staging GA4 hostname gate 與離線安裝導引破圖降級(#606 #607) - #629
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96946dec84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da6c9ba7c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- 新增 resolveGaMeasurementId:以 APP_INFO.siteUrl(SSOT)導出正式站 hostname - 非正式 host(staging/preview/localhost)回空字串,initGA 提早返回不注入 gtag - main.tsx 以 window.location.hostname 過 gate 後才取用 VITE_GA_ID - 補 production/staging/localhost/子網域單元測試,附 changeset 並更新 002 紀錄 測試:pnpm --filter @app/ratewise exec vitest run 全綠(178 檔 4018 tests);本地 preview 網路面板實證零 gtag 請求 Co-authored-by: Cursor <cursoragent@cursor.com>
- pwa-install/** 未納入 precache(三格式共 708KB 超過體積門檻),維持 globIgnores 排除 - img onError 時隱藏整個 picture 圖區,文字步驟導引保留,對齊離線誠實原則 - 補離線載圖失敗降級單元測試,changeset 拆分為兩筆對應兩 issue,更新 002 紀錄 - 截圖證據:screenshots/qa-607-offline-install-guide.png 測試:pnpm --filter @app/ratewise exec vitest run 全綠(178 檔 4018 tests) Co-authored-by: Cursor <cursoragent@cursor.com>
- 匯出 analyticsGate 的 PRODUCTION_HOSTNAME 供 e2e 判斷(同一 SSOT) - 期望 config 次數依「內嵌 GA runtime 且執行 host 為正式站」決定 1 或 0 - 非正式站 host 斷言恆 0、不逾時等待,保留不重複初始化語意 - analyticsGate 測試補 www 前綴與 FQDN 尾點兩個繞過 case - changeset 註記 GA 驗證流程後移至正式站;002 記一筆 penalty 測試:analyticsGate+PwaInstallGuide vitest 16 tests 綠;ga-defer-lcp offline-pwa-chromium 6 passed Co-authored-by: Cursor <cursoragent@cursor.com>
da6c9ba to
d19a98a
Compare
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d19a98a8c4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Closes #606
Closes #607
Summary
一次修復兩個 staging/PWA 巡檢 issue,兩者皆為最小 diff、附單元測試與瀏覽器實證。
#606 — GA4 staging 無 gate 污染正式資料
apps/ratewise/src/utils/analyticsGate.ts的resolveGaMeasurementId(hostname, measurementId):正式站 hostname 由APP_INFO.siteUrl(SSOT,app.haotool.org)以new URL().hostname導出並匯出為PRODUCTION_HOSTNAME,禁止另行硬編網域。main.tsx以window.location.hostname過 gate 後才取用VITE_GA_ID;非正式 host(staging / preview / localhost / 子網域 / www 前綴 / FQDN 尾點)一律回空字串,initGA提早返回,gtag 腳本完全不注入。VITE_SITE_URLenv 判斷:staging 部署(fix(ratewise): manifest 網域改由 VITE_SITE_URL 環境驅動 #613 模式)會把VITE_SITE_URL設為 staging 網域,若以「hostname === VITE_SITE_URL host」判斷,staging 反而會放行 GA。runtime hostname 對比正式站 SSOT 才能在「同一份 production build 部署到多環境」時正確擋下。ga-defer-lcp.spec.ts已改 gate-aware:期望 config 次數依「HAS_BUILT_GA_RUNTIME且執行 host ===PRODUCTION_HOSTNAME(import 自analyticsGate,同一 SSOT)」決定 1 或 0;0 次時斷言恆 0、不逾時等待,保留「不重複初始化」語意。GA4 skill 文件(~/.agents/skills/google-analytics-ga4/)與 hostname gate 的 drift 由 PM 另案處理。#607 — 離線時 PWA 安裝導引 hero 圖破圖
pwa-install/**hero 圖三格式(avif/webp/png × ios/android)共 708KB,超過 200KB 門檻,納入 precache 會讓所有用戶(含永不觸發安裝導引者)付出快取成本,故維持globIgnores排除,precache 體積零變化。PwaInstallGuide的<img>掛onError:載圖失敗(離線未快取、CDN 異常)時隱藏整個<picture>圖區,文字步驟導引完整保留,對齊離線誠實原則。驗收對照
gtag|googletagmanager|google-analytics|collect為空;typeof window.gtag === 'undefined'、dataLayer長度 0、無 gtag script 節點analyticsGate.test.ts8 案例:production host 放行、staging / localhost / 127.0.0.1 / 子網域 /www.app.haotool.org/app.haotool.org.(FQDN 尾點)回空、空 ID 維持空ga-defer-lcp.spec.ts --project=offline-pwa-chromium本地 6 passed(gate-aware:localhost 斷言 config 恆 0)pwa-install/**請求,圖區自動隱藏、文字導引完整(screenshots/qa-607-offline-install-guide.png,QA 暫存不入 repo);單元測試覆蓋 onError 降級閘門
pnpm --filter @app/ratewise exec vitest run:178 檔 4018+ tests 全綠(rootpnpm vitest run無 root config,等效以 workspace 配置執行)pnpm --filter @app/ratewise exec playwright test tests/e2e/ga-defer-lcp.spec.ts --project=offline-pwa-chromium:6 passed(審查 Blocking 修訂後綠燈)pnpm typecheck:全 workspace 通過pnpm build:ratewise:成功(pre-push 亦重跑 typecheck + test + build 全綠).changeset/staging-ga4-gate-offline-install-img.md、.changeset/offline-install-guide-img-degrade.md)