Repository navigation
fix(analytics): correct pageviews, proxy PostHog and stop sending search text / 统计:修正 pageview、代理 PostHog 并不再发送搜索文本 - #1552
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Oct 28, 2026
Merged
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 02:06
8f5aa4e to
35b6d15
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 02:06
1125679 to
081236f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 05:54
35b6d15 to
ef3f544
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 05:54
23bbcfa to
cb98d5b
Compare
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 06:03
ef3f544 to
51da156
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 06:03
cb98d5b to
e1bff67
Compare
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 06:15
51da156 to
4e92f3d
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 06:15
e1bff67 to
c1076d7
Compare
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 06:19
4e92f3d to
1ce3c49
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 06:19
c1076d7 to
376c160
Compare
adibarra
force-pushed
the
fix/layout-shift-ux
branch
from
October 29, 2026 06:24
1ce3c49 to
a257455
Compare
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 06:24
376c160 to
0425bdd
Compare
…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,排队和实时两条路径均适用,并沿用去重规则避免重复计数。
adibarra
force-pushed
the
fix/analytics-pageviews
branch
from
October 29, 2026 06:32
0425bdd to
be33d38
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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):
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.
$pageviewfires only for a model the user picked:setSelectedModelmarks 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 }./ingestrewrites.skipTrailingSlashRedirectis set, and two redirect rules strip trailing slashes elsewhere; a test compiles them with@vercel/routing-utilsto catch a Vercel-only redirect loop. Dead-click capture is off.query_lengthonly, and replay network capture strips search params.outbound_link_clicked,not_found_page_shownandinference_chart_rendered(time since navigation) are added. Pageviews carryroute_templateandlocale. The unusedVisitTrackeris 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
anthropic/claude-opus-5-5(runtime-exposed identifier for the coordinating agent).PR checklist
inferencex-skillschanges (no filters or views change)/zhsiblingdocs/chinese-copy.md(Chinese maintainer review pending)中文
本 PR 为从 #1530 拆分的 stack 中的第 8 部分,请按顺序审核与合并。CI 只在以
master为目标的 PR 上运行,因此每一层都在本地验证;整体改动已在 #1530 上通过完整 CI。切换模型此前不会记录 pageview,而 overview 与 profit estimator 的筛选变化每次都会记录;PostHog 加载前排队的事件顺序与时间错误;PostHog 直接请求易被广告拦截的域名;还会发送原始搜索文本。
$pageview:setSelectedModel会标记用户选择,而裸路由补全、preset 处理、自动纠正与非模型筛选变化只改写路径、不记录 pageview;overview 控件变化不再记录 pageview。自动设置模型的代码须传入{ userSelection: false }。/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$pageviewfires only when the pathname changes from a user model pick (setSelectedModelwith defaultuserSelection: true). Bare-route canonicalization, presets, auto-corrections, profit-estimator filter path rewrites, and overview control updates no longer count as pageviews; overview usestrackVirtualPageview, 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$pageviewbefore othertrack()calls when the pathname moved. PostHog loads after idle (or immediately when the page hides with queued events).PostHog sends through first-party
/ingestrewrites (withskipTrailingSlashRedirectand trailing-slash redirects that exclude/ingest/). Session replay maskssearch/q/queryon captured network URLs; search-related events sendquery_length(and result counts where relevant) instead of raw queries. New instrumentation includesinference_chart_rendered(ms since navigation),outbound_link_clicked, andnot_found_page_shown, plusroute_template/localeon pageviews. LocalVisitTracker/ 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.