Web analytics

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

Get a breakdown by a property (e.g. browser, device type, country, etc.). This endpoint is in beta, please contact support to enable it for your team.

Retrieve web analytics breakdown

Required API key scopes

query:read

Path parameters

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.

Query parameters

  • apply_path_cleaning
    boolean
    Default: true

    Apply URL path cleaning

  • breakdown_by
    string
    One of: "DeviceType""Browser""OS""Viewport""InitialReferringDomain""InitialUTMSource""InitialUTMMedium""InitialUTMCampaign""InitialUTMTerm""InitialUTMContent""Country""Region""City""InitialPage""Page""ExitPage""InitialChannelType"

    Property to break down by

    • DeviceType - DeviceType
    • Browser - Browser
    • OS - OS
    • Viewport - Viewport
    • InitialReferringDomain - InitialReferringDomain
    • InitialUTMSource - InitialUTMSource
    • InitialUTMMedium - InitialUTMMedium
    • InitialUTMCampaign - InitialUTMCampaign
    • InitialUTMTerm - InitialUTMTerm
    • InitialUTMContent - InitialUTMContent
    • Country - Country
    • Region - Region
    • City - City
    • InitialPage - InitialPage
    • Page - Page
    • ExitPage - ExitPage
    • InitialChannelType - InitialChannelType
  • date_from
    string

    Start date for the query (format: YYYY-MM-DD)

  • date_to
    string

    End date for the query (format: YYYY-MM-DD)

  • filter_test_accounts
    boolean
    Default: true

    Filter out test accounts

  • host
    string

    Host to filter by (e.g. example.com)

  • limit
    integer
    Default: 100

    Number of results to return

  • offset
    integer
    Default: 0

    Number of results to skip

Response


Request

GET /api/projects/:project_id/web_analytics/breakdown
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/breakdown/

Response

Status 200 Get a breakdown of web analytics data by supported properties.
RESPONSE
{
"count": 25,
"next": "https://us.posthog.com/api/web_analytics/breakdown?offset=2&limit=2",
"previous": null,
"results": [
{
"breakdown_value": "/home",
"visitors": 8500,
"views": 12000,
"sessions": 9200
},
{
"breakdown_value": "/about",
"visitors": 2100,
"views": 2800,
"sessions": 2300
}
]
}

Retrieve web analytics overview

Get an overview of web analytics data including visitors, views, sessions, bounce rate, and session duration. This endpoint is in beta, please contact support to enable it for your team.

Required API key scopes

query:read

Path parameters

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.

Query parameters

  • date_from
    string

    Start date for the query (format: YYYY-MM-DD)

  • date_to
    string

    End date for the query (format: YYYY-MM-DD)

  • filter_test_accounts
    boolean
    Default: true

    Filter out test accounts

  • host
    string

    Host to filter by (e.g. example.com)

Response


Request

GET /api/projects/:project_id/web_analytics/overview
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/overview/

Response

Status 200 Get simple overview metrics: visitors, views, sessions, bounce rate, session duration
RESPONSE
{
"visitors": 12500,
"views": 45000,
"sessions": 18200,
"bounce_rate": 0.32,
"session_duration": 185.5
}

Community questions

Was this page useful?