{
 "kind": "api",
 "slug": "posthog",
 "path": "apis/posthog/",
 "name": "PostHog",
 "logo": "https://agentgid.com/media/avatars/posthog.png",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "APIs",
   "apis/"
  ],
  [
   "Error tracking and analytics",
   "apis/monitoring/"
  ]
 ],
 "lead": "See what users do in your product.",
 "chips": [
  {
   "label": "Error tracking and analytics",
   "path": "apis/monitoring/"
  }
 ],
 "primary": {
  "label": "Copy prompt for your agent",
  "copy": "Add PostHog to my Next.js app by hand (no wizard): pin posthog-js, init it with NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST, call posthog.identify() after login and posthog.reset() on logout, mask form inputs in replays, and never put a personal API key in browser code."
 },
 "links": [
  {
   "label": "Website",
   "href": "https://posthog.com"
  },
  {
   "label": "Pricing",
   "href": "https://posthog.com/pricing"
  },
  {
   "label": "GitHub",
   "href": "https://github.com/PostHog/posthog"
  }
 ],
 "track": "Outages, price changes and new versions on your dashboard",
 "verdicts": [
  {
   "key": "price",
   "label": "Price",
   "value": "Open source",
   "status": "yes",
   "sub": "Run it yourself for free",
   "quote": "97% of companies use PostHog for free.",
   "note": "Free tier: 1M events, 5K session replays, 1M feature flag requests, 100K exceptions, 1500 survey responses per month. As reported on the official pricing page, checked Oct 9, 2026.",
   "src": "https://posthog.com/pricing"
  },
  {
   "key": "commercial",
   "label": "Commercial use",
   "value": "Allowed",
   "status": "yes",
   "sub": "Trains on your data unless you opt out",
   "quote": "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the License.",
   "note": "Use PostHog Cloud under PostHog's terms; the browser package is Apache-2.0.",
   "src": "https://github.com/PostHog/posthog-js/blob/main/LICENSE"
  },
  {
   "key": "key",
   "label": "Key & sign-up",
   "value": "API key",
   "status": "info",
   "sub": "Env var NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST (names from the Next.js guide; the packages take the token as an argument)",
   "quote": null,
   "note": "Project token (write-only) in the request body for capture and flags; personal API key as a Bearer token for private endpoints, or OAuth for apps other PostHog users install. Only the project token is browser-safe; personal API keys are server-only.",
   "src": "https://posthog.com/docs/settings/projects"
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Docs for agents",
   "status": "info",
   "sub": "llms.txt · OpenAPI · SDK",
   "quote": "The PostHog Model Context Protocol (MCP) server is a free, hosted endpoint that lets your AI agent use PostHog",
   "note": " Our agent check: 4 of 6 (Nov 13, 2026).",
   "src": "https://posthog.com/docs/model-context-protocol"
  }
 ],
 "vfoot": "Checked against the maker's official pages, pricing on Oct 9, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What PostHog does",
   "parts": [
    {
     "t": "prose",
     "text": "PostHog is an online service that records what people do in your website or app, such as page views, clicks and sign-ups, and turns it into charts. The same account also gives you screen recordings of visits, feature switches for gradual launches, error reports and in-app surveys. Each product has a free monthly allowance; above it you pay per use."
    },
    {
     "t": "list",
     "items": [
      "PostHog is one of 27 APIs in the Error tracking and analytics category on AgentGid.",
      "It is one of 20 that can be started for free.",
      "5 of them ship an official MCP server; PostHog does not.",
      "Its official SDK is the 2nd most downloaded in the category (40.2M a week)."
     ],
     "muted": true
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Find where sign-ups drop off",
       "text": "See how many visitors reach each step from landing page to paid plan, and which step loses the most people.",
       "idea": false
      },
      {
       "title": "Watch recordings of confusing screens",
       "text": "Replay real visits to see where people click, scroll and get stuck, for example on a checkout page.",
       "idea": false
      },
      {
       "title": "Launch a feature to some users first",
       "text": "Turn a new feature on for 10% of users or for beta testers only, and switch it off without a new release if it breaks.",
       "idea": false
      },
      {
       "title": "Catch errors users actually hit",
       "text": "Collect crashes from the browser and the server, then watch the recording of the visit where the error happened.",
       "idea": false
      },
      {
       "title": "Quick in-app surveys",
       "text": "Ask a short question inside your app, such as \"How likely are you to recommend us?\", and see the answers next to usage data.",
       "idea": false
      },
      {
       "title": "Track the cost of AI features",
       "text": "Log each call your app makes to an AI model, with tokens used and cost, to see which feature is expensive.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "PostHog popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "37.7M",
       "l": "SDK downloads a week",
       "d": "+25.4% on the 4-week average",
       "up": true
      },
      {
       "n": "572",
       "l": "public agent repos use its SDK"
      },
      {
       "n": "41K",
       "l": "GitHub stars, PostHog/posthog"
      }
     ]
    },
    {
     "t": "small",
     "text": "SDK downloads from npm and PyPI, weekly. Numbers as of Nov 17, 2026."
    }
   ]
  },
  {
   "id": "pricing",
   "nav": "Pricing and limits",
   "h2": "Pricing",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Free tier",
       "v": "1M events, 5K session replays, 1M feature flag requests, 100K exceptions, 1500 survey responses per month"
      },
      {
       "l": "Cheapest plan",
       "v": "No monthly plan"
      },
      {
       "l": "Usage price",
       "v": "Usage-based pricing per product (events, replays, requests, exceptions, responses, etc.)"
      },
      {
       "l": "Plans",
       "v": "Added automatically: its SDK was in 90 of the public agent repos we sampled when it was added. Prices read from the official pricing page. The main repo PostHog/posthog is MIT outside ee/ (LICENSE). Privacy policy: PostHog may use customer content, aggregated or de-identified, for training its own models."
      }
     ]
    },
    {
     "t": "h3",
     "text": "What one action costs"
    },
    {
     "t": "table",
     "head": [
      "Action",
      "Price"
     ],
     "num": true,
     "rows": [
      [
       "1 analytics event beyond the free 1 million a month (1,000,001 to 2,000,000)",
       "$0.00005"
      ],
      [
       "1 session recording beyond the free 5,000 a month (5,001 to 15,000)",
       "$0.005"
      ],
      [
       "1 feature flag request beyond the free 1 million a month (up to 2,000,000)",
       "$0.0001"
      ],
      [
       "1 exception beyond the free 100,000 a month (100,001 to 325,000)",
       "$0.00037"
      ],
      [
       "1 survey response beyond the free 1,500 a month (1,501 to 2,000)",
       "$0.1"
      ]
     ]
    },
    {
     "t": "more",
     "items": [
      {
       "title": "Price history",
       "items": [
        "A year of the pricing page in the Internet Archive (11 months): the lowest monthly figure went from $250 (2025-10) to $250 (2026-08).",
        "2026-06: no longer shown $2000/mo"
       ]
      }
     ]
    },
    {
     "t": "small",
     "text": "As reported on the official pricing page, checked Oct 9, 2026. Prices change: confirm before you buy.",
     "link": "posthog.com/pricing",
     "href": "https://posthog.com/pricing"
    }
   ]
  },
  {
   "id": "limits",
   "nav": null,
   "spy_as": "pricing",
   "h2": "Limits",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "All plans, private endpoints (analytics such as insights and persons)",
       "v": "240 requests per minute and 1,200 per hour per personal API key",
       "src": "https://posthog.com/docs/api"
      },
      {
       "l": "All plans, query endpoint",
       "v": "2,400 requests per hour",
       "src": "https://posthog.com/docs/api"
      },
      {
       "l": "All plans, other create/read/update/delete endpoints",
       "v": "480 requests per minute and 4,800 per hour",
       "src": "https://posthog.com/docs/api"
      },
      {
       "l": "All plans, event capture and flag evaluation",
       "v": "No request-level rate limit",
       "src": "https://posthog.com/docs/api"
      },
      {
       "l": "All plans, request size",
       "v": "20 MB per request body",
       "src": "https://posthog.com/docs/api"
      }
     ]
    },
    {
     "t": "small",
     "text": "From the official docs.",
     "link": "posthog.com/docs/api",
     "href": "https://posthog.com/docs/api"
    }
   ]
  },
  {
   "id": "access",
   "nav": "Access and terms",
   "h2": "Key and access",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "How it signs in",
       "v": "Project token (write-only) in the request body for capture and flags; personal API key as a Bearer token for private endpoints, or OAuth for apps other PostHog users install."
      },
      {
       "l": "Environment variable",
       "v": "NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST (names from the Next.js guide; the packages take the token as an argument)",
       "code": true
      },
      {
       "l": "Safe in browser code",
       "v": "Yes",
       "status": "yes"
      },
      {
       "l": "Card at sign-up",
       "v": "No"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Steps only a person can do"
    },
    {
     "t": "list",
     "items": [
      "Sign up for PostHog, choose the US or EU cloud, and create a project. Copy the project token and host into .env as NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST.",
      "Decide on cookie consent, recording masking and the model-training opt-out for your users' data. Set opt_out_capturing_by_default or masking options in posthog.init to match that decision.",
      "Only when you need more than the free allowance, add a card and set a billing limit per product. No code change; the same token keeps working.",
      "Only for server-side reads (queries, local flag evaluation), create a personal API key with limited scopes. Store it as a server secret, never in browser code."
     ]
    }
   ]
  },
  {
   "id": "terms",
   "nav": null,
   "spy_as": "access",
   "h2": "Commercial use and your data",
   "parts": [
    {
     "t": "prose",
     "text": "PostHog Cloud is a paid online service with a free allowance, used under PostHog's terms. The browser package is open source under Apache 2.0, and the main code is MIT outside its \"ee\" folder if you host it yourself."
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In a paid app",
       "v": "Yes",
       "status": "yes",
       "sub": "Use PostHog Cloud under PostHog's terms; the browser package is Apache-2.0.",
       "quote": "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the License.",
       "src": "https://github.com/PostHog/posthog-js/blob/main/LICENSE"
      },
      {
       "l": "inside-app-bundle",
       "v": "With conditions",
       "status": "cond",
       "sub": "Shipping posthog-js in your bundle is allowed under Apache-2.0; keep its license and notices.",
       "quote": "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the License.",
       "src": "https://github.com/PostHog/posthog-js/blob/main/LICENSE"
      },
      {
       "l": "redistribute-files",
       "v": "With conditions",
       "status": "cond",
       "sub": "Self-hosted PostHog code is MIT except the ee/ folder, which has its own license.",
       "quote": "All content that resides under the \"ee/\" directory of this repository, if that directory exists, is licensed under the license defined in \"ee/LICENSE\".",
       "src": "https://github.com/PostHog/posthog/blob/master/LICENSE"
      },
      {
       "l": "Trains on what you send",
       "v": "“We may use data you upload or generate through your use of PostHog to help improve PostHog's features and train our own models.”",
       "quote": null,
       "src": "https://posthog.com/terms"
      },
      {
       "l": "Keeps your data",
       "v": "Events 1 year on free plans and 2 years on pay-as-you-go; longer with platform add-ons.",
       "quote": "Events are retained for 1 year on free plans and 2 years on pay-as-you-go plans.",
       "src": "https://posthog.com/pricing"
      },
      {
       "l": "Where data is stored",
       "v": "US cloud (Virginia) or EU cloud (Frankfurt).",
       "quote": "Select your cloud US (Virginia) EU (Frankfurt)",
       "src": "https://posthog.com/pricing"
      }
     ]
    }
   ]
  },
  {
   "id": "errors",
   "nav": null,
   "spy_as": "access",
   "h2": "Errors to handle",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "400 invalid_project",
       "v": "PostHog could not tell which project the events belong to.",
       "sub": "Check the project token and the region host; do not retry unchanged."
      },
      {
       "l": "400 invalid_payload",
       "v": "The request body is not valid.",
       "sub": "Fix the JSON body (api_key, event and distinct_id fields); do not retry unchanged."
      },
      {
       "l": "401 invalid_api_key",
       "v": "The project token is wrong.",
       "sub": "Copy the token again from the project settings."
      },
      {
       "l": "401 invalid_personal_api_key",
       "v": "The personal API key used for a private endpoint is wrong or revoked.",
       "sub": "Create or rotate the personal API key and check its scopes."
      },
      {
       "l": "200 but the event never appears",
       "v": "Events without a name or distinct_id are accepted with 200 and then dropped; over-quota capture also returns 200.",
       "sub": "Send event and distinct_id on every event, and check the quota_limited field and ingestion warnings."
      }
     ]
    }
   ]
  },
  {
   "id": "agent",
   "nav": "For agents",
   "h2": "Use it from an agent",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Our agent check",
       "v": "4 of 6: llms.txt yes, OpenAPI yes, SDK yes, MCP no, status page no, AI assistants allowed yes",
       "sub": "Checked Nov 13, 2026."
      },
      {
       "l": "MCP server",
       "v": "PostHog MCP server",
       "sub": "The server URL is https://mcp.posthog.com/mcp . The PostHog authentication server automatically routes you to the correct data region (US or EU) based on the account you log in with."
      },
      {
       "l": "npm",
       "v": "npm install posthog-js",
       "code": true
      },
      {
       "l": "PyPI",
       "v": "pip install posthog",
       "code": true
      }
     ]
    },
    {
     "t": "h3",
     "text": "Instructions in its docs to check first"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The docs say",
       "v": "“Installation: Use the PostHog wizard to install and configure PostHog automatically.”",
       "sub": "The page addresses AI coding assistants and points to npx @posthog/wizard@latest, an unpinned package that signs in and changes the project. Ask the person first; prefer the manual setup from the library docs."
      },
      {
       "l": "The docs say",
       "v": "“There is also a Claude Code plugin: claude plugin install posthog.”",
       "sub": "Installing a plugin changes the person's assistant setup; ask them first."
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "PostHog",
       "me": true,
       "facts": [
        "Free (open source)",
        "Free tier"
       ]
      },
      {
       "name": "Mixpanel",
       "why": "Pick Mixpanel when product analytics is the main need; it also offers session replay, experiments and feature flags.",
       "path": "apis/mixpanel/",
       "facts": [
        "Free plan",
        "Free tier"
       ]
      },
      {
       "name": "Sentry",
       "why": "Pick Sentry when error tracking and performance tracing are the main need, with session replay alongside.",
       "path": "apis/sentry/",
       "facts": [
        "from $0.0003625 per error",
        "Free tier"
       ]
      },
      {
       "name": "GrowthBook",
       "why": "Pick GrowthBook when you mainly need feature flags and A/B testing for product teams.",
       "path": "apis/growthbook/",
       "facts": [
        "Free (open source)",
        "Free tier"
       ]
      }
     ],
     "more": "All error tracking and analytics APIs",
     "more_path": "apis/monitoring/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Add PostHog to my Next.js app by hand (no wizard): pin posthog-js, init it with NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST, call posthog.identify() after login and posthog.reset() on logout, mask form inputs in replays, and never put a personal API key in browser code."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Create a PostHog account (US or EU cloud) and copy the project token and host from the project settings.",
       "code": null,
       "src": "https://posthog.com/docs/settings/projects"
      },
      {
       "text": "Install the browser package (or use the HTML snippet from the docs).",
       "code": "npm install --save posthog-js",
       "src": "https://posthog.com/docs/libraries/js.md"
      },
      {
       "text": "Initialise it with your token and host; in Next.js read them from public environment variables.",
       "code": "import posthog from 'posthog-js'\n\nposthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN, {\n  api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n  defaults: '2026-08-30'\n});",
       "src": "https://posthog.com/docs/libraries/next-js.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "First request"
    },
    {
     "t": "tabs",
     "label": "First request",
     "items": [
      {
       "tab": "Request",
       "code": "curl -v -L --header \"Content-Type: application/json\" -d '{\n  \"api_key\": \"<ph_project_token>\",\n  \"event\": \"event name\",\n  \"distinct_id\": \"user distinct id\",\n  \"properties\": {\n    \"account_type\": \"pro\"\n  },\n  \"timestamp\": \"[optional timestamp in ISO 8601 format]\"\n}' https://us.i.posthog.com/i/v0/e/",
       "intro": null
      },
      {
       "tab": "Response",
       "code": "{ \"status\": \"Ok\" }"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Putting a personal API key (phx_...) in browser code to read data from PostHog.",
       "fix": "Use only the project token in the browser; call private endpoints from your server with the personal key.",
       "why": "A personal API key gives the same access as being logged into your PostHog account."
      },
      {
       "dont": "Adding posthog-js to a site with a strict Content Security Policy and not updating the policy.",
       "fix": "Allow https://*.posthog.com in script-src and connect-src, and blob: in worker-src, or use a reverse proxy.",
       "why": "Blocked requests fail silently and no events arrive."
      },
      {
       "dont": "Sending events to us.i.posthog.com for a project created in the EU cloud (or the other way round).",
       "fix": "Use the host shown in your project settings (https://eu.i.posthog.com for EU projects).",
       "why": "Requests must go to the domain of the region where the project lives."
      },
      {
       "dont": "Returning from a serverless function right after client.capture() in posthog-node.",
       "fix": "await client.flush() before returning (or shutdown() when the client is no longer needed).",
       "why": "posthog-node queues events and sends them in batches; an unflushed queue is lost when the function stops."
      },
      {
       "dont": "Writing new server code with client.isFeatureEnabled() or getFeatureFlag() in posthog-node.",
       "fix": "Call client.evaluateFlags() once per user and read flags.isEnabled() from the snapshot.",
       "why": "The old methods still work during a migration period but are deprecated."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Is there a free plan?",
       "a": "Yes. Every product has a free monthly allowance that resets each month, and no credit card is needed.",
       "evidence": {
        "url": "https://posthog.com/pricing",
        "quote": "Your free allowance renews every month."
       }
      },
      {
       "q": "Can the project token be in my website code?",
       "a": "Yes. Capture and flag requests use the project token and return no sensitive data; private data endpoints need a personal key that stays on the server.",
       "evidence": {
        "url": "https://posthog.com/docs/api/capture",
        "quote": "Both are POST-only public endpoints that use your project token and do not return any sensitive data from your PostHog instance."
       }
      },
      {
       "q": "Where is my data stored?",
       "a": "In PostHog's US cloud (Virginia) or EU cloud (Frankfurt), whichever you pick, or on your own server if you self-host.",
       "evidence": {
        "url": "https://posthog.com/pricing",
        "quote": "Select your cloud US (Virginia) EU (Frankfurt)"
       }
      },
      {
       "q": "How long is data kept?",
       "a": "Events are kept 1 year on the free plan and 2 years on pay-as-you-go; recordings 1 month on free and 90 days on pay-as-you-go.",
       "evidence": {
        "url": "https://posthog.com/pricing",
        "quote": "Events are retained for 1 year on free plans and 2 years on pay-as-you-go plans."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Maker",
   "PostHog"
  ],
  [
   "Category",
   "Error tracking and analytics"
  ],
  [
   "Price",
   "Free (open source)"
  ],
  [
   "Official SDK",
   "npm posthog-js, PyPI posthog"
  ],
  [
   "Latest SDK",
   "1.447.5 on npm"
  ],
  [
   "Agent check",
   "4 of 6"
  ],
  [
   "Pricing checked",
   "Oct 9, 2026"
  ]
 ],
 "good": [
  "The free plan needs no card and resets every month, for example 1 million events and 5,000 session recordings.",
  "On the free plan, events above the limit are dropped for good, and feature flags return a fallback answer.",
  "You can set a spending limit per product, so a traffic spike does not cause a surprise bill."
 ],
 "checked_line": "Read by AgentGid from 27 official pages, card checked Nov 10, 2026; usage numbers update daily."
}