Web Analytics Path Cleaning

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

POST
GET
POST

Create web analytics path cleaning suggestions

Merges the suggestion's rules into the team's path_cleaning_filters (never overwrites existing rules) and resolves the underlying health issue. Requires project admin, matching the team API's gate on path_cleaning_filters.

Required API key scopes

web_analytics:write

Path parameters

  • id
    string

Response


Example request

POST /api/projects/:project_id/web_analytics_path_cleaning_suggestions/:id/apply
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/web_analytics_path_cleaning_suggestions/:id/apply/

Example response

Status 200
RESPONSE
{
"applied": 0
}

Retrieve web analytics path cleaning suggestions

Applies the suggestion's rules (in order) to a fresh sample of the team's top paths and returns before/after pairs for the paths that would change. Computed on demand; path samples are never stored. Nothing is modified.

Required API key scopes

web_analytics:read

Path parameters

  • id
    string

Response


Example request

GET /api/projects/:project_id/web_analytics_path_cleaning_suggestions/:id/preview
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/web_analytics_path_cleaning_suggestions/:id/preview/

Example response

Status 200
RESPONSE
{
"examples": [
{
"before": "string",
"after": "string",
"views": 0
}
],
"changed_path_count": 0,
"sampled_path_count": 0
}

Create web analytics path cleaning suggestions

Samples the team's recent paths, asks the LLM for cleaning rules, validates them against the real paths, and stores the result as a path_cleaning_suggestions health issue (replacing any previous active one). Runs even if the team already has rules. Returns the suggestion (or a skip status when there aren't enough paths to suggest from).

Required API key scopes

web_analytics:write

Response


Example request

POST /api/projects/:project_id/web_analytics_path_cleaning_suggestions/generate
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/web_analytics_path_cleaning_suggestions/generate/

Example response

Status 200
RESPONSE
{
"status": "string",
"suggestion": {
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"created_at": "2019-08-24T14:15:22Z",
"rules": [
{
"regex": "string",
"alias": "string",
"order": 0,
"match_count": 0
}
],
"model": "string",
"sampled_path_count": 0,
"distinct_path_count": 0
}
}