Skip to content

fix(analytics): correct pageviews, proxy PostHog and stop sending search text / 统计:修正 pageview、代理 PostHog 并不再发送搜索文本 - #1552

Merged
adibarra merged 4 commits into
masterfrom
fix/analytics-pageviews
Oct 29, 2026
Merged

adibarra merged 4 commits into
masterfrom
fix/analytics-pageviews

Conversation

@adibarra

@adibarra adibarra commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 8 of the stack split from #1530. Review and merge in order. CI only runs on PRs that target master, so each layer was verified locally; the combined change passed full CI on #1530.

Stack (merge in order):

  1. fix(next): stop the image optimizer hanging after a cancelled request / 修复请求取消后图片优化器卡住的问题 #1545 Next image optimizer patch
  2. feat(api): negotiate compression, add ETag/304 and stale-while-revalidate purges / API 协商压缩,支持 ETag/304 与 stale-while-revalidate 失效 #1546 API response caching
  3. fix(dashboard): load benchmarks in parallel with availability / dashboard 的 benchmarks 与 availability 并行加载 #1547 Dashboard data waterfall
  4. fix(seo): social images, canonicals, titles, intros, structured data and sitemap / SEO:社交图片、canonical、标题、简介、结构化数据与 sitemap #1548 SEO metadata
  5. feat(seo): render compare, run, rankings, overview and blog index with ISR / compare、run、rankings、overview 与博客索引改用 ISR #1549 ISR for programmatic pages
  6. fix(perf): cut client bundle, image and prefetch weight / 减少客户端代码、图片与预取体积 #1550 Client bundle, image and prefetch weight
  7. fix(ux): remove layout shifts and explain blocked legend toggles / 消除布局偏移并说明被禁用的图例切换 #1551 Layout shift and UX
  8. fix(analytics): correct pageviews, proxy PostHog and stop sending search text / 统计:修正 pageview、代理 PostHog 并不再发送搜索文本 #1552 Analytics pageviews and privacy ← this PR
  9. feat(analytics): cover untracked interactions, add event context and standardize keys / 统计:覆盖未追踪的交互,补充事件上下文并统一键名 #1555 Analytics coverage

Model switches recorded no pageview, while overview and profit-estimator filter changes recorded one each. Events queued before PostHog loaded arrived out of order with the wrong time. PostHog went straight to an ad-blockable host, and raw search text was sent.

  • Pageviews. A virtual $pageview fires only for a model the user picked: setSelectedModel marks user selections, and bare-route canonicalization, preset handling, auto-corrections and non-model filter changes rewrite the path without a pageview. Overview control changes no longer send pageviews. Code that sets the model automatically must pass { userSelection: false }.
  • Queued events. Events queued before PostHog loads keep their original order, URL and time, and the queue is capped. A hidden page starts PostHog at once.
  • PostHog proxy. PostHog posts through first-party /ingest rewrites. skipTrailingSlashRedirect is set, and two redirect rules strip trailing slashes elsewhere; a test compiles them with @vercel/routing-utils to catch a Vercel-only redirect loop. Dead-click capture is off.
  • Privacy. Search events send query_length only, and replay network capture strips search params.
  • New events and properties. outbound_link_clicked, not_found_page_shown and inference_chart_rendered (time since navigation) are added. Pageviews carry route_template and locale. The unused VisitTracker is removed.

PostHog does not initialize on previews (no project key), so these changes need a check after the production deploy.

Validation details

Targeted Cypress (Chrome): navigation 31/31, landing-dashboard-navigation 23/23, overview 35/35. This layer's tree is identical to #1530, whose full CI (unit, lint, all 16 Chrome and Firefox E2E shards, component tests) passed on the same content. Lint, format, typecheck and the full unit suite pass on this layer.

AI model disclosure
  • Model/version: anthropic/claude-opus-5-5 (runtime-exposed identifier for the coordinating agent).
  • Role: audited the site, planned and integrated the change set, split it into this stack, and wrote commit and PR text.
  • Delegated agents (scout, worker and critic subagents) implemented slices, built the stack and ran verification under the same harness. Their exact model identifier was not exposed to the coordinating agent, so it could not be verified.
PR checklist
  • I have completed the AI model disclosure and kept it current
  • Added, changed, or removed filters, views, or pages include the matching API and inferencex-skills changes (no filters or views change)
  • New or changed indexable pages ship their /zh sibling
  • Changed Chinese copy follows the PR review checklist in docs/chinese-copy.md (Chinese maintainer review pending)
中文

本 PR 为从 #1530 拆分的 stack 中的第 8 部分,请按顺序审核与合并。CI 只在以 master 为目标的 PR 上运行,因此每一层都在本地验证;整体改动已在 #1530 上通过完整 CI。

切换模型此前不会记录 pageview,而 overview 与 profit estimator 的筛选变化每次都会记录;PostHog 加载前排队的事件顺序与时间错误;PostHog 直接请求易被广告拦截的域名;还会发送原始搜索文本。

  • pageview。 仅在用户主动选择模型时记录虚拟 $pageview:setSelectedModel 会标记用户选择,而裸路由补全、preset 处理、自动纠正与非模型筛选变化只改写路径、不记录 pageview;overview 控件变化不再记录 pageview。自动设置模型的代码须传入 { userSelection: false }。
  • 排队事件。 PostHog 加载前排队的事件保留原始顺序、URL 与时间,队列设有上限;页面被隐藏时立即启动 PostHog。
  • PostHog 代理。 PostHog 经第一方 /ingest 转发,并设置 skipTrailingSlashRedirect,另用两条跳转规则去除其他路径的尾部斜杠;测试用 @vercel/routing-utils 编译这些规则,以发现仅在 Vercel 上出现的跳转死循环。关闭 dead click 采集。
  • 隐私。 搜索事件只发送 query_length,会话回放的网络记录会去除搜索参数。
  • 新事件与属性。 新增 outbound_link_clicked、not_found_page_shown 与 inference_chart_rendered(自导航开始的耗时);pageview 附带 route_template 与 locale;移除未使用的 VisitTracker。

preview 上未初始化 PostHog(无项目 key),这些改动需在生产部署后核对。

验证:定向 Cypress(Chrome):navigation 31/31、landing-dashboard-navigation 23/23、overview 35/35。本层代码与 #1530 完全一致,#1530 在相同内容上通过了完整 CI(单元测试、lint、全部 16 个 Chrome 与 Firefox E2E 分片及组件测试)。本层的 lint、格式、类型检查与完整单元测试均通过。

AI 模型使用说明:协调 agent 使用 anthropic/claude-opus-5-5(运行环境提供的标识),负责审计、规划与整合改动、拆分 stack 以及撰写提交与 PR 文本;委派的子 agent 在同一环境中实现各部分、构建 stack 并运行验证,其确切模型标识无法获取,因此无法确认。


Note

Medium Risk
Changes how pageviews and client routing events are measured and what PII-adjacent data leaves the browser; incorrect wiring would skew analytics but does not affect auth or data integrity.

Overview
Fixes pageview counting and PostHog delivery/privacy so analytics match real navigation and do not leak search text.

Pageviews are centralized in trackPageview / trackVirtualPageview: a virtual $pageview fires only when the pathname changes from a user model pick (setSelectedModel with default userSelection: true). Bare-route canonicalization, presets, auto-corrections, profit-estimator filter path rewrites, and overview control updates no longer count as pageviews; overview uses trackVirtualPageview, which dedupes on pathname only. Inference chart controls pass { pageview: value !== selectedModel } on pathname rewrites.

Pre-load queueing stamps URL/time on each event, replays in order with PostHog timestamp, caps at 200 events, and auto-inserts a $pageview before other track() calls when the pathname moved. PostHog loads after idle (or immediately when the page hides with queued events).

PostHog sends through first-party /ingest rewrites (with skipTrailingSlashRedirect and trailing-slash redirects that exclude /ingest/). Session replay masks search/q/query on captured network URLs; search-related events send query_length (and result counts where relevant) instead of raw queries. New instrumentation includes inference_chart_rendered (ms since navigation), outbound_link_clicked, and not_found_page_shown, plus route_template / locale on pageviews. Local VisitTracker / visit-count storage is removed.

Reviewed by Cursor Bugbot for commit be33d38. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
inferencemax-app Ready Ready Preview Oct 29, 2026 6:33am UTC

Request Review

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 23bbcfa. Configure here.

…og proxy

PostHog posts through first-party /ingest rewrites, with skipTrailingSlashRedirect
and two explicit trailing-slash redirects so its slash-terminated endpoints
are not redirected. A next.config test, using @vercel/routing-utils, checks
the rules as Vercel compiles them. Events queued before PostHog loads keep
their URL and time, are capped, and replay after the page's own pageview.
A hidden page starts loading PostHog at once. Model switches record a
virtual pageview only when they pass { pageview: true }, so filter and
overview control changes are no longer pageviews, and the custom
VisitTracker is removed. Pageviews carry route_template and locale.
Outbound links, 404 pages and first chart render timing are tracked,
dead-click capture is off, search events send query_length instead of the
typed text, and recordings mask search params in network timing.

中文:PostHog 改经第一方 /ingest rewrite 发送,配合 skipTrailingSlashRedirect
与两条显式去尾斜杠重定向,避免其以斜杠结尾的端点被重定向。新增基于
@vercel/routing-utils 的 next.config 测试,按 Vercel 的编译结果校验这些规则。
PostHog 加载前排队的事件保留触发时的 URL 与时间并设置上限,在页面自身的
pageview 之后回放。页面被隐藏时立即加载 PostHog。切换模型仅在传入
{ pageview: true } 时记录虚拟 pageview,筛选与 overview 控件变化不再计为
pageview,并移除自定义 VisitTracker。pageview 携带 route_template 与 locale。
新增外链点击、404 页面与首个图表渲染耗时的统计,关闭 dead click 采集,搜索事件
只上报 query_length 而非输入内容,录屏的网络耗时会屏蔽搜索参数。
…el switches

GlobalFilterProvider rewrote the model slug from an effect that also reruns on
sequence, precision, TCO and run state, and marked every rewrite as a pageview.
Settling those flags on a bare /calculator, /historical or /profit-estimator
therefore recorded a virtual $pageview for a canonicalization the user never
asked for. The provider now remembers the model the user picked through
setSelectedModel and flags the rewrite only when that pick is what changed the
model. URL presets and the profit estimator's model correction pass
{ userSelection: false }. The inference model picker no longer flags a re-pick
of the current model, which only canonicalizes a bare /inference path.

中文:GlobalFilterProvider 在一个同时依赖序列、精度、TCO 和运行状态的 effect 中改写模型路径,并把每次改写都标记为页面浏览。在 /calculator、/historical 或 /profit-estimator 这类无模型段的路径上,这些状态稳定下来时会记录一次用户并未触发的虚拟 $pageview。现在 provider 会记住用户通过 setSelectedModel 选择的模型,只有当这次选择真正改变了模型时才把改写记为页面浏览。URL 预设和利润估算器的模型自动纠正会传入 { userSelection: false }。推理页的模型选择器在重新选择当前模型时也不再记录页面浏览,因为那只是把 /inference 规范化为带模型段的路径。
A model switch keeps the previous scatter points mounted while controls re-render, so the observer reported stale points as the new navigation's first chart with a near-zero ms_since_navigation. After mount, only MutationRecords that add .dot-group nodes now trigger the report, once per navigation.

中文:切换模型时旧散点仍在 DOM 中,控件变动会让观察器把旧点误报为新导航的首个图表渲染,耗时接近零。现在挂载后只有新增 .dot-group 节点的变动才会触发上报,每次导航仅上报一次。
track() only inserted a leading $pageview when no pageview had been recorded, so after a client navigation page mount events such as submissions_page_viewed were captured before PageViewTracker sent the new $pageview. track() now records the current URL's pageview first whenever its pathname differs from the last recorded one, on both the queued and live PostHog paths. The usual dedupe keeps the tracker from counting it twice.

中文:track() 之前只在尚未记录任何 $pageview 时补发,因此客户端导航后,页面挂载事件(如 submissions_page_viewed)会先于 PageViewTracker 的新 $pageview 被捕获。现在只要当前 URL 的路径与上次记录的不同,track() 会先记录当前页面的 $pageview,排队和实时两条路径均适用,并沿用去重规则避免重复计数。
Base automatically changed from fix/layout-shift-ux to master October 29, 2026 06:32
@adibarra
adibarra force-pushed the fix/analytics-pageviews branch from 0425bdd to be33d38 Compare October 29, 2026 06:32
@adibarra
adibarra merged commit 45836a1 into master Oct 29, 2026
34 of 57 checks passed
@adibarra
adibarra deleted the fix/analytics-pageviews branch October 29, 2026 06:37

This branch was successfully deployed

1 active deployment
Preview — be33d388 Deployed Oct 29, 2026 by vercel[bot]
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