跳到正文
Skillpedia
分析与电子表格41k · #6976

managing-path-cleaning-rules

它能做什么

这项技能教智能体如何在 PostHog 中设置整理网页地址的规则。适合报告中因为数千个几乎相同的页面链接而被拆散的网站所有者。

适用场景

  • ✓当你的网站分析中出现同一页面的许多不同 ID 版本的时候。
  • ✓当你想把相似的地址(例如用户页面)合并成一行的时候。
  • ✓当你想测试或修改清理页面地址的规则的时候。

技能链接

https://github.com/PostHog/posthog/blob/master/products/web_analytics/skills/managing-path-cleaning-rules/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/PostHog/posthog/blob/master/products/web_analytics/skills/managing-path-cleaning-rules/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的报告中,每个用户资料页都单独占一行。你能设置规则,让它们全部合并成一行吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会查看真实的页面地址,找出会变化的部分,例如数字或 ID。然后它会编写一个匹配模式和一个易读的替换结果,用数据进行测试,并调整规则顺序,让具体的规则先生效。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Managing path cleaning rules

Path cleaning rules normalize $pathname and $entry_pathname so that pages sharing the same template (/users/123/profile, /users/456/profile, …) collapse into one row (/users/<id>/profile) in Web analytics tiles, Paths insights, and any HogQL query that calls apply_path_cleaning. They are the right answer when a breakdown is fragmented across thousands of near-identical URLs.

This skill teaches you how to:

  • recognize when path cleaning is the right tool
  • inspect real paths to find what needs cleaning
  • write regex + alias rules in re2 syntax with the project's placeholder convention
  • test rules before saving them
  • order rules so specific patterns aren't swallowed by generic ones
  • apply the rules via MCP

Data model

Team.path_cleaning_filters is a JSON list of PathCleaningFilter objects:

{
  "regex": "/users/\\d+/profile",
  "alias": "/users/<id>/profile",
  "order": 0
}
  • regex — a re2 pattern. No need to escape /. Anchor with ^ / $ when you mean it.
  • alias — the replacement. Default to angle-bracket placeholders (<id>, <slug>, <uuid>, <date>) so the cleaned path stays human-readable. Backreferences to the regex's capture groups also work, but they cost more to evaluate — see the backreference pitfall below before reaching for one.
  • order — integer. Rules apply sequentially in order ascending, each rule's output feeds the next.

Application is replaceRegexpAll(pathname, regex, alias) per rule, chained.

Workflow

1. Confirm path cleaning is the right move

Ask yourself: is the user complaining about cardinality (too many distinct paths in a chart), or do they want a per-URL drill-down? Path cleaning is for the former. If they want per-URL data, suggest a property filter on $pathname instead.

2. Inspect the real paths

Don't guess at patterns — query them. With the execute-sql MCP tool:

SELECT properties.$pathname AS path, count() AS views
FROM events
WHERE event = '$pageview'
  AND timestamp > now() - INTERVAL 7 DAY
GROUP BY path
ORDER BY views DESC
LIMIT 200

Scan the result for:

  • numeric IDs: /users/123, /orders/4242
  • UUIDs: /sessions/8f3c1a3b-…
  • slugs: /posts/why-i-love-posthog
  • dates: /archive/2024-09-12
  • locales: /en-US/, /fr-FR/
  • pagination: ?page=3, /page/3/

3. Draft regex + alias

Pattern Example match regex alias
Numeric segment /users/123/profile /users/\d+/profile /users/<id>/profile
UUID v4 /sessions/8f3c1a3b-… /sessions/[0-9a-f-]{36} /sessions/<uuid>
Slug /posts/why-posthog /posts/[a-z0-9-]+$ /posts/<slug>
ISO date /archive/2024-09-12 /archive/\d{4}-\d{2}-\d{2} /archive/<date>
Locale prefix /en-US/about ^/[a-z]{2}-[A-Z]{2}/ /<locale>/
Trailing query/page /blog?page=3 \?page=\d+$ (empty alias drops it)

Anchoring rules of thumb:

  • start the regex with ^ only when the segment must be at the beginning of the path
  • end with $ to keep a generic rule (e.g. \d+$) from matching mid-path segments

4. Test before saving

Three options, pick one:

  • Settings page tester: /settings/project#path_cleaning has a built-in "test path" input that replays the full ordered chain.

  • Project HogQL (via execute-sql):

    SELECT replaceRegexpAll('/users/42/profile', '/users/\d+/profile', '/users/<id>/profile')
    

    Chain replaceRegexpAll calls in the same order the rules will run if you want to verify multi-rule interaction.

  • Built-in AI helper: there is already an AiRegexHelper modal accessible from the rule editor (Help me with Regex button) that turns natural language into a regex. Suggest it to the user when they say "I don't know regex" — but always validate the output against real paths via the tester.

5. Order rules from most-specific to most-general

Sequential application means a generic rule placed first will swallow everything that should have hit a specific rule.

order=0  /users/me/profile        →  /users/me/pro
常见问题

清理后的地址会出现在我的报告中吗?

会。使用这些规则的报告和查询中会显示清理后的版本。

像 id 这样的占位符是什么样的?

它们是易读的标签,例如 id 或 slug,在清理后的地址中用尖括号括起来显示。

规则的顺序为什么重要?

宽泛的规则可能会吞掉具体的规则,所以具体的匹配模式应该放在前面。

详情

作者的原始描述

Inspects URL paths and proposes, tests, orders, and applies project-level path cleaning rules so dynamic segments (numeric IDs, UUIDs, slugs, dates) collapse into readable aliases. Use when the user says "clean the paths", "normalize URLs", "group similar pages", "too many distinct paths", "/users/123 and /users/456 are the same page", "set up path cleaning", or asks why a Web analytics or Paths breakdown is fragmented across thousands of nearly-identical URLs. Covers regex syntax (re2), alias placeholder convention, rule ordering, the test workflow, and applying rules via the path-cleaning-ru

repo: PostHog/posthog

热度

GitHub 星标
41k
排名
#6976
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能