APIYard
Back to APIs
AnalyticsBearer TokenFree tier

PostHog

PostHog provides product analytics, session replays, feature flags, A/B testing, and surveys — self-hostable or cloud-hosted.

Base URL

https://app.posthog.com
product analyticsfeature flagssession replayA/B testingopen source

Endpoints

POST/capture

Capture a custom event from your application.

const response = await fetch("https://app.posthog.com/capture", {
  method: "POST",
  headers: {
  "Content-Type": "application/json",
  "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  },
  body: JSON.stringify({
  "api_key": "phc_yourkey",
  "event": "user_signed_up",
  "distinct_id": "user_123",
  "properties": {
    "plan": "pro",
    "source": "landing_page"
  }
})
});

const data = await response.json();
console.log(data);

Response Preview

{
  "status": 1
}
GET/api/projects/{project_id}/events

Query events from your PostHog project.

const response = await fetch("https://app.posthog.com/api/projects/12345/events?event=user_signed_up&limit=5", {
  method: "GET",
  headers: {
  "Content-Type": "application/json",
  "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  }
});

const data = await response.json();
console.log(data);

Response Preview

{
  "results": [{
    "id": "abc123",
    "event": "user_signed_up",
    "distinct_id": "user_123",
    "properties": { "plan": "pro" },
    "timestamp": "2024-05-01T10:00:00Z"
  }],
  "next": "https://app.posthog.com/api/..."
}