managing-path-cleaning-rules
Fungsinya
Skill ini menunjukkan cara agent menyiapkan aturan untuk merapikan alamat halaman web di PostHog. Skill ini untuk pemilik situs yang laporannya terpecah di ribuan tautan halaman yang hampir sama.
Kapan dipakai
- βSaat analitik web Anda menampilkan banyak versi dari halaman yang sama dengan ID berbeda.
- βSaat Anda ingin mengelompokkan alamat yang mirip, seperti halaman pengguna, menjadi satu baris.
- βSaat Anda ingin menguji atau mengubah aturan yang merapikan alamat halaman.
Link skill
https://github.com/PostHog/posthog/blob/master/products/web_analytics/skills/managing-path-cleaning-rules/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βLaporan saya menampilkan baris terpisah untuk setiap halaman profil pengguna. Bisakah Anda membuat aturan agar semuanya dikelompokkan menjadi satu baris?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent melihat alamat halaman yang sebenarnya untuk menemukan bagian yang berubah, seperti angka atau ID. Agent menulis pola dan penggantinya yang mudah dibaca, mengujinya pada data, lalu mengurutkan aturan agar yang spesifik diterapkan lebih dulu.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Apakah alamat yang sudah dirapikan muncul di laporan saya?
Ya. Versi yang sudah dirapikan muncul di laporan dan kueri yang memakai aturan tersebut.
Seperti apa placeholder seperti id?
Itu adalah label yang mudah dibaca, seperti id atau slug, yang ditampilkan dalam tanda kurung sudut pada alamat yang sudah dirapikan.
Mengapa urutan aturan penting?
Aturan yang terlalu luas dapat menelan aturan yang lebih spesifik, jadi pola yang spesifik sebaiknya ditaruh di depan.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 41k
- Peringkat
- #6976
- Lisensi
- β
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
depot-ci
41kMembantu agent Anda menyiapkan dan menjalankan alur kerja Depot CI, alternatif GitHub Actions, termasuk memigrasikan alur kerja yang ada dan membaca log eksekusi.
depot-container-builds
41kMembantu agent Anda membangun image Docker di builder jarak jauh Depot, termasuk image multi-platform, pengiriman ke registry, dan perbaikan kegagalan build.
depot-github-runners
41kMembantu agent Anda memindahkan job GitHub Actions ke runner yang dikelola Depot, memilih ukuran dan label runner, serta memecahkan masalah pengaturan runner.
editing-agents-md
41kMembantu agent Anda memutuskan apakah sebuah aturan layak masuk ke berkas AGENTS.md atau CLAUDE.md, dan menulisnya agar tetap dipatuhi tanpa membuat berkas membengkak.
Skill serupa
gitcrawl
394kMemungkinkan agent Anda mencari arsip issue dan pull request GitHub yang tersimpan, mengelompokkan yang duplikat, dan memeriksa status terkininya di GitHub.
slacrawl
394kMemungkinkan agent Anda mencari dan menghitung pesan di arsip Slack lokal, memeriksa seberapa baru arsip itu, dan menyegarkannya bila diperlukan.
goplaces
394kMembantu agent Anda mencari tempat, mendapatkan detail dan ulasannya, serta menentukan nama tempat memakai Google Places, dengan keluaran JSON untuk skrip.