Skip to content

fix(ratewise): staging GA4 hostname gate 與離線安裝導引破圖降級(#606 #607) - #629

Merged
s123104 merged 3 commits into
experiment/ratewise-product-2026h2from
fix/staging-ga4-offline-img
Jul 6, 2026
Merged

fix(ratewise): staging GA4 hostname gate 與離線安裝導引破圖降級(#606 #607)#629
s123104 merged 3 commits into
experiment/ratewise-product-2026h2from
fix/staging-ga4-offline-img

Conversation

@s123104

@s123104 s123104 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closes #606
Closes #607

Summary

一次修復兩個 staging/PWA 巡檢 issue,兩者皆為最小 diff、附單元測試與瀏覽器實證。

#606 — GA4 staging 無 gate 污染正式資料

  • 新增 apps/ratewise/src/utils/analyticsGate.tsresolveGaMeasurementId(hostname, measurementId):正式站 hostname 由 APP_INFO.siteUrl(SSOT,app.haotool.org)以 new URL().hostname 導出並匯出為 PRODUCTION_HOSTNAME,禁止另行硬編網域。
  • main.tsxwindow.location.hostname 過 gate 後才取用 VITE_GA_ID;非正式 host(staging / preview / localhost / 子網域 / www 前綴 / FQDN 尾點)一律回空字串,initGA 提早返回,gtag 腳本完全不注入。
  • 為何選 hostname gate 而非 VITE_SITE_URL env 判斷: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 注入的實證驗證自此後移至正式站——本地 preview / staging 恆零注入(gate 語意),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 圖破圖

  • 取捨(二擇一選 b:離線優雅降級)pwa-install/** hero 圖三格式(avif/webp/png × ios/android)共 708KB,超過 200KB 門檻,納入 precache 會讓所有用戶(含永不觸發安裝導引者)付出快取成本,故維持 globIgnores 排除,precache 體積零變化。
  • PwaInstallGuide<img>onError:載圖失敗(離線未快取、CDN 異常)時隱藏整個 <picture> 圖區,文字步驟導引完整保留,對齊離線誠實原則。

驗收對照

Issue 驗收標準 證據
#606 非 production host 零 gtag 請求(網路面板) 本地 preview(localhost:4606)載入後等待 12s(涵蓋 6s init delay + idle window),網路面板過濾 gtag|googletagmanager|google-analytics|collect 為空;typeof window.gtag === 'undefined'dataLayer 長度 0、無 gtag script 節點
#606 production 判斷路徑有單元測試 analyticsGate.test.ts 8 案例:production host 放行、staging / localhost / 127.0.0.1 / 子網域 / www.app.haotool.org / app.haotool.org.(FQDN 尾點)回空、空 ID 維持空
#606 e2e 與 gate 語意一致(審查修訂) ga-defer-lcp.spec.ts --project=offline-pwa-chromium 本地 6 passed(gate-aware:localhost 斷言 config 恆 0)
#607 離線開安裝導引無破圖(截圖) Playwright iPhone 模擬阻斷 pwa-install/** 請求,圖區自動隱藏、文字導引完整(screenshots/qa-607-offline-install-guide.png,QA 暫存不入 repo);單元測試覆蓋 onError 降級
#607 precache 體積變化揭露 零變化(維持 globIgnores 排除,理由見上)

閘門

  • pnpm --filter @app/ratewise exec vitest run:178 檔 4018+ tests 全綠(root pnpm vitest run 無 root config,等效以 workspace 配置執行)
  • pnpm --filter @app/ratewise exec playwright test tests/e2e/ga-defer-lcp.spec.ts --project=offline-pwa-chromium6 passed(審查 Blocking 修訂後綠燈)
  • pnpm typecheck:全 workspace 通過
  • pnpm build:ratewise:成功(pre-push 亦重跑 typecheck + test + build 全綠)
  • changeset:兩筆 patch(.changeset/staging-ga4-gate-offline-install-img.md.changeset/offline-install-guide-img-degrade.md

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread docs/dev/002_development_reward_penalty_log.md Outdated
Comment thread apps/ratewise/src/main.tsx
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread docs/dev/002_development_reward_penalty_log.md Outdated
haotool and others added 3 commits July 6, 2026 10:30
- 新增 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>
@s123104
s123104 force-pushed the fix/staging-ga4-offline-img branch from da6c9ba to d19a98a Compare July 6, 2026 02:35
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/ratewise/tests/e2e/ga-defer-lcp.spec.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant