Skillpedia
التحليل وجداول البيانات41k · #6976

managing-path-cleaning-rules

ما الذي تفعله

تُظهر هذه المهارة للوكيل كيفية إعداد قواعد تنظّم عناوين صفحات الويب في PostHog. وهي موجهة إلى أصحاب المواقع التي تتوزع تقاريرهم على آلاف الروابط المتشابهة تقريباً.

متى تستخدمها

  • ✓عندما تُظهر تحليلات الويب لديك نسخاً كثيرة من الصفحة نفسها باختلاف المعرّفات.
  • ✓عندما تريد تجميع عناوين متشابهة، مثل صفحات المستخدمين، في صف واحد.
  • ✓عندما تريد اختبار القواعد التي تنظّف عناوين الصفحات أو تعديلها.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/PostHog/posthog/blob/master/products/web_analytics/skills/managing-path-cleaning-rules/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“تُظهر تقاريري صفاً منفصلاً لكل صفحة ملف مستخدم. هل يمكنك إعداد قواعد تجعلها كلها تُجمع في صف واحد؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

ينظر الوكيل إلى عناوين صفحات حقيقية ليجد الأجزاء المتغيرة، مثل الأرقام أو المعرّفات. ثم يكتب نمطاً واستبدالاً مقروءاً، ويختبره على البيانات، ويرتب القواعد بحيث تُطبّق القواعد المحددة أولاً.

المحتوى التقني (ملف 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
الترخيص
—
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة