Install PostHog
Install PostHog in seconds with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):
Wait for it to finish and test the setup once the wizard is complete.
The wizard supports React, Next.js, Svelte, and React Native. We've got more on the way.
Check out the wizard's GitHub repo for more details.
We recommend setting up a reverse proxy, so that events are less likely to be intercepted by tracking blockers. We have our own managed reverse proxy service included in the platform packages, which routes through our infrastructure and makes setting up your proxy easy. If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using Cloudflare, AWS Cloudfront, and Vercel.Set up a reverse proxy (recommended)
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and group them in one project. This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.Grouping products in one project (recommended)
For certain features like heatmaps, your Web Application Firewall (WAF) may be blocking PostHog’s requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site. EU: US: These are public, stable IPs used by PostHog services (e.g., Celery tasks for snapshots).Add IPs to Firewall/WAF allowlists (recommended)
3.75.65.221, 18.197.246.42, 3.120.223.25344.205.89.55, 52.4.194.122, 44.208.188.173
This is the simplest way to get PostHog up and running. It only takes a few minutes.
Copy the snippet below and replace <ph_project_api_key> and <ph_client_api_host> with your project's values, then add it within the <head> tags at the base of your product - ideally just before the closing </head> tag. This ensures PostHog loads on any page users visit.
You can find the snippet pre-filled with this data in your project settings.
Once the snippet is added, PostHog automatically captures $pageview and other events like button clicks. You can then enable other products, such as session replays, within your project settings.
We recommend setting up a reverse proxy, so that events are less likely to be intercepted by tracking blockers. We have our own managed reverse proxy service included in the platform packages, which routes through our infrastructure and makes setting up your proxy easy. If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using Cloudflare, AWS Cloudfront, and Vercel.Set up a reverse proxy (recommended)
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and group them in one project. This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.Grouping products in one project (recommended)
For certain features like heatmaps, your Web Application Firewall (WAF) may be blocking PostHog’s requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site. EU: US: These are public, stable IPs used by PostHog services (e.g., Celery tasks for snapshots).Add IPs to Firewall/WAF allowlists (recommended)
3.75.65.221, 18.197.246.42, 3.120.223.25344.205.89.55, 52.4.194.122, 44.208.188.173
Include ES5 support (optional)
If you need ES5 support for example to track Internet Explorer 11 replace /static/array.js in the snippet with /static/array.full.es5.js
Working with AI code editors?
If you’re working with AI code editors (like Lovable, Bolt.new, Replit, and others), it’s easy to install PostHog. Just give it this prompt: npx -y @posthog/wizard@latest
Custom-built libraries for integrating PostHog with popular client and server-side langauges.
Framework-specific guides that cover our recommended approach to installing PostHog in a number of popular environments.
Events can be ingested directly using our API and the /i/v0/e endpoint, which is the same endpoint that all of our libraries use behind the scenes.
Generally, this isn't something you'll need to use when integrating PostHog, but if you're working with a language or framework that PostHog doesn't support yet, this will allow you to still send events.
Note: For this API, you should use your 'Project API Key' from the 'Project' page in PostHog. This is the same key used in your frontend snippet.
Sending events
Events can be sent either one at a time, or together in a batch. There is no limit on the number of events you can send in a batch, but the entire request body must be less than 20MB by default.
Note: Timestamp is optional. If not set, it'll automatically be set to the current time.