Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.5 KB
Raw Blame
"""Links to an inbox report that PostHog writes into other surfaces.

Each link carries a `link_source` query param. The inbox reads it, records it on
`Inbox report opened`, and removes it from the address bar. The inbox filters already use `source`. The values must match
`INBOX_REPORT_LINK_SOURCES` in `frontend/inbox/inboxAnalytics.ts`.

A link can also carry a `link_action` query param. The inbox reads it once and removes it too.
"""

from enum import StrEnum
from uuid import UUID

from posthog.utils import absolute_uri


class ReportLinkSource(StrEnum):
    FIRST_REPORT_EMAIL = "first_report_email"
    MCP = "mcp"
    SLACK = "slack"
    SLACK_SCOUT = "slack_scout"
    SCOUT = "scout"
    GITHUB_COMMENT = "github_comment"
    GITHUB_PR = "github_pr"
    TRACKER = "tracker"
    SUPPORT = "support"
    TASK = "task"
    TODAY = "today"


class ReportLinkAction(StrEnum):
    # Opens the implementation choices of the report's Implement button.
    IMPLEMENT = "implement"


def report_path(
    team_id: int, report_id: str | UUID, source: ReportLinkSource, action: ReportLinkAction | None = None
) -> str:
    path = f"/project/{team_id}/inbox/reports/{report_id}?link_source={source.value}"
    return f"{path}&link_action={action.value}" if action else path


def build_report_url(
    team_id: int, report_id: str | UUID, source: ReportLinkSource, action: ReportLinkAction | None = None
) -> str:
    return absolute_uri(report_path(team_id, report_id, source, action))