Web analytics

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

Endpoints

GET

Retrieve web analytics weekly

Summarizes a project's web analytics over a lookback window (default 7 days): unique visitors, pageviews, sessions, bounce rate, and average session duration with period-over-period comparisons, plus the top 5 pages, top 5 traffic sources, and goal conversions.

Required API key scopes

web_analytics:read

Path parameters

  • project_id
    string

Query parameters

  • compare
    boolean
    Default: true
  • days
    integer
    Default: 7

Response


Example request

GET /api/environments/:project_id/web_analytics/weekly_digest
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/web_analytics/weekly_digest/

Example response

Status 200
RESPONSE
{
"visitors": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"pageviews": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"sessions": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"bounce_rate": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"avg_session_duration": {
"current": "string",
"previous": "string",
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"top_pages": [
{
"host": "string",
"path": "string",
"visitors": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"top_sources": [
{
"name": "string",
"visitors": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"goals": [
{
"name": "string",
"conversions": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"dashboard_url": "http://example.com"
}

Retrieve web analytics weekly

Summarizes a project's web analytics over a lookback window (default 7 days): unique visitors, pageviews, sessions, bounce rate, and average session duration with period-over-period comparisons, plus the top 5 pages, top 5 traffic sources, and goal conversions.

Required API key scopes

web_analytics:read

Path parameters

  • project_id
    string

Query parameters

  • compare
    boolean
    Default: true
  • days
    integer
    Default: 7

Response


Example request

GET /api/environments/:project_id/web_analytics/weekly_digest
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/web_analytics/weekly_digest/

Example response

Status 200
RESPONSE
{
"visitors": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"pageviews": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"sessions": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"bounce_rate": {
"current": 0.1,
"previous": 0.1,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"avg_session_duration": {
"current": "string",
"previous": "string",
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
},
"top_pages": [
{
"host": "string",
"path": "string",
"visitors": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"top_sources": [
{
"name": "string",
"visitors": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"goals": [
{
"name": "string",
"conversions": 0,
"change": {
"percent": 0,
"direction": "Up",
"color": "string",
"text": "string",
"long_text": "string"
}
}
],
"dashboard_url": "http://example.com"
}

Community questions

Questions about this page? or post a community question.