managing-path-cleaning-rules
What it does
This skill shows an agent how to set up rules that tidy up web page addresses in PostHog. It is for site owners whose reports are split across thousands of almost identical page links.
When to use it
- βWhen your web analytics show many versions of the same page with different IDs.
- βWhen you want to group similar addresses, such as user pages, into one row.
- βWhen you want to test or change the rules that clean up page addresses.
Skill link
https://github.com/PostHog/posthog/blob/master/products/web_analytics/skills/managing-path-cleaning-rules/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βMy reports show a separate row for every user profile page. Can you set up rules so they all group into one row?β
5 new skills a week. 1 minute to read.
How it works
The agent looks at real page addresses to find the parts that change, such as numbers or IDs. It writes a pattern and a readable replacement, tests it on the data, and orders the rules so the specific ones apply first.
Technical content (original SKILL.md)
Original text by the author, straight from 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+aliasrules 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 inorderascending, 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_cleaninghas 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
replaceRegexpAllcalls in the same order the rules will run if you want to verify multi-rule interaction.Built-in AI helper: there is already an
AiRegexHelpermodal accessible from the rule editor (Help me with Regexbutton) 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
FAQ
Do cleaned addresses show up in my reports?
Yes. The cleaned version appears in the reports and queries that use the rules.
What do placeholders like id look like?
They are readable labels such as id or slug, shown in angle brackets in the cleaned address.
Why does the order of rules matter?
A broad rule can swallow a specific one, so the specific patterns should come first.
Details
Original description by the author
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
Popularity
- GitHub stars
- 41k
- Ranking position
- #6976
- License
- β
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
depot-ci
41kHelps your agent set up and run Depot CI workflows, a GitHub Actions alternative, including migrating existing workflows and reading run logs.
depot-container-builds
41kHelps your agent build Docker images on Depot's remote builders, including multi-platform images, pushing to registries, and fixing build failures.
depot-github-runners
41kHelps your agent move GitHub Actions jobs to Depot-managed runners, choosing runner sizes and labels, and troubleshooting runner setup issues.
editing-agents-md
41kHelps your agent decide whether a rule belongs in an AGENTS.md or CLAUDE.md file, and write it so it sticks without bloating the file.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.